summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-12-19 19:33:56 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-12-19 19:33:56 (GMT)
commitd7c6c2369ac21141b7c6cceaebc6414ec3da14ad (patch)
tree9aa0b15668a5bffa1f05e766eebab1d3cbafb380 /diff.c
parent6d2c4619a59d53325e6de2265205c407767bde9d (diff)
parent2477ab2ea8651920a9909f6d05b15ad9004a6c64 (diff)
downloadgit-d7c6c2369ac21141b7c6cceaebc6414ec3da14ad.zip
git-d7c6c2369ac21141b7c6cceaebc6414ec3da14ad.tar.gz
git-d7c6c2369ac21141b7c6cceaebc6414ec3da14ad.tar.bz2
Merge branch 'jt/diff-anchored-patience'
"git diff" learned a variant of the "--patience" algorithm, to which the user can specify which 'unique' line to be used as anchoring points. * jt/diff-anchored-patience: diff: support anchoring line(s)
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/diff.c b/diff.c
index b3ef25c..516f68d 100644
--- a/diff.c
+++ b/diff.c
@@ -3210,6 +3210,8 @@ static void builtin_diff(const char *name_a,
ecbdata.opt = o;
ecbdata.header = header.len ? &header : NULL;
xpp.flags = o->xdl_opts;
+ xpp.anchors = o->anchors;
+ xpp.anchors_nr = o->anchors_nr;
xecfg.ctxlen = o->context;
xecfg.interhunkctxlen = o->interhunkcontext;
xecfg.flags = XDL_EMIT_FUNCNAMES;
@@ -3302,6 +3304,8 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
memset(&xpp, 0, sizeof(xpp));
memset(&xecfg, 0, sizeof(xecfg));
xpp.flags = o->xdl_opts;
+ xpp.anchors = o->anchors;
+ xpp.anchors_nr = o->anchors_nr;
xecfg.ctxlen = o->context;
xecfg.interhunkctxlen = o->interhunkcontext;
if (xdi_diff_outf(&mf1, &mf2, diffstat_consume, diffstat,
@@ -4594,9 +4598,18 @@ int diff_opt_parse(struct diff_options *options,
DIFF_XDL_SET(options, INDENT_HEURISTIC);
else if (!strcmp(arg, "--no-indent-heuristic"))
DIFF_XDL_CLR(options, INDENT_HEURISTIC);
- else if (!strcmp(arg, "--patience"))
+ else if (!strcmp(arg, "--patience")) {
+ int i;
options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
- else if (!strcmp(arg, "--histogram"))
+ /*
+ * Both --patience and --anchored use PATIENCE_DIFF
+ * internally, so remove any anchors previously
+ * specified.
+ */
+ for (i = 0; i < options->anchors_nr; i++)
+ free(options->anchors[i]);
+ options->anchors_nr = 0;
+ } else if (!strcmp(arg, "--histogram"))
options->xdl_opts = DIFF_WITH_ALG(options, HISTOGRAM_DIFF);
else if ((argcount = parse_long_opt("diff-algorithm", av, &optarg))) {
long value = parse_algorithm_value(optarg);
@@ -4608,6 +4621,11 @@ int diff_opt_parse(struct diff_options *options,
options->xdl_opts &= ~XDF_DIFF_ALGORITHM_MASK;
options->xdl_opts |= value;
return argcount;
+ } else if (skip_prefix(arg, "--anchored=", &arg)) {
+ options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
+ ALLOC_GROW(options->anchors, options->anchors_nr + 1,
+ options->anchors_alloc);
+ options->anchors[options->anchors_nr++] = xstrdup(arg);
}
/* flags options */