xdiff: implement empty line chunk heuristic
v5 cover xdiff: implement empty line chunk heuristic
Thanks Jeff for pointing out issues in the comment!
Thanks,
Stefan
diff to origin/jk/diff-compact-heuristic:
xdiff/xdiffi.c +3 -3
@@ -515,12 +515,12 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { }/* -* If a group can be moved back and forth, see if there is an +* If a group can be moved back and forth, see if there is a * blank line in the moving space. If there is a blank line, * make sure the last blank line is the end of the group. * -* As we shifted the group forward as far as possible, we only -* need to shift it back if at all. +* As we already shifted the group forward as far as possible +* in the earlier loop, we need to shift it back only if at all. */ if ((flags &XDF_COMPACTION_HEURISTIC ) && blank_lines) { while (ixs > 0 &&
Jacob Keller (1):
xdiff: add recs_match helper function
Stefan Beller (1):
xdiff: implement empty line chunk heuristic
Documentation/diff-config.txt | 5 +++++ Documentation/diff-options.txt | 6 ++++++ diff.c | 11 +++++++++++ xdiff/xdiff.h | 2 ++ xdiff/xdiffi.c | 40 ++++++++++++++++++++++++++++++++++++---- 5 files changed, 60 insertions(+), 4 deletions(-)
Signature · 1 line
2.4.11.2.g96ed4e5.dirty
PATCH v5 1/2 xdiff: add recs_match helper function
From: Jacob Keller <[email protected]>
It is a common pattern in xdl_change_compact to check that hashes and strings match. The resulting code to perform this change causes very long lines and makes it hard to follow the intention. Introduce a helper function recs_match which performs both checks to increase code readability.
--- xdiff/xdiffi.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
xdiff/xdiffi.c +10 -4
@@ -400,6 +400,14 @@ static xdchange_t *xdl_add_change(xdchange_t *xscr, long i1, long i2, long chg1, } +static int recs_match (xrecord_t **recs,long ixs,long ix,long flags) +{ +return (recs[ixs]->ha == recs[ix]->ha && +xdl_recmatch (recs[ixs]->ptr, recs[ixs]->size, + recs[ix]->ptr, recs[ix]->size, + flags)); +} +int xdl_change_compact (xdfile_t *xdf,xdfile_t *xdfo,long flags) {long ix, ixo, ixs, ixref, grpsiz, nrec = xdf->nrec;char *rchg = xdf->rchg, *rchgo = xdfo->rchg;
@@ -442,8 +450,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {* the last line of the current change group, shift backward * the group. */ -while (ixs >0 && recs[ixs -1 ]->ha == recs[ix -1 ]->ha && -xdl_recmatch (recs[ixs -1 ]->ptr, recs[ixs -1 ]->size, recs[ix -1 ]->ptr, recs[ix -1 ]->size, flags)) { +while (ixs >0 &&recs_match (recs, ixs -1 , ix -1 , flags)) { rchg[--ixs] =1 ; rchg[--ix] =0 ;
@@ -470,8 +477,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {* the line next of the current change group, shift forward * the group. */ -while (ix < nrec && recs[ixs]->ha == recs[ix]->ha && -xdl_recmatch (recs[ixs]->ptr, recs[ixs]->size, recs[ix]->ptr, recs[ix]->size, flags)) { +while (ix < nrec &&recs_match (recs, ixs, ix, flags)) { rchg[ixs++] =0 ; rchg[ix++] =1 ;
Signature · 1 line
2.4.11.2.g96ed4e5.dirty
PATCH v5 2/2 xdiff: implement empty line chunk heuristic
In reply to Stefan BellerIn 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, it can be disabled via diff.compactionHeuristic.
--- Documentation/diff-config.txt | 5 +++++ Documentation/diff-options.txt | 6 ++++++ diff.c | 11 +++++++++++ xdiff/xdiff.h | 2 ++ xdiff/xdiffi.c | 26 ++++++++++++++++++++++++++ 5 files changed, 50 insertions(+)
Documentation/diff-config.txt +5 -0
@@ -166,6 +166,11 @@ diff.tool:: include::mergetools-diff.txt[] +diff.compactionHeuristic:: + Set this option to enable an experimental heuristic that + shifts the hunk boundary in an attempt to make the resulting + patch easier to read. + diff.algorithm:: Choose a diff algorithm. The variants are as follows: +
Documentation/diff-options.txt +6 -0
@@ -63,6 +63,12 @@ ifndef::git-format-patch[] Synonym for `-p --raw`. endif::git-format-patch[] +--compaction-heuristic:: +--no-compaction-heuristic:: + These are to help debugging and tuning an experimental + heuristic that shifts the hunk boundary in an attempt to + make the resulting patch easier to read. + --minimal:: Spend extra time to make sure the smallest possible diff is produced.
diff.c +11 -0
@@ -25,6 +25,7 @@#endif static int diff_detect_rename_default; +static int diff_compaction_heuristic =1 ;static int diff_rename_limit_default =400 ;static int diff_suppress_blank_empty;static int diff_use_color_default =-1 ;
@@ -181,6 +182,10 @@ int git_diff_ui_config(const char *var, const char *value, void *cb) }if (!strcmp (var,"diff.renames" )) { diff_detect_rename_default =git_config_rename (var, value); +return 0 ; + } +if (!strcmp (var,"diff.compactionheuristic" )) { + diff_compaction_heuristic =git_config_bool (var, value);return 0 ; }if (!strcmp (var,"diff.autorefreshindex" )) {
@@ -3235,6 +3240,8 @@ void diff_setup(struct diff_options *options) options->use_color = diff_use_color_default; options->detect_rename = diff_detect_rename_default; options->xdl_opts |= diff_algorithm; +if (diff_compaction_heuristic) +DIFF_XDL_SET (options,COMPACTION_HEURISTIC ); options->orderfile = diff_order_file_cfg;
@@ -3712,6 +3719,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)DIFF_XDL_SET (options,IGNORE_WHITESPACE_AT_EOL ); else if (!strcmp(arg, "--ignore-blank-lines"))DIFF_XDL_SET (options,IGNORE_BLANK_LINES ); + else if (!strcmp(arg, "--compaction-heuristic")) +DIFF_XDL_SET (options,COMPACTION_HEURISTIC ); + else if (!strcmp(arg, "--no-compaction-heuristic")) +DIFF_XDL_CLR (options,COMPACTION_HEURISTIC ); else if (!strcmp(arg, "--patience")) options->xdl_opts =DIFF_WITH_ALG (options,PATIENCE_DIFF ); else if (!strcmp(arg, "--histogram"))
xdiff/xdiff.h +2 -0
@@ -41,6 +41,8 @@ extern "C" {#define XDF_IGNORE_BLANK_LINES (1 << 7) +#define XDF_COMPACTION_HEURISTIC (1 << 8) +#define XDL_EMIT_FUNCNAMES (1 << 0)#define XDL_EMIT_COMMON (1 << 1)#define XDL_EMIT_FUNCCONTEXT (1 << 2)
xdiff/xdiffi.c +26 -0
@@ -400,6 +400,11 @@ static xdchange_t *xdl_add_change(xdchange_t *xscr, long i1, long i2, long chg1, } +static int is_blank_line (xrecord_t **recs,long ix,long flags) +{ +return xdl_blankline (recs[ix]->ptr, recs[ix]->size, flags); +} +static int recs_match (xrecord_t **recs,long ixs,long ix,long flags) { return (recs[ixs]->ha == recs[ix]->ha &&
@@ -411,6 +416,7 @@ static int recs_match(xrecord_t **recs, long ixs, long ix, long flags)int xdl_change_compact (xdfile_t *xdf,xdfile_t *xdfo,long flags) {long ix, ixo, ixs, ixref, grpsiz, nrec = xdf->nrec;char *rchg = xdf->rchg, *rchgo = xdfo->rchg; +unsigned int blank_lines;xrecord_t **recs = xdf->recs;/*
@@ -444,6 +450,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { do { grpsiz = ix - ixs; + blank_lines = 0; /* * If the line before the current change group, is equal to
@@ -478,6 +485,8 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {* the group. */ while (ix < nrec &&recs_match (recs, ixs, ix, flags)) { + blank_lines +=is_blank_line (recs, ix, flags); + rchg[ixs++] =0 ; rchg[ix++] =1 ;
@@ -503,6 +512,23 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { rchg[--ixs] =1 ; rchg[--ix] =0 ;while (rchgo[--ixo]); + } + +/* +* If a group can be moved back and forth, see if there is a +* blank line in the moving space. If there is a blank line, +* make sure the last blank line is the end of the group. +* +* As we already shifted the group forward as far as possible +* in the earlier loop, we need to shift it back only if at all. +*/ +if ((flags &XDF_COMPACTION_HEURISTIC ) && blank_lines) { +while (ixs >0 && + !is_blank_line (recs, ix -1 , flags) && +recs_match (recs, ixs -1 , ix -1 , flags)) { + rchg[--ixs] =1 ; + rchg[--ix] =0 ; + } } }
Signature · 1 line
2.4.11.2.g96ed4e5.dirty
A message that is not in the archive (sent off-list or not yet received): CA+P7+xoqn3fxEZGn02ST1XV-2UpQGr3iwV-37R8pakFJy_9n0w@mail.gmail.com
[your original probably didn't make it to the list because of its 5MB
attachment; the list has a 100K limit; I'll try to quote liberally]
Quoted 10 lines · Jacob Keller
I ran this version of the patch against the entire Linux kernel history, as I figured this has a large batch of C code to try and spot any issues.
I ran something like the following command in bash
$git rev-list HEAD | while read -r rev; do diff -F ^commit -u <(git show --format="commit %H" --no-compaction-heuristic $rev) <(git show --format="commit %H" --compaction-heuristic $rev); done > heuristic.patch
My earlier tests with the perl script were all done with "git log -p", which will not show anything at all for merges (and my script wouldn't know how to deal with combined diffs anyway). But I think this new patch _will_ kick in for combined diffs (because it is built on individual diffs). It will be interesting to see if this has any effect there, and what it looks like.
We should be able to see it (on a small enough repository) with:
git log --format='commit %H' --cc --merges
and comparing the before/after.
Quoted 5 lines
I've attached the file that I generated for the Linux history, it's rather large so hopefully I can get some help to spot any differences. The above approach will work for pretty much any repository, and works better than trying to generate the entire thing first and then diff (since that runs out of memory pretty fast).
I don't think there is much point in generating a complete diff between the patches for every commit, when nobody can look at the whole thing. Unless we have automated tooling to find "interesting" bits (and certainly a tool to remove the boring "a comment got shifted by one" lines would help; those are all known improvements, but it's the _other_ stuff we want to look).
But if we are not using automated tooling to find the needle in the haystack, we might as well using sampling to make the dataset more manageable. Adding "--since=1.year.ago" is one way, though we may want to sample more randomly across time.
Quoted 3 lines
So far, I haven't spotted anything that would want me to disable it, while I've spotted several cases where I felt that readability was improved. It's somewhat difficult to spot though.
I did find one case that I think is worse. Look at 857942fd1a in the kernel. It has a pattern like this:
... surrounding code ...
function_one();
... more surrounding code ...
which becomes:
... surrounding code ...
function_two();
... more surrounding code
Without the new heuristic, that looks like:
-function_one(); +function_two(); +
but with it, it becomes:
+ +function_two(); -function_one();
which is kind of weird. Having the two directly next to each other reads better to me. This is a pretty unusual diff, though, in that it did change the surrounding whitespace (and if you look further in the diff, the identical change is made elsewhere _without_ touching the whitespace). So this is kind of an anomaly. And IMHO the weirdness here is outweighed by the vast number of improvements elsewhere.
-Peff
Quoted 7 lines · Jeff King
My earlier tests with the perl script were all done with "git log -p", which will not show anything at all for merges (and my script wouldn't know how to deal with combined diffs anyway). But I think this new patch _will_ kick in for combined diffs (because it is built on individual diffs). It will be interesting to see if this has any effect there, and what it looks like.
Quoted 5 lines
We should be able to see it (on a small enough repository) with:
git log --format='commit %H' --cc --mergesand comparing the before/after.
Add in "-p" if you are testing the tip of jk/diff-compact-heuristic. It is based on the older maintenance track in which "--cc" does not imply "-p".
Looking over the results, it's about what you'd expect (comment blocks shifted by one as we want, and then there happens to be a one-line conflict resolved later in the hunk).
The most interesting thing I found was db65f0fc3b1e. There we have two functions being added in the same spot, and the resolution obviously is to put one after the other. So both sides do the usual comment-block thing, and the resulting combined diff carries through that improvement as you'd expect.
-Peff
Quoted 80 lines · Jeff King
[your original probably didn't make it to the list because of its 5MB
attachment; the list has a 100K limit; I'll try to quote liberally]Quoted 10 lines · Jacob Keller
I ran this version of the patch against the entire Linux kernel history, as I figured this has a large batch of C code to try and spot any issues.
I ran something like the following command in bash
$git rev-list HEAD | while read -r rev; do diff -F ^commit -u <(git show --format="commit %H" --no-compaction-heuristic $rev) <(git show --format="commit %H" --compaction-heuristic $rev); done > heuristic.patch
My earlier tests with the perl script were all done with "git log -p", which will not show anything at all for merges (and my script wouldn't know how to deal with combined diffs anyway). But I think this new patch _will_ kick in for combined diffs (because it is built on individual diffs). It will be interesting to see if this has any effect there, and what it looks like.
We should be able to see it (on a small enough repository) with:
git log --format='commit %H' --cc --mergesand comparing the before/after.
Quoted 5 lines
I've attached the file that I generated for the Linux history, it's rather large so hopefully I can get some help to spot any differences. The above approach will work for pretty much any repository, and works better than trying to generate the entire thing first and then diff (since that runs out of memory pretty fast).
I don't think there is much point in generating a complete diff between the patches for every commit, when nobody can look at the whole thing. Unless we have automated tooling to find "interesting" bits (and certainly a tool to remove the boring "a comment got shifted by one" lines would help; those are all known improvements, but it's the _other_ stuff we want to look).
But if we are not using automated tooling to find the needle in the haystack, we might as well using sampling to make the dataset more manageable. Adding "--since=1.year.ago" is one way, though we may want to sample more randomly across time.
Quoted 3 lines
So far, I haven't spotted anything that would want me to disable it, while I've spotted several cases where I felt that readability was improved. It's somewhat difficult to spot though.
I did find one case that I think is worse. Look at
857942fd1ain the kernel. It has a pattern like this:... surrounding code ...
function_one();
... more surrounding code ...which becomes:
... surrounding code ...
function_two();... more surrounding code
Without the new heuristic, that looks like:
-function_one(); +function_two(); +but with it, it becomes:
+ +function_two(); -function_one();
Quoted 6 lines
which is kind of weird. Having the two directly next to each other reads better to me. This is a pretty unusual diff, though, in that it did change the surrounding whitespace (and if you look further in the diff, the identical change is made elsewhere _without_ touching the whitespace). So this is kind of an anomaly. And IMHO the weirdness here is outweighed by the vast number of improvements elsewhere.
The new implementation supports the flags for ignoring white space, too.
Quoted 2 lines
-Peff
Quoted 6 lines · Jeff King
... Having the two directly next to each other reads
better to me. This is a pretty unusual diff, though, in that it did change the surrounding whitespace (and if you look further in the diff, the identical change is made elsewhere _without_ touching the whitespace). So this is kind of an anomaly. And IMHO the weirdness here is outweighed by the vast number of improvements elsewhere.
So... is everybody happy with the result and now we can drop the tweaking knob added to help experimentation before merging the result to 'master'?
I am pretty happy with the end result myself.
Quoted 9 lines · Junio C Hamano
Quoted 6 lines · Jeff King
... Having the two directly next to each other reads
better to me. This is a pretty unusual diff, though, in that it did change the surrounding whitespace (and if you look further in the diff, the identical change is made elsewhere _without_ touching the whitespace). So this is kind of an anomaly. And IMHO the weirdness here is outweighed by the vast number of improvements elsewhere.
Quoted 5 lines
So... is everybody happy with the result and now we can drop the tweaking knob added to help experimentation before merging the result to 'master'?
I am pretty happy with the end result myself.
I am very happy with it. I haven't had any issues, and I think we'll find better traction by enabling it at this point and seeing when/if someone complains.
I think for most it won't be noticed and for those that do it will likely be positive.
Thanks,
Jake
Quoted 14 lines · Jacob Keller
Quoted 13 lines · Junio C Hamano
Quoted 6 lines · Jeff King
... Having the two directly next to each other reads
better to me. This is a pretty unusual diff, though, in that it did change the surrounding whitespace (and if you look further in the diff, the identical change is made elsewhere _without_ touching the whitespace). So this is kind of an anomaly. And IMHO the weirdness here is outweighed by the vast number of improvements elsewhere.So... is everybody happy with the result and now we can drop the tweaking knob added to help experimentation before merging the result to 'master'?
Quoted 8 lines
Quoted 1 line
I am pretty happy with the end result myself.
I am very happy with it. I haven't had any issues, and I think we'll find better traction by enabling it at this point and seeing when/if someone complains.
I think for most it won't be noticed and for those that do it will likely be positive.
I am doing this only to prepare in case we have a concensus, i.e. this is not to declare that I do not care what other people say. Here is a patch to remove the experimentation knob.
Let's say we keep this patch out of tree for now and keep the topic in 'next' so that people can further play with it for several more weeks, and then apply this on top and merge the result to 'master' early in the next cycle.
-- >8 --
diff: enable "compaction heuristics" and lose experimentation knob
It seems that the new "find a good hunk boundary by locating a blank line" heuristics gives much more pleasant result without much noticeable downsides. Let's make it the new algorithm for real, without the opt-out knob we added while experimenting with it.
--- Documentation/diff-config.txt | 5 ----- Documentation/diff-options.txt | 6 ------ diff.c | 11 ----------- xdiff/xdiff.h | 2 -- xdiff/xdiffi.c | 2 +- 5 files changed, 1 insertion(+), 25 deletions(-)
Documentation/diff-config.txt +0 -5
@@ -166,11 +166,6 @@ diff.tool:: include::mergetools-diff.txt[] -diff.compactionHeuristic:: - Set this option to enable an experimental heuristic that - shifts the hunk boundary in an attempt to make the resulting - patch easier to read. - diff.algorithm:: Choose a diff algorithm. The variants are as follows: +
Documentation/diff-options.txt +0 -6
@@ -63,12 +63,6 @@ ifndef::git-format-patch[] Synonym for `-p --raw`. endif::git-format-patch[] ---compaction-heuristic:: ---no-compaction-heuristic:: - These are to help debugging and tuning an experimental - heuristic that shifts the hunk boundary in an attempt to - make the resulting patch easier to read. - --minimal:: Spend extra time to make sure the smallest possible diff is produced.
diff.c +0 -11
@@ -25,7 +25,6 @@#endif static int diff_detect_rename_default; -static int diff_compaction_heuristic =1 ;static int diff_rename_limit_default =400 ;static int diff_suppress_blank_empty;static int diff_use_color_default =-1 ;
@@ -184,10 +183,6 @@ int git_diff_ui_config(const char *var, const char *value, void *cb) diff_detect_rename_default =git_config_rename (var, value);return 0 ; } -if (!strcmp (var,"diff.compactionheuristic" )) { - diff_compaction_heuristic =git_config_bool (var, value); -return 0 ; - }if (!strcmp (var,"diff.autorefreshindex" )) { diff_auto_refresh_index =git_config_bool (var, value);return 0 ;
@@ -3240,8 +3235,6 @@ void diff_setup(struct diff_options *options) options->use_color = diff_use_color_default; options->detect_rename = diff_detect_rename_default; options->xdl_opts |= diff_algorithm; -if (diff_compaction_heuristic) -DIFF_XDL_SET (options,COMPACTION_HEURISTIC ); options->orderfile = diff_order_file_cfg;
@@ -3719,10 +3712,6 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)DIFF_XDL_SET (options,IGNORE_WHITESPACE_AT_EOL ); else if (!strcmp(arg, "--ignore-blank-lines"))DIFF_XDL_SET (options,IGNORE_BLANK_LINES ); - else if (!strcmp(arg, "--compaction-heuristic")) -DIFF_XDL_SET (options,COMPACTION_HEURISTIC ); - else if (!strcmp(arg, "--no-compaction-heuristic")) -DIFF_XDL_CLR (options,COMPACTION_HEURISTIC ); else if (!strcmp(arg, "--patience")) options->xdl_opts =DIFF_WITH_ALG (options,PATIENCE_DIFF ); else if (!strcmp(arg, "--histogram"))
xdiff/xdiff.h +0 -2
@@ -41,8 +41,6 @@ extern "C" {#define XDF_IGNORE_BLANK_LINES (1 << 7) -#define XDF_COMPACTION_HEURISTIC (1 << 8) -#define XDL_EMIT_FUNCNAMES (1 << 0)#define XDL_EMIT_COMMON (1 << 1)#define XDL_EMIT_FUNCCONTEXT (1 << 2)
xdiff/xdiffi.c +1 -1
@@ -522,7 +522,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {* As we already shifted the group forward as far as possible * in the earlier loop, we need to shift it back only if at all. */ -if ((flags &XDF_COMPACTION_HEURISTIC ) && blank_lines) { +if (blank_lines) {while (ixs >0 && !is_blank_line (recs, ix -1 , flags) &&recs_match (recs, ixs -1 , ix -1 , flags)) {
Quoted 34 lines · Junio C Hamano
Quoted 14 lines · Jacob Keller
Quoted 13 lines · Junio C Hamano
Quoted 6 lines · Jeff King
... Having the two directly next to each other reads
better to me. This is a pretty unusual diff, though, in that it did change the surrounding whitespace (and if you look further in the diff, the identical change is made elsewhere _without_ touching the whitespace). So this is kind of an anomaly. And IMHO the weirdness here is outweighed by the vast number of improvements elsewhere.So... is everybody happy with the result and now we can drop the tweaking knob added to help experimentation before merging the result to 'master'?
Quoted 8 lines
Quoted 1 line
I am pretty happy with the end result myself.
I am very happy with it. I haven't had any issues, and I think we'll find better traction by enabling it at this point and seeing when/if someone complains.
I think for most it won't be noticed and for those that do it will likely be positive.
I am doing this only to prepare in case we have a concensus, i.e. this is not to declare that I do not care what other people say. Here is a patch to remove the experimentation knob.
Let's say we keep this patch out of tree for now and keep the topic in 'next' so that people can further play with it for several more weeks, and then apply this on top and merge the result to 'master' early in the next cycle.
Quoted 7 lines
-- >8 --
diff: enable "compaction heuristics" and lose experimentation knobIt seems that the new "find a good hunk boundary by locating a blank line" heuristics gives much more pleasant result without much noticeable downsides. Let's make it the new algorithm for real, without the opt-out knob we added while experimenting with it.
I would remove the opt-out knob much later in the game, i.e.
1) make a patch that removes the documentation only before the next release (i.e. before 2.9)
2) make a patch to remove the actual (unlabeled) knobs, merge into master before 2.10 (i.e. just after the 2.9 release)
Then we get the most of the community to test it with the 2.9 release and still have an emergency knob in case some major headaches show up. After one release cycle we'll be much more confident about its usage and its short comings and do not need the emergency turn off. If the community doesn't like it for some reason we can document it and debate the default setting?
I agree we want the knob gone eventually.
Making it an undocumented feature is as good as that from a users point of view?
Quoted 112 lines
Signed-off-by Junio C Hamano <[email protected]>--- Documentation/diff-config.txt | 5 ----- Documentation/diff-options.txt | 6 ------ diff.c | 11 ----------- xdiff/xdiff.h | 2 -- xdiff/xdiffi.c | 2 +- 5 files changed, 1 insertion(+), 25 deletions(-)Documentation/diff-config.txt +0
-5@@ -166,11 +166,6 @@ diff.tool:: include::mergetools-diff.txt[] -diff.compactionHeuristic:: - Set this option to enable an experimental heuristic that - shifts the hunk boundary in an attempt to make the resulting - patch easier to read. - diff.algorithm:: Choose a diff algorithm. The variants are as follows: +Documentation/diff-options.txt +0
-6@@ -63,12 +63,6 @@ ifndef::git-format-patch[] Synonym for `-p --raw`. endif::git-format-patch[] ---compaction-heuristic:: ---no-compaction-heuristic:: - These are to help debugging and tuning an experimental - heuristic that shifts the hunk boundary in an attempt to - make the resulting patch easier to read. - --minimal:: Spend extra time to make sure the smallest possible diff is produced.diff.c +0
-11@@ -25,7 +25,6 @@#endif static int diff_detect_rename_default; -static int diff_compaction_heuristic =1 ;static int diff_rename_limit_default =400 ;static int diff_suppress_blank_empty;static int diff_use_color_default =-1 ;@@ -184,10 +183,6 @@ int git_diff_ui_config(const char *var, const char *value, void *cb) diff_detect_rename_default =git_config_rename (var, value);return 0 ; } -if (!strcmp (var,"diff.compactionheuristic" )) { - diff_compaction_heuristic =git_config_bool (var, value); -return 0 ; - }if (!strcmp (var,"diff.autorefreshindex" )) { diff_auto_refresh_index =git_config_bool (var, value);return 0 ;@@ -3240,8 +3235,6 @@ void diff_setup(struct diff_options *options) options->use_color = diff_use_color_default; options->detect_rename = diff_detect_rename_default; options->xdl_opts |= diff_algorithm; -if (diff_compaction_heuristic) -DIFF_XDL_SET (options,COMPACTION_HEURISTIC ); options->orderfile = diff_order_file_cfg;@@ -3719,10 +3712,6 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)DIFF_XDL_SET (options,IGNORE_WHITESPACE_AT_EOL ); else if (!strcmp(arg, "--ignore-blank-lines"))DIFF_XDL_SET (options,IGNORE_BLANK_LINES ); - else if (!strcmp(arg, "--compaction-heuristic")) -DIFF_XDL_SET (options,COMPACTION_HEURISTIC ); - else if (!strcmp(arg, "--no-compaction-heuristic")) -DIFF_XDL_CLR (options,COMPACTION_HEURISTIC ); else if (!strcmp(arg, "--patience")) options->xdl_opts =DIFF_WITH_ALG (options,PATIENCE_DIFF ); else if (!strcmp(arg, "--histogram"))xdiff/xdiff.h +0
-2@@ -41,8 +41,6 @@ extern "C" {#define XDF_IGNORE_BLANK_LINES (1 << 7) -#define XDF_COMPACTION_HEURISTIC (1 << 8) -#define XDL_EMIT_FUNCNAMES (1 << 0)#define XDL_EMIT_COMMON (1 << 1)#define XDL_EMIT_FUNCCONTEXT (1 << 2)xdiff/xdiffi.c +1
-1@@ -522,7 +522,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {* As we already shifted the group forward as far as possible * in the earlier loop, we need to shift it back only if at all. */ -if ((flags &XDF_COMPACTION_HEURISTIC ) && blank_lines) { +if (blank_lines) {while (ixs >0 && !is_blank_line (recs, ix -1 , flags) &&recs_match (recs, ixs -1 , ix -1 , flags)) {
Quoted 68 lines · Stefan Beller
Quoted 43 lines · Junio C Hamano
Quoted 28 lines · Jacob Keller
Quoted 13 lines · Junio C Hamano
Quoted 10 lines · Jeff King
... Having the two directly next to each other reads better to me. This is a pretty unusual diff, though, in that it did
change the surrounding whitespace (and if you look further in the diff,
the identical change is made elsewhere _without_ touching the whitespace). So this is kind of an anomaly. And IMHO the weirdness here
is outweighed by the vast number of improvements elsewhere.Quoted 6 lines
So... is everybody happy with the result and now we can drop the
tweaking knob added to help experimentation before merging the result to 'master'?I am pretty happy with the end result myself.
I am very happy with it. I haven't had any issues, and I think we'll
find better traction by enabling it at this point and seeing when/if
someone complains.Quoted 3 lines
I think for most it won't be noticed and for those that do it will
likely be positive.I am doing this only to prepare in case we have a concensus, i.e. this is not to declare that I do not care what other people say. Here is a patch to remove the experimentation knob.
Let's say we keep this patch out of tree for now and keep the topic in 'next' so that people can further play with it for several more weeks, and then apply this on top and merge the result to 'master' early in the next cycle.
Quoted 8 lines
-- >8 --
diff: enable "compaction heuristics" and lose experimentation knobIt seems that the new "find a good hunk boundary by locating a blank
line" heuristics gives much more pleasant result without much noticeable downsides. Let's make it the new algorithm for real, without the opt-out knob we added while experimenting with it.I would remove the opt-out knob much later in the game, i.e.
1) make a patch that removes the documentation only before the next release (i.e. before 2.9)
2) make a patch to remove the actual (unlabeled) knobs, merge into master before 2.10 (i.e. just after the 2.9 release)Then we get the most of the community to test it with the 2.9 release and still have an emergency knob in case some major headaches show up. After one release cycle we'll be much more confident about its usage and its short comings and do not need the emergency turn off. If the community doesn't like it for some reason we can document it and debate the default setting?
Quoted 4 lines
I agree we want the knob gone eventually.
Making it an undocumented feature is as good as that from a users point of view?
Currently it's an "opt in" knob, so this doesn't make sense to me. If we remove the entire knob as is, we can always (fairly easily) add it back. I would keep the code inside xdiff as a knob, but set it to enable default so that the user config has no knob at the top level but the xdiff machinery does (this making a "disable" be relatively small patch).
Thanks,
Jake
Quoted 1 line
Currently it's an "opt in" knob, so this doesn't make sense to me.
+static int diff_compaction_heuristic = 1;
It's rather an opt-out knob going by the current
origin/jk/diff-compact-heuristic
Quoted 6 lines
If
we remove the entire knob as is, we can always (fairly easily) add it back. I would keep the code inside xdiff as a knob, but set it to enable default so that the user config has no knob at the top level but the xdiff machinery does (this making a "disable" be relatively small patch).
When writing my reply, I thought about people using Git from a binary distribution with little to no admin rights. They want to have an emergency knob to disable this thing, but cannot patch/recompile Git.
If you can patch and compile your version of Git, then reverting is easy, so in that case Junios patch looks good to me.
Thanks,
Stefan
Quoted 3 lines
Thanks,
Jake
Quoted 4 lines · Stefan Beller
Quoted 2 lines
Currently it's an "opt in" knob, so this doesn't make sense to me.
+static int
diff_compaction_heuristic= 1;
Oops didn't know we'd made it default at some point. (all my versions had it disabled by default)
Quoted 3 lines
It's rather an opt-out knob going by the current
origin/jk/diff-compact-heuristic
Yea in that case, we could keep it.
Quoted 16 lines
Quoted 11 lines
If
we remove the entire knob as is, we can always (fairly easily) add it
back. I would keep the code inside xdiff as a knob, but set it to enable default so that the user config has no knob at the top level but
the xdiff machinery does (this making a "disable" be relatively small
patch).When writing my reply, I thought about people using Git from a binary distribution with little to no admin rights. They want to have an emergency
knob to disable this thing, but cannot patch/recompile Git.
Quoted 6 lines
If you can patch and compile your version of Git, then reverting is easy, so
in that case Junios patch looks good to me.Thanks,
Stefan
True. I think the chances that it needs such a thing are quite minor, and if an undocumented knob gets exposed it would have to become documented and maintained, so I'd prefer to avoid it. Given that the risk is pretty small I think that's ok.
Thanks,
Jake
Quoted 4 lines · Jacob E
True. I think the chances that it needs such a thing are quite minor, and if an undocumented knob gets exposed it would have to become documented and maintained, so I'd prefer to avoid it. Given that the risk is pretty small I think that's ok.
OK, then let's do only the "documentation" part.
-- >8 --
Subject: [PATCH] diff: undocument the compaction heuristic knobs for experimentation
It seems that people around here are all happy with the updated heuristics used to decide where the hunks are separated. Let's keep that as the default. Even though we do not expect too much trouble from the difference between the old and the new algorithms, just in case let's leave the implementation of the knobs to turn it off for emergencies. There is no longer need for documenting them, though.
--- Documentation/diff-config.txt | 5 ----- Documentation/diff-options.txt | 6 ------ 2 files changed, 11 deletions(-)
Documentation/diff-config.txt +0 -5
@@ -166,11 +166,6 @@ diff.tool:: include::mergetools-diff.txt[] -diff.compactionHeuristic:: - Set this option to enable an experimental heuristic that - shifts the hunk boundary in an attempt to make the resulting - patch easier to read. - diff.algorithm:: Choose a diff algorithm. The variants are as follows: +
Documentation/diff-options.txt +0 -6
@@ -63,12 +63,6 @@ ifndef::git-format-patch[] Synonym for `-p --raw`. endif::git-format-patch[] ---compaction-heuristic:: ---no-compaction-heuristic:: - These are to help debugging and tuning an experimental - heuristic that shifts the hunk boundary in an attempt to - make the resulting patch easier to read. - --minimal:: Spend extra time to make sure the smallest possible diff is produced.
Signature · 1 line
2.8.2-458-gacc1066
Quoted 12 lines · Junio C Hamano
Quoted 4 lines · Jacob E
True. I think the chances that it needs such a thing are quite minor, and if an undocumented knob gets exposed it would have to become documented and maintained, so I'd prefer to avoid it. Given that the risk is pretty small I think that's ok.
OK, then let's do only the "documentation" part.
-- >8 --
Subject: [PATCH] diff: undocument the compaction heuristic knobs for experimentation
Quoted 6 lines
It seems that people around here are all happy with the updated heuristics used to decide where the hunks are separated. Let's keep that as the default. Even though we do not expect too much trouble from the difference between the old and the new algorithms, just in case let's leave the implementation of the knobs to turn it off for emergencies. There is no longer need for documenting them, though.
I agree with this reasoning. Thanks.
-Peff
Quoted 21 lines · Jeff King
Quoted 12 lines · Junio C Hamano
Quoted 4 lines · Jacob E
True. I think the chances that it needs such a thing are quite minor, and if an undocumented knob gets exposed it would have to become documented and maintained, so I'd prefer to avoid it. Given that the risk is pretty small I think that's ok.
OK, then let's do only the "documentation" part.
-- >8 --
Subject: [PATCH] diff: undocument the compaction heuristic knobs for experimentationQuoted 6 lines
It seems that people around here are all happy with the updated heuristics used to decide where the hunks are separated. Let's keep that as the default. Even though we do not expect too much trouble from the difference between the old and the new algorithms, just in case let's leave the implementation of the knobs to turn it off for emergencies. There is no longer need for documenting them, though.
Quoted 3 lines
I agree with this reasoning. Thanks.
-Peff
I think I agree too.
Thanks,
Jake
Quoted 8 lines · Junio C Hamano
Quoted 4 lines · Jacob E
True. I think the chances that it needs such a thing are quite minor, and if an undocumented knob gets exposed it would have to become documented and maintained, so I'd prefer to avoid it. Given that the risk is pretty small I think that's ok.
OK, then let's do only the "documentation" part.
The patch below looks good to me.
Thanks,
Stefan
Quoted 53 lines
-- >8 --
Subject: [PATCH] diff: undocument the compaction heuristic knobs for experimentationIt seems that people around here are all happy with the updated heuristics used to decide where the hunks are separated. Let's keep that as the default. Even though we do not expect too much trouble from the difference between the old and the new algorithms, just in case let's leave the implementation of the knobs to turn it off for emergencies. There is no longer need for documenting them, though.
Signed-off-by Junio C Hamano <[email protected]>--- Documentation/diff-config.txt | 5 ----- Documentation/diff-options.txt | 6 ------ 2 files changed, 11 deletions(-)Documentation/diff-config.txt +0
-5@@ -166,11 +166,6 @@ diff.tool:: include::mergetools-diff.txt[] -diff.compactionHeuristic:: - Set this option to enable an experimental heuristic that - shifts the hunk boundary in an attempt to make the resulting - patch easier to read. - diff.algorithm:: Choose a diff algorithm. The variants are as follows: +Documentation/diff-options.txt +0
-7@@ -63,12 +63,6 @@ ifndef::git-format-patch[] Synonym for `-p --raw`. endif::git-format-patch[] ---compaction-heuristic:: ---no-compaction-heuristic:: - These are to help debugging and tuning an experimental - heuristic that shifts the hunk boundary in an attempt to - make the resulting patch easier to read. - --minimal:: Spend extra time to make sure the smallest possible diff is produced. --2.8.2-458-gacc1066
Quoted 8 lines · Stefan Beller
Quoted 7 lines
-- >8 --
diff: enable "compaction heuristics" and lose experimentation knobIt seems that the new "find a good hunk boundary by locating a blank line" heuristics gives much more pleasant result without much noticeable downsides. Let's make it the new algorithm for real, without the opt-out knob we added while experimenting with it.
Quoted 6 lines
I would remove the opt-out knob much later in the game, i.e.
1) make a patch that removes the documentation only before the next release (i.e. before 2.9)
2) make a patch to remove the actual (unlabeled) knobs, merge into master before 2.10 (i.e. just after the 2.9 release)
Yeah, I think it might be a good idea to keep some sort of undocumented safety valve in the release, at least for a cycle or two. The heuristic won't _really_ see wide use until it is in a released version of git, as much as we would like it to be otherwise.
So I am anticipating a possible conversation where somebody reports that the new output looks bad, and it would be nice to say "try it with this flag (or environment variable, or whatever) and see if that looks better". And then based on that conversation we can decide what the right next is (a real user-visible flag, or reversion, or deciding the user's case isn't worth it). Or maybe if we're lucky that conversation never happens.
The "whatever" in the instructions can obviously be "build with this patch" or "try with an older version of git", but we're a lot more likely to get a good response if it's easy for the user to do.
-Peff
Quoted 11 lines · Stefan Beller
Thanks Jeff for pointing out issues in the comment!
Thanks,
Stefandiff to origin/jk/diff-compact-heuristic:
xdiff/xdiffi.c +0
-0
xdiff/xdiffi.c int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { · line 520
Quoted 7 lines
xdiff/xdiffi.c +1
-1@@ -515,12 +515,12 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { }/* -* If a group can be moved back and forth, see if there is an +* If a group can be moved back and forth, see if there is a * blank line in the moving space. If there is a blank line, * make sure the last blank line is the end of the group.
I guess this is mine to blame. Thanks for catching and rerolling.
Will re-queue.