-
Notifications
You must be signed in to change notification settings - Fork 411
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
🐛 CRLF line endings are stripped from diff #754
Comments
Thanks @plgruener. Do you have time to look at #664 and help me decide what the correct course of action is? In that PR, code was added that deliberately strips trailing CR. cc @norisio in case you have time to advise also. |
#664 is not the only cause. byte_lines may also strip CR.
|
I've tried this by applying sample code in https://rosettacode.org/wiki/Check_output_device_is_a_terminal#Rust To find a solution, I think it would be better if I understand the cause of #664 a little more.
This (=CR erases the line) does not happen with the default pager. Why does this happen with delta? |
I think this is because: Suppose we have a line ending with CR LF. Git changes that to CR ANSI LF. With delta, bytelines strips the LF but leaves the CR (due to ANSI escape added by git). So now the line ends with CR ANSI but no LF. I think this causes the line to be overwritten by the terminal emulator. Whereas with the usual pager the line ends CR ANSI LF. |
I found right_fill_background_color's output overwrites the text before CR.
I think one solution is to define delta's new command line option to replace control characters by caret notations (like |
I've made a fix in this way and created a pull request. Would you please take a look? @norisio @dandavison |
Is it true that the problem is occurring because (1) git is placing an ANSI character between CR and LF: ? If so, would one solution be for delta to strip trailing CR if it is followed by the trailing ANSI character? Presumably that would be very rare in real input. In any case, delta's output is for humans to look at, not for machines to read, so it's not the end of the world if we occasionally remove a byte someone wanted as long as it really is rare. |
Only when used with |
Therefore this issue is not related to the CR-ANSI-LF problem, I guess. |
Thanks!
Right. OK, so: I think it is correct that delta's internal code paths work with a stripped line. So maybe the solution is we update bytelines so that it does not strip the line endings, or strips them but returns them to us with the line. Then, when delta is ready to print a line, it adds back the original line ending. I do think it's worth bearing in mind that delta's output is for humans to look at, not for machines to parse: if you want machine-readable diff output then that's delta's input, not its output. And indeed, if you redirect git's output into a pipe or file, then delta doesn't even get invoked (git doesn't invoke HOWEVER:
|
What is the status on this?
This is true but us humans also need to understand the output. If it show a line removed but the same line added again, that's extremely confusing. You might be able to deduce it's due to line endings but then you're left wondering what changed about line endings. Line endings are already complex enough in git as is. |
I'm trying to show CRLF line endings in my diffs (on Linux, to quickly spot if someone committed a file with CRLF instead of LF). Less has the option
-u/--underline-special
to do just that, so I could just use that as pager for delta. However, delta always seems to strip the carriage return byte from diffs, see:Here is a hexdump of both diffs. You can see the CR-bytes (0x0d) are missing.

Even if delta strips the ANSI color escape codes (which is turned off here with
--raw
), it should never just delete any other character from the output. Let the pager decide to show those control chars or not.The text was updated successfully, but these errors were encountered: