difftastic icon indicating copy to clipboard operation
difftastic copied to clipboard

Highlight moved, novel regions

Open Wilfred opened this issue 2 years ago • 4 comments

If a subtree is deeply novel on both sides but exists on both sides, it could be treated as a move.

Wilfred avatar May 01 '23 07:05 Wilfred

VSCode recently added a new feature called move code detection. The algorithm is surprisingly simple: after normal diff, calculate similarity(deletion, insertion) for every deletion & insertion pair. The code can be found here https://github.com/microsoft/vscode/blob/166097a20cbd06d10d255ef561837c439f372de3/src/vs/editor/common/diff/defaultLinesDiffComputer/computeMovedLines.ts#L44-L85.

But intuitively demonstrating the moving relationship on TUI might be a challenge.

QuarticCat avatar Sep 26 '23 01:09 QuarticCat

Git supports this through --color-moved, and delta displays the moved code nicely. It would be great if difftastic could also do this to detect code moved between files.

nzbart avatar Jan 16 '24 00:01 nzbart

Capturing my notes on --color-moved from another issue here:

Have you looked into git diff's --color-moved at all?

  • https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---color-movedltmodegt

Personally I tend to use the zebra mode of it. From my git aliases:

  • https://github.com/0xdevalias/dotfiles/blob/a59d60e18b58069fe1d2c21dc5ef42a1c0afe797/git/gitconfig.symlink#L248-L259
  # https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---color-movedltmodegt
  # https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---color-moved-wsltmodesgt
  # https://git-scm.com/docs/git-config#Documentation/git-config.txt-color
  # https://git-scm.com/docs/git-config#Documentation/git-config.txt-colordiffltslotgt
  diff-refactor = \
    -c color.diff.oldMoved='white dim' \
    -c color.diff.oldMovedAlternative='white dim' \
    -c color.diff.newMoved='white dim' \
    -c color.diff.newMovedAlternative='white dim' \
    -c color.diff.newMovedDimmed='white dim' \
    -c color.diff.newMovedAlternativeDimmed='white dim' \
    diff --ignore-blank-lines --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space --minimal

Originally posted by @0xdevalias in https://github.com/Wilfred/difftastic/issues/539#issuecomment-1916033305

0xdevalias avatar Mar 01 '24 01:03 0xdevalias