Skip to content
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

🐛 git's --color-moved with DOS line endings (\r\n) triggers a panic #795

Closed
th1000s opened this issue Nov 24, 2021 · 2 comments · Fixed by #800
Closed

🐛 git's --color-moved with DOS line endings (\r\n) triggers a panic #795

th1000s opened this issue Nov 24, 2021 · 2 comments · Fixed by #800

Comments

@th1000s
Copy link
Collaborator

th1000s commented Nov 24, 2021

Using delta 92d6591 and git version 2.30.2. To reproduce:

$ echo -e "move_this_long_function()\\nfoo()\\nbar()" | sed 's,$,\r,' > a.py
$ { tail -n 2 a.py; head -n 1 a.py; } > b.py 
$ git diff --color-moved --no-index --color=always a.py b.py | target/release/delta --no-gitconfig 

thread 'main' panicked at 'String mismatch encountered while superimposing style sections: '
'', src/paint.rs:921:17

[..]
2: delta::paint::superimpose_style_sections::superimpose_style_sections
3: delta::paint::Painter::paint_line
4: delta::paint::Painter::paint_buffered_minus_and_plus_lines
5: delta::delta::delta
6: delta::main
$ cat -A a.py
move_this_long_function()^M$
foo()^M$
bar()^M$
@dandavison
Copy link
Owner

dandavison commented Nov 25, 2021

Thanks @th1000s. This is happening because git (for some reason -- does anyone know why? Is it intentional?) inserts ANSI escape sequences (in this case a "reset" command) between the \r and \n. This behavior of git was noted in #664.

$ git diff --color-moved --no-index --color=always a.py b.py | bat -pA
␛[1mdiff·--git·a/a.py·b/b.py␛[m␊
␛[1mindex·cb0f8bb..3dc21ec·100644␛[m␊
␛[1m---·a/a.py␛[m␊
␛[1m+++·b/b.py␛[m␊
␛[36m@@·-1,3·+1,3·@@␛[m␊
␛[1;35m-move_this_long_function()␛[m␍␊
·foo()␛[m␍␊
·bar()␛[m␍␊
␛[1;36m+␛[m␛[1;36mmove_this_long_function()␛[m␛[41m␍␛[m␊

Fixed in #800 by doing the \r-stripping on the raw line, accounting for the possibility of trailing ANSI escape sequences.

@dandavison
Copy link
Owner

dandavison commented Nov 25, 2021

My guess is this is a bug in git -- failing to account for the possibility of \r\n endings when inserting a reset ANSI code, but terminal emulators tolerate it.

It looks like the relevant code is here: https://github.com/git/git/blob/9865b6e6a4ca1e895fd473c827cf1822f3bd8249/diff.c#L1920-L1933 Maybe the line endings are supposed to be normalized prior to that point?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants