diff-parseopt: convert --diff-algorithm

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Mar 5, 2019 at 19:30 UTC 10f35b1cc01875e5fc2c02698f0e724578b38a53
1 file changed +22 -11
diff.c
+22 -11
@@ -4891,6 +4891,24 @@ static int diff_opt_compact_summary(const struct option *opt,
4891 return 0;
4892 }
4893
4894 +static int diff_opt_diff_algorithm(const struct option *opt,
4895 + const char *arg, int unset)
4896 +{
4897 + struct diff_options *options = opt->value;
4898 + long value = parse_algorithm_value(arg);
4899 +
4900 + BUG_ON_OPT_NEG(unset);
4901 + if (value < 0)
4902 + return error(_("option diff-algorithm accepts \"myers\", "
4903 + "\"minimal\", \"patience\" and \"histogram\""));
4904 +
4905 + /* clear out previous settings */
4906 + DIFF_XDL_CLR(options, NEED_MINIMAL);
4907 + options->xdl_opts &= ~XDF_DIFF_ALGORITHM_MASK;
4908 + options->xdl_opts |= value;
4909 + return 0;
4910 +}
4911 +
4912 static int diff_opt_dirstat(const struct option *opt,
4913 const char *arg, int unset)
4914 {
@@ -5154,6 +5172,9 @@ static void prep_parse_options(struct diff_options *options)
5172 OPT_BITOP(0, "histogram", &options->xdl_opts,
5173 N_("generate diff using the \"histogram diff\" algorithm"),
5174 XDF_HISTOGRAM_DIFF, XDF_DIFF_ALGORITHM_MASK),
5175 + OPT_CALLBACK_F(0, "diff-algorithm", options, N_("<algorithm>"),
5176 + N_("choose a diff algorithm"),
5177 + PARSE_OPT_NONEG, diff_opt_diff_algorithm),
5178
5179 OPT_GROUP(N_("Diff other options")),
5180 OPT_CALLBACK_F(0, "relative", options, N_("<prefix>"),
@@ -5192,17 +5213,7 @@ int diff_opt_parse(struct diff_options *options,
5213 return ac;
5214
5215 /* xdiff options */
5195 - if ((argcount = parse_long_opt("diff-algorithm", av, &optarg))) {
5196 - long value = parse_algorithm_value(optarg);
5197 - if (value < 0)
5198 - return error("option diff-algorithm accepts \"myers\", "
5199 - "\"minimal\", \"patience\" and \"histogram\"");
5200 - /* clear out previous settings */
5201 - DIFF_XDL_CLR(options, NEED_MINIMAL);
5202 - options->xdl_opts &= ~XDF_DIFF_ALGORITHM_MASK;
5203 - options->xdl_opts |= value;
5204 - return argcount;
5205 - } else if (skip_prefix(arg, "--anchored=", &arg)) {
5216 + if (skip_prefix(arg, "--anchored=", &arg)) {
5217 options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
5218 ALLOC_GROW(options->anchors, options->anchors_nr + 1,
5219 options->anchors_alloc);