From: Stefan Beller <sbeller@google.com>
To: Jacob Keller <jacob.e.keller@intel.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>,
Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
Jens Lehmann <Jens.Lehmann@web.de>,
Davide Libenzi <davidel@xmailserver.org>
Subject: Re: [RFC PATCH, WAS: "weird diff output?" 2/2] xdiff: implement empty line chunk heuristic
Date: Fri, 15 Apr 2016 12:57:05 -0700 [thread overview]
Message-ID: <CAGZ79ka7h25=rHun_hPv1qjqeghXt1UwUU3Q6xT0aj4+OW87fg@mail.gmail.com> (raw)
In-Reply-To: <20160415165141.4712-3-jacob.e.keller@intel.com>
On Fri, Apr 15, 2016 at 9:51 AM, Jacob Keller <jacob.e.keller@intel.com> wrote:
> From: Stefan Beller <sbeller@google.com>
>
> In order to produce the smallest possible diff and combine several diff
> hunks together, we implement a heuristic from GNU Diff which moves diff
> hunks forward as far as possible when we find common context above and
> below a diff hunk. This sometimes produces less readable diffs when
> writing C, Shell, or other programming languages, ie:
>
> ...
> /*
> + *
> + *
> + */
> +
> +/*
> ...
>
> instead of the more readable equivalent of
>
> ...
> +/*
> + *
> + *
> + */
> +
> /*
> ...
>
> Implement the following heuristic to (optionally) produce the desired
> output.
>
> If there are diff chunks which can be shifted around, shift each hunk
> such that the last common empty line is below the chunk with the rest
> of the context above.
>
> This heuristic appears to resolve the above example and several other
> common issues without producing significantly weird results. However, as
> with any heuristic it is not really known whether this will always be
> more optimal. Thus, leave the heuristic disabled by default.
>
> Add an XDIFF flag to enable this heuristic only conditionally. Add
> a diff command line option and diff configuration option to allow users
> to enable this option when desired.
>
> TODO:
> * Add tests
> * Add better/more documentation explaining the heuristic, possibly with
> examples(?)
> * better name(?)
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
> ---
> Documentation/diff-config.txt | 6 ++++++
> Documentation/diff-options.txt | 6 ++++++
> diff.c | 11 +++++++++++
> xdiff/xdiff.h | 2 ++
> xdiff/xdiffi.c | 26 ++++++++++++++++++++++++++
> 5 files changed, 51 insertions(+)
>
> diff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt
> index edba56522bce..cebf82702d2a 100644
> --- a/Documentation/diff-config.txt
> +++ b/Documentation/diff-config.txt
> @@ -170,6 +170,12 @@ diff.tool::
>
> include::mergetools-diff.txt[]
>
> +diff.emptyLineHeuristic::
I was looking at the TODO here and thought about the name:
It should not encode the `emptyLine` into the config option as
it is only one of many heuristics.
It should be something like `diff.heuristic=lastEmptyLine`
The we could add firstEmptyLine, aggressiveUp, aggressiveDown,
breakAtShortestLineLength or other styles as well later on.
I do not quite understand the difference between diff.algorithm
and the newly proposed heuristic as the heuristic is part of
the algorithm? So I guess we'd need to have some documentation
saying how these differ. (fundamental algorithm vs last minute
style fixup?)
next prev parent reply other threads:[~2016-04-15 19:57 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-15 16:51 [RFC PATCH, WAS: "weird diff output?" 0/2] implement better chunk heuristics Jacob Keller
2016-04-15 16:51 ` [RFC PATCH, WAS: "weird diff output?" 1/2] xdiff: add xdl_hash_and_recmatch helper function Jacob Keller
2016-04-15 17:25 ` Junio C Hamano
2016-04-15 19:09 ` Jacob Keller
2016-04-15 16:51 ` [RFC PATCH, WAS: "weird diff output?" 2/2] xdiff: implement empty line chunk heuristic Jacob Keller
2016-04-15 19:57 ` Stefan Beller [this message]
2016-04-15 20:06 ` Junio C Hamano
2016-04-15 20:17 ` Jacob Keller
2016-04-15 20:30 ` Junio C Hamano
2016-04-15 21:15 ` Jacob Keller
2016-04-15 21:22 ` Jacob Keller
2016-04-15 21:44 ` Junio C Hamano
2016-04-15 21:56 ` Jacob Keller
2016-04-15 20:06 ` Jacob Keller
2016-04-15 17:02 ` [RFC PATCH, WAS: "weird diff output?" 0/2] implement better chunk heuristics Stefan Beller
2016-04-15 17:10 ` Stefan Beller
2016-04-15 17:27 ` Junio C Hamano
2016-04-15 17:33 ` Stefan Beller
2016-04-15 17:48 ` Junio C Hamano
2016-04-15 19:09 ` Jacob Keller
2016-04-15 19:08 ` Jacob Keller
2016-04-15 19:07 ` Jacob Keller
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='CAGZ79ka7h25=rHun_hPv1qjqeghXt1UwUU3Q6xT0aj4+OW87fg@mail.gmail.com' \
--to=sbeller@google.com \
--cc=Jens.Lehmann@web.de \
--cc=davidel@xmailserver.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jacob.e.keller@intel.com \
--cc=peff@peff.net \
/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).