From: Junio C Hamano Date: Tue, 19 Dec 2017 19:33:56 +0000 (-0800) Subject: Merge branch 'jt/diff-anchored-patience' X-Git-Tag: v2.16.0-rc0~48 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/d7c6c2369ac21141b7c6cceaebc6414ec3da14ad?ds=inline;hp=-c 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) --- d7c6c2369ac21141b7c6cceaebc6414ec3da14ad diff --combined diff.c index b3ef25c345,9ce83e675d..516f68dbb4 --- a/diff.c +++ b/diff.c @@@ -3210,6 -3210,8 +3210,8 @@@ static void builtin_diff(const char *na 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 +3304,8 @@@ static void builtin_diffstat(const cha 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 +4598,18 @@@ int diff_opt_parse(struct diff_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 +4621,11 @@@ 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 */ @@@ -5454,7 -5472,7 +5472,7 @@@ void diff_warn_rename_limit(const char warning(_(rename_limit_warning)); else return; - if (0 < needed && needed < 32767) + if (0 < needed) warning(_(rename_limit_advice), varname, needed); }