dandavison / delta

A syntax-highlighting pager for git, diff, grep, and blame output
https://dandavison.github.io/delta/
MIT License
23.05k stars 382 forks source link

🐛 Duplicate "renamed" header when file is renamed with changes #245

Closed waldyrious closed 4 years ago

waldyrious commented 4 years ago

For https://github.com/Homebrew/homebrew-cask-fonts/pull/2188, I renamed a file and also edited it. Here's how delta shows the diff (with diff-highlight emulation and a couple extra customizations, which should only influence style, not semantics):

Screenshot 2020-07-11 at 22 37 38

And for comparison, here's how git shows it natively (without using a pager):

Screenshot 2020-07-11 at 22 37 39

I would like delta to not show the renamed header twice.

waldyrious commented 4 years ago

There's also the sub-optimal detection of the changed text, by the way. Should I open a separate issue for that?

For reference, diff-so-fancy/diff-highlight shows a much more sensible result:

Screenshot 2020-07-11 at 23 22 41

dandavison commented 4 years ago

Hey @waldyrious, thanks.

There's also the sub-optimal detection of the changed text, by the way. Should I open a separate issue for that?

Yes please. FWIW, with word-diff-regex = . delta gives better highlighting than diff-highlight:

image

The algorithm in diff-highlight/diff-so-fancy is described thus:

It will find the common prefix and suffix of two lines, and consider everything in the middle to be "different".

In contrast, delta's algorithm is to tokenize into "words" defined by the customizable regex (word-diff-regex), and then run a Levenshtein-type dynamic programming edit inference algorithm at the level of "words" (I think this is more properly known as Wagner-Fischer or Needleman-Wunsch).

I've been thinking that it will probably make sense to implement the (deliberately) more simple-minded algorithm of diff-highlight as an alternative diff-highlighting algorithm in delta. Do you think diff-highlight and diff-so-fancy in delta should default to using the original, simpler, diff highlight algorithm? On the one hand there is something appealing in being able to say that delta --diff-highlightaims for a pixel-for-pixel emulation, and OTOH I do find that the dynamic programming algorithm often gives more helpful results.