From: Jeff King <peff@peff.net>
To: Michael Haggerty <mhagger@alum.mit.edu>
Cc: Stefan Beller <sbeller@google.com>,
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 04:41:50 -0400 [thread overview]
Message-ID: <20160610084149.GA14592@sigill.intra.peff.net> (raw)
In-Reply-To: <575A7AD1.50604@alum.mit.edu>
On Fri, Jun 10, 2016 at 10:31:13AM +0200, Michael Haggerty wrote:
> 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.
Hmm. That might help this case, but the original motivation for this
heuristic was something like:
##
# foo
def foo
something
end
##
# bar
def bar
something_else
end
where we add the first function above the second. We end up with:
diff --git a/file.rb b/file.rb
index 1f9b151..f991c76 100644
--- a/file.rb
+++ b/file.rb
@@ -1,4 +1,10 @@
##
+# foo
+def foo
+ something
+end
+
+##
# bar
def bar
something else
I.e., crediting the "##" to the wrong spot (or in C, the "/*"). I don't
think indentation helps us there (sliding-up would, but like
sliding-down, it just depends on the order of the hunks).
So I agree that adding indentation to the mix might help, but I don't
think it can replace this heuristic.
-Peff
next prev parent reply other threads:[~2016-06-10 8:42 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 ` [BUG-ish] diff compaction heuristic false positive Michael Haggerty
2016-06-10 8:41 ` Jeff King [this message]
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160610084149.GA14592@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jacob.keller@gmail.com \
--cc=mhagger@alum.mit.edu \
--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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).