New git diff compaction heuristic not working

Update

This is solved now, thanks to @torek answer

I needed to have more lines above the new addition so that Git could move around the difference block, and I mean:

+a +b +c + +["foo", "bar", "baz"].map do |i| + i +end + ["foo", "bar", "baz"].map do |i| i.upcase end 

Note. I tried with one line break instead of a\nb\nc\n , and also worked


The original question ...

I am using Git 2.9 on Mac OSX

The following is a validation example:

 $ mkdir git-highlight && cd git-highlight $ touch foo.rb 

I add and commit the following content:

 ["foo", "bar", "baz"].map do |i| i.upcase end 

Now I am modifying the file to have the following content:

 ["foo", "bar", "baz"].map do |i| i end ["foo", "bar", "baz"].map do |i| i.upcase end 

If I were to run either git diff or git diff --compaction-heuristic , then I get the following unexpected output:

 diff --git a/foo.rb b/foo.rb index 9056b22..f0d289a 100644 --- a/foo.rb +++ b/foo.rb @@ -1,3 +1,7 @@ ["foo", "bar", "baz"].map do |i| + i +end + +["foo", "bar", "baz"].map do |i| i.upcase end 

If you read this blog post from GitHub https://github.com/blog/2188-git-2-9-has-been-released , I am convinced that my output should look something like this:

 +["foo", "bar", "baz"].map do |i| + i +end + ["foo", "bar", "baz"].map do |i| i.upcase end 

The idea, which is a Git diffing algorithm, is more intelligent and able to identify a block change.

I also tried adding the following to my ~/.gitconfig , but it has no meaning for the result, I still get unexpected output:

 [diff] compactionHeuristic = true 

Any ideas on what I'm missing here?

+6
source share
2 answers

I have not played with the new features yet, so this may be required from grain to full juice, but:

Any ideas on what I'm missing here?

The description says that git diff hunks move up to reach the empty line. There is no line above line 1; if it were possible, that would be enough. (This may require even more “higher” context, which should not be empty, since the norm should include three lines of context above and below, and it is not clear from the brief description whether there will be a “move up” lack of additional lines.)

+3
source

Speaking of “git, the compaction heuristic does not work” ... Git 2.12 (Q1 2017) will remove this heuristic .
Git 2.14 will instead use the indentation heuristic as the default value .

" git diff " and his family had two experimental heuristics to move the contents of a piece to make the patch easier to read.
One of them turned out to be better than the other, so leave only " --indent-heuristic " and delete the other.

See commit 3cde4e0 (December 23, 2016) Junio ​​C Hamano ( gitster ) .
Proposed: Jeff King ( peff ) .
(Merger of Junio ​​C Hamano - gitster - on commit 2ced5f2 , January 10, 2017

More details:

diff : remove the compaction evacuation

When a patch inserts a block of lines whose last lines coincide with the existing lines that appear before the inserted block, git diff can select any place between these existing lines as the border between the pretext and the added lines (adjusting the end of the inserted block if necessary) so that come up with variations of the same patch, and some variations are easier to read than others.

We tried to improve the choice of this border, and Git 2.11 comes with an experimental " compaction-heuristic ".
Since then, another attempt to improve logic has led to the emergence of a new logic, " indent-heuristic ".
It was agreed that the latter gives the best result in general, and the first of them has withstood its usefulness.

Eliminate the “compaction” and keep the “indentation” as an experimental function.
The latter, I hope, will be included by default in a future version, but this should be done as a separate step.


Update for the following Git 2.15.x / 2.16 (Q1 2018):

See commit bab7614 (October 29, 2017) Carlos Martin Nieto ( carlosmn ) .
(merged Junio ​​C Hamano - gitster - in commit 662ac3b , November 6, 2017

diff : --indent-heuristic no longer experimental

This heuristic was defaulted from 2.14, so we should not confuse our users by indicating that it is experimental and turned off by default.

+7
source

All Articles