summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2019-02-21 11:16:14 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-02-21 23:16:59 (GMT)
commitf476308b273bdc78f9a8921b2bafffd39ea1e00e (patch)
tree77a31f7853d2e35296cd1d801677949559729a2b /diff.c
parentced4e179feaadd2c0b43fa963acedc7243d09a58 (diff)
downloadgit-f476308b273bdc78f9a8921b2bafffd39ea1e00e.zip
git-f476308b273bdc78f9a8921b2bafffd39ea1e00e.tar.gz
git-f476308b273bdc78f9a8921b2bafffd39ea1e00e.tar.bz2
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>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/diff.c b/diff.c
index d213908..2c904e0 100644
--- a/diff.c
+++ b/diff.c
@@ -4909,6 +4909,22 @@ static int diff_opt_dirstat(const struct option *opt,
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,
const struct option *opt,
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"),
PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
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")),
{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
@@ -5074,13 +5094,7 @@ int diff_opt_parse(struct diff_options *options,
return ac;
/* renames options */
- if (starts_with(arg, "-M") ||
- 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")) {
+ if (!strcmp(arg, "-D") || !strcmp(arg, "--irreversible-delete")) {
options->irreversible_delete = 1;
}
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 (*opt == 0 || *opt++ == '=')
cmd = 'C';
- } else if (skip_prefix(opt, "find-renames", &opt)) {
- if (*opt == 0 || *opt++ == '=')
- cmd = 'M';
}
}
- if (cmd != 'M' && cmd != 'C')
- return -1; /* that is not a -M, or -C option */
+ if (cmd != 'C')
+ return -1; /* that is not a -M option */
opt1 = parse_rename_score(&opt);
if (*opt != 0)