From: Michael Haggerty <mhagger@alum.mit.edu>
To: Jeff King <peff@peff.net>, Stefan Beller <sbeller@google.com>
Cc: Junio C Hamano <gitster@pobox.com>,
Jacob Keller <jacob.keller@gmail.com>,
git@vger.kernel.org
Subject: Re: [BUG-ish] diff compaction heuristic false positive
Date: Fri, 10 Jun 2016 10:31:13 +0200 [thread overview]
Message-ID: <575A7AD1.50604@alum.mit.edu> (raw)
In-Reply-To: <20160610075043.GA13411@sigill.intra.peff.net>
On 06/10/2016 09:50 AM, Jeff King wrote:
> I found a false positive with the new compaction heuristic in v2.9:
> [...]
> 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
I've often thought that indentation would be a good, fairly universal
signal for diff to use when deciding how to slide hunks around. Most
source code is indented in a way that shows its structure.
I propose the following heuristic:
* Prefer to start and end hunks following lines with the least
indentation.
* Define the "indentation" of a blank line to be the indentation of
the previous non-blank line minus epsilon.
* In the case of a tie, prefer to slide the hunk down as far as
possible.
For the case above, the indentations for the candidate "before-the-hunk"
lines and the resulting hunk would be
> def foo
> 2 do_foo_stuff()
> 2-ε
> 2 common_ending()
> 0 end
> 0-ε +
> +def bar
> + do_bar_stuff()
> +
> + common_ending()
> +end
I haven't tried testing this heuristic systematically but I have the
feeling that it would be pretty effective and yet quite easy to implement.
Michael
next prev parent reply other threads:[~2016-06-10 8:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Michael Haggerty [this message]
2016-06-10 8:41 ` [BUG-ish] diff compaction heuristic false positive Jeff King
2016-06-10 11:00 ` Michael Haggerty
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=575A7AD1.50604@alum.mit.edu \
--to=mhagger@alum.mit.edu \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jacob.keller@gmail.com \
--cc=peff@peff.net \
--cc=sbeller@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.