Repository navigation
Make line endings of saved files consistent across platforms - #774
CoffeeFlux wants to merge 2 commits into
Conversation
rcombs
left a comment
There was a problem hiding this comment.
LGTM, with a couple nits.
| std::string cr("\r"), lf("\n"); | ||
| if (conv) { | ||
| cr = conv->Convert(cr); | ||
| lf = conv->Convert(lf); | ||
| } |
There was a problem hiding this comment.
I guess this just exists to handle UTF-16? Kinda awkward that it gets searched byte-wise, but eh, probably good enough.
This seems like an odd way to do it; basically all editors I can think of would keep the original file's line endings in memory, and write back what they read (notably, files read as CRLF would still be written as CRLF after a "Save as..."). This is unlikely to directly break anything, so it's more of a philosophical question than a practical concern, but I can think of at least one edge case: All that said if the primary concern is about VCS churn: is this actually a relevant concern in the first place? The only platform where Aegisub would write CRLF is Windows, and though Git defaults to |
Previously TextFileWriter wrote \r\n on Windows and \n everywhere else, so the same script saved on different platforms produced spurious version-control diffs. Always write \n for newly created files on every platform. When overwriting an existing file, detect the line endings it already uses (in the target charset, so UTF-16 files are handled too) and keep them, so files already committed with \r\n don't churn when resaved. Also drop the platform-dependent LINEBREAK macro from the ASS writer's format lines, which bypassed TextFileWriter's newline handling. Fixes TypesettingTools#757. Requested-by: Ryan Lucia
DetectExistingNewline already converts CR and LF to the target encoding for detection, so return those directly instead of converting the result a second time in the constructor. Requested-by: Ryan Lucia
c464bd8 to
f94b655
Compare
|
I mostly agree with petzku:
My current gut feeling is that simply switching Aegisub to unconditionally writing LF would be a much simpler solution that should not actually break any existing workflows. But if anyone knows a genuine real-world case where this would break something, I'd be very interested in that. |
|
VCS churn is the only modern concern I'm aware of (setting aside, like, WinXP Notepad users). As for CRLFs in repos, I'm aware of it happening (running into it was the reason I opened this issue in the first place); breaking autocrlf seems to be the national pastime of windows users, somehow. On the other hand, I'm not sure if anyone would actually mind those getting forced to LFs on save; it'd just make affected users with updated aegisub equivalent to non-windows users. I suggested the autodetection out of an abundance of caution, and have no strong opinions on how it should work (or if it should be implemented at all); my only strong opinion here is that we should do something promptly. I think any of the proposals here is strictly better than the status quo, and bikeshedding on tweaks for these edge cases after merge/release is no worse than doing the bikeshedding first. |
As in people intentionally storing CRLF in the repository, or as in them accidentally storing CRLF, e.g. by uploading files through the GitHub website rather than a local checkout (leading to the affected file then being permanently marked "modified" for any Windows user with autocrlf enabled)? |
|
Accidentally storing CRLF, because |
|
In that case I would definitely prefer just unconditionally writing LF everywhere. |
Previously TextFileWriter wrote \r\n on Windows and \n everywhere else, so the same script saved on different platforms produced spurious version-control diffs.
Always write \n for newly created files on every platform. When overwriting an existing file, detect the line endings it already uses (in the target charset, so UTF-16 files are handled too) and keep them, so files already committed with \r\n don't churn when resaved.
Also drop the platform-dependent LINEBREAK macro from the ASS writer's format lines, which bypassed TextFileWriter's newline handling.
Fixes #757.
Requested-by: Ryan Lucia