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>maint
parent
ced4e179fe
commit
f476308b27
35
diff.c
35
diff.c
|
@ -4909,6 +4909,22 @@ static int diff_opt_dirstat(const struct option *opt,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int diff_opt_find_renames(const struct option *opt,
|
||||||
|
const char *arg, int unset)
|
||||||
|
{
|
||||||
|
struct diff_options *options = opt->value;
|
||||||
|
|
||||||
|
BUG_ON_OPT_NEG(unset);
|
||||||
|
if (!arg)
|
||||||
|
arg = "";
|
||||||
|
options->rename_score = parse_rename_score(&arg);
|
||||||
|
if (*arg != 0)
|
||||||
|
return error(_("invalid argument to %s"), opt->long_name);
|
||||||
|
|
||||||
|
options->detect_rename = DIFF_DETECT_RENAME;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,
|
static enum parse_opt_result diff_opt_output(struct parse_opt_ctx_t *ctx,
|
||||||
const struct option *opt,
|
const struct option *opt,
|
||||||
const char *arg, int unset)
|
const char *arg, int unset)
|
||||||
|
@ -5040,6 +5056,10 @@ static void prep_parse_options(struct diff_options *options)
|
||||||
N_("break complete rewrite changes into pairs of delete and create"),
|
N_("break complete rewrite changes into pairs of delete and create"),
|
||||||
PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
|
PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
|
||||||
diff_opt_break_rewrites),
|
diff_opt_break_rewrites),
|
||||||
|
OPT_CALLBACK_F('M', "find-renames", options, N_("<n>"),
|
||||||
|
N_("detect renames"),
|
||||||
|
PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
|
||||||
|
diff_opt_find_renames),
|
||||||
|
|
||||||
OPT_GROUP(N_("Diff other options")),
|
OPT_GROUP(N_("Diff other options")),
|
||||||
{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
|
{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
|
||||||
|
@ -5074,13 +5094,7 @@ int diff_opt_parse(struct diff_options *options,
|
||||||
return ac;
|
return ac;
|
||||||
|
|
||||||
/* renames options */
|
/* renames options */
|
||||||
if (starts_with(arg, "-M") ||
|
if (!strcmp(arg, "-D") || !strcmp(arg, "--irreversible-delete")) {
|
||||||
skip_to_optional_arg(arg, "--find-renames", NULL)) {
|
|
||||||
if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
|
|
||||||
return error("invalid argument to -M: %s", arg+2);
|
|
||||||
options->detect_rename = DIFF_DETECT_RENAME;
|
|
||||||
}
|
|
||||||
else if (!strcmp(arg, "-D") || !strcmp(arg, "--irreversible-delete")) {
|
|
||||||
options->irreversible_delete = 1;
|
options->irreversible_delete = 1;
|
||||||
}
|
}
|
||||||
else if (starts_with(arg, "-C") ||
|
else if (starts_with(arg, "-C") ||
|
||||||
|
@ -5363,13 +5377,10 @@ static int diff_scoreopt_parse(const char *opt)
|
||||||
if (skip_prefix(opt, "find-copies", &opt)) {
|
if (skip_prefix(opt, "find-copies", &opt)) {
|
||||||
if (*opt == 0 || *opt++ == '=')
|
if (*opt == 0 || *opt++ == '=')
|
||||||
cmd = 'C';
|
cmd = 'C';
|
||||||
} else if (skip_prefix(opt, "find-renames", &opt)) {
|
|
||||||
if (*opt == 0 || *opt++ == '=')
|
|
||||||
cmd = 'M';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cmd != 'M' && cmd != 'C')
|
if (cmd != 'C')
|
||||||
return -1; /* that is not a -M, or -C option */
|
return -1; /* that is not a -M option */
|
||||||
|
|
||||||
opt1 = parse_rename_score(&opt);
|
opt1 = parse_rename_score(&opt);
|
||||||
if (*opt != 0)
|
if (*opt != 0)
|
||||||
|
|
Loading…
Reference in New Issue