diff-parseopt: convert -M|--find-renames
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
Feb 21, 2019 at 18:16 UTC
f476308b273bdc78f9a8921b2bafffd39ea1e00e
1 file changed
+23
-12
diff.c
+23
-12
@@ -4909,6 +4909,22 @@ static int diff_opt_dirstat(const struct option *opt,
4909
return 0;
4910
}
4911
4912
+static int diff_opt_find_renames(const struct option *opt,
4913
+ const char *arg, int unset)
4914
+{
4915
+ struct diff_options *options = opt->value;
4916
+
4917
+ BUG_ON_OPT_NEG(unset);
4918
+ if (!arg)
4919
+ arg = "";
4920
+ options->rename_score = parse_rename_score(&arg);
4921
+ if (*arg != 0)
4922
+ return error(_("invalid argument to %s"), opt->long_name);
4923
+
4924
+ options->detect_rename = DIFF_DETECT_RENAME;
4925
+ return 0;
4926
+}
4927
+
4928
static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,
4929
const struct option *opt,
4930
const char *arg, int unset)
@@ -5040,6 +5056,10 @@ static void prep_parse_options(struct diff_options *options)
5056
N_("break complete rewrite changes into pairs of delete and create"),
5057
PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
5058
diff_opt_break_rewrites),
5059
+ OPT_CALLBACK_F('M', "find-renames", options, N_("<n>"),
5060
+ N_("detect renames"),
5061
+ PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
5062
+ diff_opt_find_renames),
5063
5064
OPT_GROUP(N_("Diff other options")),
5065
{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
@@ -5074,13 +5094,7 @@ int diff_opt_parse(struct diff_options *options,
5094
return ac;
5095
5096
/* renames options */
5077
- if (starts_with(arg, "-M") ||
5078
- skip_to_optional_arg(arg, "--find-renames", NULL)) {
5079
- if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
5080
- return error("invalid argument to -M: %s", arg+2);
5081
- options->detect_rename = DIFF_DETECT_RENAME;
5082
- }
5083
- else if (!strcmp(arg, "-D") || !strcmp(arg, "--irreversible-delete")) {
5097
+ if (!strcmp(arg, "-D") || !strcmp(arg, "--irreversible-delete")) {
5098
options->irreversible_delete = 1;
5099
}
5100
else if (starts_with(arg, "-C") ||
@@ -5363,13 +5377,10 @@ static int diff_scoreopt_parse(const char *opt)
5377
if (skip_prefix(opt, "find-copies", &opt)) {
5378
if (*opt == 0 || *opt++ == '=')
5379
cmd = 'C';
5366
- } else if (skip_prefix(opt, "find-renames", &opt)) {
5367
- if (*opt == 0 || *opt++ == '=')
5368
- cmd = 'M';
5380
}
5381
}
5371
- if (cmd != 'M' && cmd != 'C')
5372
- return -1; /* that is not a -M, or -C option */
5382
+ if (cmd != 'C')
5383
+ return -1; /* that is not a -M option */
5384
5385
opt1 = parse_rename_score(&opt);
5386
if (*opt != 0)