-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Wiki pages are stored as/converted to CRLF line endings #17541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
In my opinion: It is a browser behavior, I think Gitea (Web UI) should not touch it: Nowadays, all modern applications in all OS can handle CRLF and LF correctly, so it won't be a problem. The If you edit files locally, git respects settings like If these methods are not enough, then maybe we need to think about a plan to cover all cases, maybe Gitea can set settings in |
What
I think the
|
Related to this behavior: Browsers always use "CRLF" for new lines when a textarea is submitted. So, Gitea need to do extra converting before it really writes the content into the repo. |
@wxiaoguang Yet, compared to those things, support of the |
Exactly, Gitea should not touch it and silently convert my files. Honestly I don't care which settings the textarea in the browser uses. If it always uses CRLF, then the web editor should behave like any other Windows user and make use of the When editing files via the webeditor in a normal (non-wiki-) repo, (almost) everything behaves as it should and LF files are not converted. So I really don't understand the problem: why can it apparently be done for the README.md in my repo, but not the Home.md in the wiki? (I also tried how Github handles this issues, here Wiki files with LF endings are not converted.) |
Let me share more information: according to HTML standard, the "newline/EOL" is always "CRLF" in HTML's textarea. So Gitea backend could always get "CRLF" from a textarea.
Because "LF" is hard-coded in non-wiki backend code, all CRLF are replaced by LF in backend for these files (well, Windows users might feel unhappy about this behavior ....) I also agree that it should do the best to make EOL correct. So the solutions could be:
Or, as a quick fix: always use "LF" for wiki files, too, just like these non-wiki files. |
ps: original wiki code wasn't written by me, neither the editor/upload code, I just happen to know the details 🤣 if I would have enough time I could also look into the problem and/or try to improve it, but I can't promise at the moment. |
Thank you for the info.
I hadn't even noticed that yet, but yeah, that's suboptimal as well. I cannot argue which solution would be better – both have to do an "auto detect", so it probably doesn't matter if you do it in the front- or backend. 2. is more closely what
Yes, I agree it should at least be consistent (else I have to always configure my wiki-repos different than the normal ones, very confusing). |
What is the current recommended approach for this?
Will make Markdown files be CRLF-terminated on local edits, and thus compatible with current gitea's web edits, thus preventing whole-page-diffs? To me this looks like the sanest approach for now, but I'm open to opinions. EDIT: made the wording clearer. |
@vn971 Relevant code: gitea/modules/git/repo_object.go Lines 68 to 74 in 9d4ebc1
gitea/modules/git/repo_object.go Lines 60 to 61 in 9d4ebc1
Line 172 in 9d4ebc1
Adding the |
@ranvis thanks for the input! To clarify on the What you're writing looks like something very useful for anyone who'd address this in gitea though |
@vn971 So even if local clients edit files in CRLF (thanks to eol=crlf), the committed content will still be LF, meaning it won't match the CRLF content that Gitea's web editor commits directly from textarea input. |
@ranvis I cannot confirm this in my tests yet. When I mix-match local edits with web editor edits in a test repo, all the diff's affect a single line only. Here's how I tested (4 commits): https://gitea.com/vas/test/commits/branch/main Do you have another way to test that would show the problem? |
@vn971
After that, I observed that the diff on Gitea shows all lines as changed, not just the edited ones, on both Gitea and local. Edit: Step 3 (right side of the image) was affected by my global attributes config ( |
@vn971 Just to make sure: in the Gitea diff UI, please check if the whitespace option (third icon from the right) is set to "Show all changes." |
@ranvis With regards to Gitea diff UI, do you see all of the lines changed in the earlier commits in my or your repo? E.g. this commit https://gitea.com/vas/test/commit/3b2b0f1dd0110c8ad242775bb44f6e113e5f7165 If in the above commit you see 1 changed line only, it would mean that the difference is rather in our local git configuration. I'm asking because I already have "Whitespace" > "Show all changes" in Gitea's UI. In my local git config, there's nothing that looks like it'd affect the commits. I've also made a separate test to make sure I'm not messing things up with my local config, so I've made another commit with no git config at all: https://gitea.com/vas/test/commit/f0a567367caf64d0ac2d9002b459c3d90cebfa66 Could it be that you have eol-related or crlf-related stuff in your local config? This could be useful to know for future debugging |
It's true, Git can only do automatic line endings conversion (or "normalization" as it's called) for [CRLF in worktree]<-->[LF in index], but not [LF in worktree]<-->[CRLF in index]. Also, setting If you want to check the line endings of your local files:
This displays both the line ending in the worktree and in the repo. If you want to have LF-normalization (so CRLF committed to the repo, the reverse of what autocrlf does), you have to manually set up clean- and smudge filters, eg. like so:
and apply that filter to all edit: leave out the smudge-filter if you don't want LF on Windows. Maybe using only |
@vn971 You're right. In your repo's commits, I do not see whole files changed in Gitea UI with "show all changes" enabled, or local git diff. It turns out I had this (
That likely caused the CRLFs to be normalized on my side. Sorry for the confusion; step 3 in my comment was affected by this config. I still don’t know why commits created by Gitea differ, and your commits don't contain CR characters either.
I'll take a look at the filter proposed by @plgruener when I have more time. Thanks. |
EDIT: this got somewhat outdated, better read @plgruener's reply below. @plgruener to be honest, I don't fully understand which problem are you addressing in your comment? My current take is simple:
I've used Does this take make sense for you? P.S. For transparency, I'm not claiming superior knowledge here. In fact, when I inspect local objects with e.g. |
@vn971 This issue (as per the title) is specifically about Gitea Wiki pages. My previous comment with the clean filter details a working workaround with automatic conversion: regardless of whether local files are made with LF or CRLF, they will be converted to CRLF on check-in (and thus not clash with the wiki-webeditor). |
( @plgruener confirming you're right. The same steps that I did on a "normal" repo fail for the wiki https://gitea.com/vas/code/wiki/from_webeditor.md.-?action=_revision ) |
Gitea Version
1.16.0+dev-455-ga5bcf1994
Git Version
No response
Operating System
No response
How are you running Gitea?
Tried in https://try.gitea.io/plgruener/wikitest/wiki/_pages
Database
No response
Can you reproduce the bug on the Gitea demo site?
Yes
Log Gist
No response
Description
Any wiki page that is created in the webeditor (wiki/_new) is stored as file with (Windows-style) CRLF line endings, not LF (Unix-style).
This also means every wiki-page that is created locally with LF line endings (eg under Linux or MacOS) and then pushed is silently converted to CRLF, either on push itself or when that page is edited in the webeditor by another person. Since that LF->CRLF conversion changes every line, it makes a diff essentially useless.
Screenshots
No response
The text was updated successfully, but these errors were encountered: