Merge branch 'jc/retire-compaction-heuristics'
"git diff" and its family had two experimental heuristics to shift the contents of a hunk to make the patch easier to read. One of them turns out to be better than the other, so leave only the "--indent-heuristic" option and remove the other one. * jc/retire-compaction-heuristics: diff: retire "compaction" heuristics
This commit is contained in:
commit
2ced5f2c2d
@ -172,10 +172,8 @@ diff.tool::
|
|||||||
include::mergetools-diff.txt[]
|
include::mergetools-diff.txt[]
|
||||||
|
|
||||||
diff.indentHeuristic::
|
diff.indentHeuristic::
|
||||||
diff.compactionHeuristic::
|
Set this option to `true` to enable experimental heuristics
|
||||||
Set one of these options to `true` to enable one of two
|
that shift diff hunk boundaries to make patches easier to read.
|
||||||
experimental heuristics that shift diff hunk boundaries to
|
|
||||||
make patches easier to read.
|
|
||||||
|
|
||||||
diff.algorithm::
|
diff.algorithm::
|
||||||
Choose a diff algorithm. The variants are as follows:
|
Choose a diff algorithm. The variants are as follows:
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
--indent-heuristic::
|
--indent-heuristic::
|
||||||
--no-indent-heuristic::
|
--no-indent-heuristic::
|
||||||
--compaction-heuristic::
|
|
||||||
--no-compaction-heuristic::
|
|
||||||
These are to help debugging and tuning experimental heuristics
|
These are to help debugging and tuning experimental heuristics
|
||||||
(which are off by default) that shift diff hunk boundaries to
|
(which are off by default) that shift diff hunk boundaries to
|
||||||
make patches easier to read.
|
make patches easier to read.
|
||||||
|
@ -2596,8 +2596,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
|
|||||||
* and are only included here to get included in the "-h"
|
* and are only included here to get included in the "-h"
|
||||||
* output:
|
* output:
|
||||||
*/
|
*/
|
||||||
{ OPTION_LOWLEVEL_CALLBACK, 0, "indent-heuristic", NULL, NULL, N_("Use an experimental indent-based heuristic to improve diffs"), PARSE_OPT_NOARG, parse_opt_unknown_cb },
|
{ OPTION_LOWLEVEL_CALLBACK, 0, "indent-heuristic", NULL, NULL, N_("Use an experimental heuristic to improve diffs"), PARSE_OPT_NOARG, parse_opt_unknown_cb },
|
||||||
{ OPTION_LOWLEVEL_CALLBACK, 0, "compaction-heuristic", NULL, NULL, N_("Use an experimental blank-line-based heuristic to improve diffs"), PARSE_OPT_NOARG, parse_opt_unknown_cb },
|
|
||||||
|
|
||||||
OPT_BIT(0, "minimal", &xdl_opts, N_("Spend extra cycles to find better match"), XDF_NEED_MINIMAL),
|
OPT_BIT(0, "minimal", &xdl_opts, N_("Spend extra cycles to find better match"), XDF_NEED_MINIMAL),
|
||||||
OPT_STRING('S', NULL, &revs_file, N_("file"), N_("Use revisions from <file> instead of calling git-rev-list")),
|
OPT_STRING('S', NULL, &revs_file, N_("file"), N_("Use revisions from <file> instead of calling git-rev-list")),
|
||||||
@ -2645,7 +2644,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
|
|||||||
}
|
}
|
||||||
parse_done:
|
parse_done:
|
||||||
no_whole_file_rename = !DIFF_OPT_TST(&revs.diffopt, FOLLOW_RENAMES);
|
no_whole_file_rename = !DIFF_OPT_TST(&revs.diffopt, FOLLOW_RENAMES);
|
||||||
xdl_opts |= revs.diffopt.xdl_opts & (XDF_COMPACTION_HEURISTIC | XDF_INDENT_HEURISTIC);
|
xdl_opts |= revs.diffopt.xdl_opts & XDF_INDENT_HEURISTIC;
|
||||||
DIFF_OPT_CLR(&revs.diffopt, FOLLOW_RENAMES);
|
DIFF_OPT_CLR(&revs.diffopt, FOLLOW_RENAMES);
|
||||||
argc = parse_options_end(&ctx);
|
argc = parse_options_end(&ctx);
|
||||||
|
|
||||||
|
23
diff.c
23
diff.c
@ -28,7 +28,6 @@
|
|||||||
|
|
||||||
static int diff_detect_rename_default;
|
static int diff_detect_rename_default;
|
||||||
static int diff_indent_heuristic; /* experimental */
|
static int diff_indent_heuristic; /* experimental */
|
||||||
static int diff_compaction_heuristic; /* experimental */
|
|
||||||
static int diff_rename_limit_default = 400;
|
static int diff_rename_limit_default = 400;
|
||||||
static int diff_suppress_blank_empty;
|
static int diff_suppress_blank_empty;
|
||||||
static int diff_use_color_default = -1;
|
static int diff_use_color_default = -1;
|
||||||
@ -223,16 +222,8 @@ void init_diff_ui_defaults(void)
|
|||||||
|
|
||||||
int git_diff_heuristic_config(const char *var, const char *value, void *cb)
|
int git_diff_heuristic_config(const char *var, const char *value, void *cb)
|
||||||
{
|
{
|
||||||
if (!strcmp(var, "diff.indentheuristic")) {
|
if (!strcmp(var, "diff.indentheuristic"))
|
||||||
diff_indent_heuristic = git_config_bool(var, value);
|
diff_indent_heuristic = git_config_bool(var, value);
|
||||||
if (diff_indent_heuristic)
|
|
||||||
diff_compaction_heuristic = 0;
|
|
||||||
}
|
|
||||||
if (!strcmp(var, "diff.compactionheuristic")) {
|
|
||||||
diff_compaction_heuristic = git_config_bool(var, value);
|
|
||||||
if (diff_compaction_heuristic)
|
|
||||||
diff_indent_heuristic = 0;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3382,8 +3373,6 @@ void diff_setup(struct diff_options *options)
|
|||||||
options->xdl_opts |= diff_algorithm;
|
options->xdl_opts |= diff_algorithm;
|
||||||
if (diff_indent_heuristic)
|
if (diff_indent_heuristic)
|
||||||
DIFF_XDL_SET(options, INDENT_HEURISTIC);
|
DIFF_XDL_SET(options, INDENT_HEURISTIC);
|
||||||
else if (diff_compaction_heuristic)
|
|
||||||
DIFF_XDL_SET(options, COMPACTION_HEURISTIC);
|
|
||||||
|
|
||||||
options->orderfile = diff_order_file_cfg;
|
options->orderfile = diff_order_file_cfg;
|
||||||
|
|
||||||
@ -3878,16 +3867,10 @@ int diff_opt_parse(struct diff_options *options,
|
|||||||
DIFF_XDL_SET(options, IGNORE_WHITESPACE_AT_EOL);
|
DIFF_XDL_SET(options, IGNORE_WHITESPACE_AT_EOL);
|
||||||
else if (!strcmp(arg, "--ignore-blank-lines"))
|
else if (!strcmp(arg, "--ignore-blank-lines"))
|
||||||
DIFF_XDL_SET(options, IGNORE_BLANK_LINES);
|
DIFF_XDL_SET(options, IGNORE_BLANK_LINES);
|
||||||
else if (!strcmp(arg, "--indent-heuristic")) {
|
else if (!strcmp(arg, "--indent-heuristic"))
|
||||||
DIFF_XDL_SET(options, INDENT_HEURISTIC);
|
DIFF_XDL_SET(options, INDENT_HEURISTIC);
|
||||||
DIFF_XDL_CLR(options, COMPACTION_HEURISTIC);
|
else if (!strcmp(arg, "--no-indent-heuristic"))
|
||||||
} else if (!strcmp(arg, "--no-indent-heuristic"))
|
|
||||||
DIFF_XDL_CLR(options, INDENT_HEURISTIC);
|
DIFF_XDL_CLR(options, INDENT_HEURISTIC);
|
||||||
else if (!strcmp(arg, "--compaction-heuristic")) {
|
|
||||||
DIFF_XDL_SET(options, COMPACTION_HEURISTIC);
|
|
||||||
DIFF_XDL_CLR(options, INDENT_HEURISTIC);
|
|
||||||
} else if (!strcmp(arg, "--no-compaction-heuristic"))
|
|
||||||
DIFF_XDL_CLR(options, COMPACTION_HEURISTIC);
|
|
||||||
else if (!strcmp(arg, "--patience"))
|
else if (!strcmp(arg, "--patience"))
|
||||||
options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
|
options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
|
||||||
else if (!strcmp(arg, "--histogram"))
|
else if (!strcmp(arg, "--histogram"))
|
||||||
|
@ -47,7 +47,6 @@ my $normal_color = $repo->get_color("", "reset");
|
|||||||
|
|
||||||
my $diff_algorithm = $repo->config('diff.algorithm');
|
my $diff_algorithm = $repo->config('diff.algorithm');
|
||||||
my $diff_indent_heuristic = $repo->config_bool('diff.indentheuristic');
|
my $diff_indent_heuristic = $repo->config_bool('diff.indentheuristic');
|
||||||
my $diff_compaction_heuristic = $repo->config_bool('diff.compactionheuristic');
|
|
||||||
my $diff_filter = $repo->config('interactive.difffilter');
|
my $diff_filter = $repo->config('interactive.difffilter');
|
||||||
|
|
||||||
my $use_readkey = 0;
|
my $use_readkey = 0;
|
||||||
@ -742,8 +741,6 @@ sub parse_diff {
|
|||||||
}
|
}
|
||||||
if ($diff_indent_heuristic) {
|
if ($diff_indent_heuristic) {
|
||||||
splice @diff_cmd, 1, 0, "--indent-heuristic";
|
splice @diff_cmd, 1, 0, "--indent-heuristic";
|
||||||
} elsif ($diff_compaction_heuristic) {
|
|
||||||
splice @diff_cmd, 1, 0, "--compaction-heuristic";
|
|
||||||
}
|
}
|
||||||
if (defined $patch_mode_revision) {
|
if (defined $patch_mode_revision) {
|
||||||
push @diff_cmd, get_diff_reference($patch_mode_revision);
|
push @diff_cmd, get_diff_reference($patch_mode_revision);
|
||||||
|
@ -41,8 +41,7 @@ extern "C" {
|
|||||||
|
|
||||||
#define XDF_IGNORE_BLANK_LINES (1 << 7)
|
#define XDF_IGNORE_BLANK_LINES (1 << 7)
|
||||||
|
|
||||||
#define XDF_COMPACTION_HEURISTIC (1 << 8)
|
#define XDF_INDENT_HEURISTIC (1 << 8)
|
||||||
#define XDF_INDENT_HEURISTIC (1 << 9)
|
|
||||||
|
|
||||||
#define XDL_EMIT_FUNCNAMES (1 << 0)
|
#define XDL_EMIT_FUNCNAMES (1 << 0)
|
||||||
#define XDL_EMIT_FUNCCONTEXT (1 << 2)
|
#define XDL_EMIT_FUNCCONTEXT (1 << 2)
|
||||||
|
@ -400,11 +400,6 @@ static xdchange_t *xdl_add_change(xdchange_t *xscr, long i1, long i2, long chg1,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int is_blank_line(xrecord_t *rec, long flags)
|
|
||||||
{
|
|
||||||
return xdl_blankline(rec->ptr, rec->size, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int recs_match(xrecord_t *rec1, xrecord_t *rec2, long flags)
|
static int recs_match(xrecord_t *rec1, xrecord_t *rec2, long flags)
|
||||||
{
|
{
|
||||||
return (rec1->ha == rec2->ha &&
|
return (rec1->ha == rec2->ha &&
|
||||||
@ -821,7 +816,6 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
|
|||||||
struct xdlgroup g, go;
|
struct xdlgroup g, go;
|
||||||
long earliest_end, end_matching_other;
|
long earliest_end, end_matching_other;
|
||||||
long groupsize;
|
long groupsize;
|
||||||
unsigned int blank_lines;
|
|
||||||
|
|
||||||
group_init(xdf, &g);
|
group_init(xdf, &g);
|
||||||
group_init(xdfo, &go);
|
group_init(xdfo, &go);
|
||||||
@ -846,13 +840,6 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
|
|||||||
*/
|
*/
|
||||||
end_matching_other = -1;
|
end_matching_other = -1;
|
||||||
|
|
||||||
/*
|
|
||||||
* Boolean value that records whether there are any blank
|
|
||||||
* lines that could be made to be the last line of this
|
|
||||||
* group.
|
|
||||||
*/
|
|
||||||
blank_lines = 0;
|
|
||||||
|
|
||||||
/* Shift the group backward as much as possible: */
|
/* Shift the group backward as much as possible: */
|
||||||
while (!group_slide_up(xdf, &g, flags))
|
while (!group_slide_up(xdf, &g, flags))
|
||||||
if (group_previous(xdfo, &go))
|
if (group_previous(xdfo, &go))
|
||||||
@ -869,11 +856,6 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
|
|||||||
|
|
||||||
/* Now shift the group forward as far as possible: */
|
/* Now shift the group forward as far as possible: */
|
||||||
while (1) {
|
while (1) {
|
||||||
if (!blank_lines)
|
|
||||||
blank_lines = is_blank_line(
|
|
||||||
xdf->recs[g.end - 1],
|
|
||||||
flags);
|
|
||||||
|
|
||||||
if (group_slide_down(xdf, &g, flags))
|
if (group_slide_down(xdf, &g, flags))
|
||||||
break;
|
break;
|
||||||
if (group_next(xdfo, &go))
|
if (group_next(xdfo, &go))
|
||||||
@ -906,21 +888,6 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
|
|||||||
if (group_previous(xdfo, &go))
|
if (group_previous(xdfo, &go))
|
||||||
xdl_bug("group sync broken sliding to match");
|
xdl_bug("group sync broken sliding to match");
|
||||||
}
|
}
|
||||||
} else if ((flags & XDF_COMPACTION_HEURISTIC) && blank_lines) {
|
|
||||||
/*
|
|
||||||
* Compaction heuristic: if it is possible to shift the
|
|
||||||
* group to make its bottom line a blank line, do so.
|
|
||||||
*
|
|
||||||
* As we already shifted the group forward as far as
|
|
||||||
* possible in the earlier loop, we only need to handle
|
|
||||||
* backward shifts, not forward ones.
|
|
||||||
*/
|
|
||||||
while (!is_blank_line(xdf->recs[g.end - 1], flags)) {
|
|
||||||
if (group_slide_up(xdf, &g, flags))
|
|
||||||
xdl_bug("blank line disappeared");
|
|
||||||
if (group_previous(xdfo, &go))
|
|
||||||
xdl_bug("group sync broken sliding to blank line");
|
|
||||||
}
|
|
||||||
} else if (flags & XDF_INDENT_HEURISTIC) {
|
} else if (flags & XDF_INDENT_HEURISTIC) {
|
||||||
/*
|
/*
|
||||||
* Indent heuristic: a group of pure add/delete lines
|
* Indent heuristic: a group of pure add/delete lines
|
||||||
|
Loading…
Reference in New Issue
Block a user