git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [BUG-ish] diff compaction heuristic false positive
@ 2016-06-10  7:50 Jeff King
  2016-06-10  8:31 ` Jeff King
  2016-06-10  8:31 ` [BUG-ish] diff compaction heuristic false positive Michael Haggerty
  0 siblings, 2 replies; 16+ messages in thread
From: Jeff King @ 2016-06-10  7:50 UTC (permalink / raw)
  To: Stefan Beller; +Cc: Junio C Hamano, Jacob Keller, git

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2016-06-10 21:47 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-10  7:50 [BUG-ish] diff compaction heuristic false positive Jeff King
2016-06-10  8:31 ` Jeff King
2016-06-10 15:56   ` Junio C Hamano
2016-06-10 16:25     ` Stefan Beller
2016-06-10 16:29       ` Jacob Keller
2016-06-10 18:13         ` Re* " Junio C Hamano
2016-06-10 18:21           ` Stefan Beller
2016-06-10 20:30           ` Jeff King
2016-06-10 20:48             ` [PATCH v2] diff: disable compaction heuristic for now Junio C Hamano
2016-06-10 20:53               ` Jeff King
2016-06-10 20:55               ` Junio C Hamano
2016-06-10 21:05                 ` Jeff King
2016-06-10 21:46                   ` Junio C Hamano
2016-06-10  8:31 ` [BUG-ish] diff compaction heuristic false positive Michael Haggerty
2016-06-10  8:41   ` Jeff King
2016-06-10 11:00     ` Michael Haggerty

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).