Wilfred / difftastic

a structural diff that understands syntax 🟥🟩
https://difftastic.wilfred.me.uk/
MIT License
20.54k stars 331 forks source link

Surprising over-large diff #580

Open tomwhoiscontrary opened 11 months ago

tomwhoiscontrary commented 11 months ago

(1) A description of the issue. A screenshot is often helpful too.

I have a Java source file with various changes, including a small change in the middle of a large method, including extracting some code into a new method which comes immediately after the large method. When i diffed my change, i was surprised to see that the whole large method was shown as deleted and re-added, so that the diff could line up some common parts in the old version of the large method and the new extracted method.

See this diff from difft:

And this one from diff -u, which is much smaller:

(2) A copy of what you're diffing.

See attached (you will need to rename these to remove the .txt):

(3) The version of difftastic you're using (see difft --version) and your operating system.

$ difft --version
Difftastic 0.52.0
$ grep PRETTY_NAME /etc/os-release
PRETTY_NAME="Ubuntu 18.04.6 LTS"
Wilfred commented 11 months ago

Thanks for the repro. That does look wrong, the result is far from the most minimal diff, which is what difftastic should be producing.

Screenshot 2023-10-11 at 08 31 24 Screenshot 2023-10-11 at 08 32 38
Wilfred commented 11 months ago

The expected diff should be more like this:

Screenshot 2023-10-11 at 08 42 46
Wilfred commented 11 months ago

This looks like a bug with the 'split unchanged' logic, as the main differ is seeing three separate things to diff. The problem disappears with DFT_DBG_KEEP_UNCHANGED=y, although I don't recommend this debug setting in general (it's crucial for performance).