From f476308b273bdc78f9a8921b2bafffd39ea1e00e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 21 Feb 2019 18:16:14 +0700 Subject: [PATCH] diff-parseopt: convert -M|--find-renames MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- diff.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/diff.c b/diff.c index d2139082b7..2c904e0526 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_("detect renames"), + PARSE_OPT_NONEG | PARSE_OPT_OPTARG, + diff_opt_find_renames), OPT_GROUP(N_("Diff other options")), { OPTION_CALLBACK, 0, "output", options, N_(""), @@ -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) -- 2.43.2