git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[BUG-ish] diff compaction heuristic false positive

From
Jeff King <peff@peff.net>
Date
Jun 10, 2016, 07:50 UTC
Message-ID
<20160610075043.GA13411@sigill.intra.peff.net>
I found a false positive with the new compaction heuristic in v2.9:
-- >8 --
# start with a simple file
cat >file.rb <<\EOF
def foo
  do_foo_stuff()
  common_ending()
end
EOF

git add file.rb git commit -m base

# and then add another function with a similar ending cat >>file.rb <<\EOF

def bar
  do_bar_stuff()
  common_ending()
end
EOF
-- 8< --
I get this rather unfortunate diff:
    $ git diff
    diff --git a/file.rb b/file.rb
    index bd9d1cb..67fbeba 100644
    --- a/file.rb
    +++ b/file.rb
    @@ -1,5 +1,11 @@
     def foo
       do_foo_stuff()
     
    +  common_ending()
    +end
    +
    +def bar
    +  do_bar_stuff()
    +
       common_ending()
     end
but without the compaction heuristic (or with an older git), I get:
    $ git -c diff.compactionHeuristic=false diff
    diff --git a/file.rb b/file.rb
    index bd9d1cb..67fbeba 100644
    --- a/file.rb
    +++ b/file.rb
    @@ -3,3 +3,9 @@ def foo
     
       common_ending()
     end
    +
    +def bar
    +  do_bar_stuff()
    +
    +  common_ending()
    +end

:( The problem is that the common bits are separated from the interesting bits by a blank line. This is simplified from a real-world example, but I think you could come up with the same example in C, like:

  if (foo) {
        do_foo();
        something_else();
  }
-Peff
Next: Jeff King
Message 1 of 16 in “[BUG-ish] diff compaction heuristic false positive”
  1. Jeff KingJun 10, 2016
  2. Jeff KingJun 10, 2016
  3. Junio C HamanoJun 10, 2016
  4. Stefan BellerJun 10, 2016
  5. Jacob KellerJun 10, 2016
  6. Re* [BUG-ish] diff compaction heuristic false positiveJunio C Hamano, Jun 10, 2016
  7. Stefan BellerJun 10, 2016
  8. Jeff KingJun 10, 2016
  9. diff: disable compaction heuristic for nowJunio C Hamano, Jun 10, 2016
  10. Jeff KingJun 10, 2016
  11. Junio C HamanoJun 10, 2016
  12. Jeff KingJun 10, 2016
  13. Junio C HamanoJun 10, 2016
  14. Michael HaggertyJun 10, 2016
  15. Jeff KingJun 10, 2016
  16. Michael HaggertyJun 10, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.