diff-parseopt: convert -C|--find-copies
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
1e5332968a
commit
7f64850d36
59
diff.c
59
diff.c
@ -4617,8 +4617,6 @@ static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *va
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int diff_scoreopt_parse(const char *opt);
|
|
||||||
|
|
||||||
static inline int short_opt(char opt, const char **argv,
|
static inline int short_opt(char opt, const char **argv,
|
||||||
const char **optarg)
|
const char **optarg)
|
||||||
{
|
{
|
||||||
@ -4909,6 +4907,26 @@ static int diff_opt_dirstat(const struct option *opt,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int diff_opt_find_copies(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);
|
||||||
|
|
||||||
|
if (options->detect_rename == DIFF_DETECT_COPY)
|
||||||
|
options->flags.find_copies_harder = 1;
|
||||||
|
else
|
||||||
|
options->detect_rename = DIFF_DETECT_COPY;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int diff_opt_find_renames(const struct option *opt,
|
static int diff_opt_find_renames(const struct option *opt,
|
||||||
const char *arg, int unset)
|
const char *arg, int unset)
|
||||||
{
|
{
|
||||||
@ -5063,6 +5081,10 @@ static void prep_parse_options(struct diff_options *options)
|
|||||||
OPT_SET_INT_F('D', "irreversible-delete", &options->irreversible_delete,
|
OPT_SET_INT_F('D', "irreversible-delete", &options->irreversible_delete,
|
||||||
N_("omit the preimage for deletes"),
|
N_("omit the preimage for deletes"),
|
||||||
1, PARSE_OPT_NONEG),
|
1, PARSE_OPT_NONEG),
|
||||||
|
OPT_CALLBACK_F('C', "find-copies", options, N_("<n>"),
|
||||||
|
N_("detect copies"),
|
||||||
|
PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
|
||||||
|
diff_opt_find_copies),
|
||||||
|
|
||||||
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>"),
|
||||||
@ -5097,15 +5119,7 @@ int diff_opt_parse(struct diff_options *options,
|
|||||||
return ac;
|
return ac;
|
||||||
|
|
||||||
/* renames options */
|
/* renames options */
|
||||||
if (starts_with(arg, "-C") ||
|
if (!strcmp(arg, "--no-renames"))
|
||||||
skip_to_optional_arg(arg, "--find-copies", NULL)) {
|
|
||||||
if (options->detect_rename == DIFF_DETECT_COPY)
|
|
||||||
options->flags.find_copies_harder = 1;
|
|
||||||
if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
|
|
||||||
return error("invalid argument to -C: %s", arg+2);
|
|
||||||
options->detect_rename = DIFF_DETECT_COPY;
|
|
||||||
}
|
|
||||||
else if (!strcmp(arg, "--no-renames"))
|
|
||||||
options->detect_rename = 0;
|
options->detect_rename = 0;
|
||||||
else if (!strcmp(arg, "--rename-empty"))
|
else if (!strcmp(arg, "--rename-empty"))
|
||||||
options->flags.rename_empty = 1;
|
options->flags.rename_empty = 1;
|
||||||
@ -5365,29 +5379,6 @@ int parse_rename_score(const char **cp_p)
|
|||||||
return (int)((num >= scale) ? MAX_SCORE : (MAX_SCORE * num / scale));
|
return (int)((num >= scale) ? MAX_SCORE : (MAX_SCORE * num / scale));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int diff_scoreopt_parse(const char *opt)
|
|
||||||
{
|
|
||||||
int opt1, cmd;
|
|
||||||
|
|
||||||
if (*opt++ != '-')
|
|
||||||
return -1;
|
|
||||||
cmd = *opt++;
|
|
||||||
if (cmd == '-') {
|
|
||||||
/* convert the long-form arguments into short-form versions */
|
|
||||||
if (skip_prefix(opt, "find-copies", &opt)) {
|
|
||||||
if (*opt == 0 || *opt++ == '=')
|
|
||||||
cmd = 'C';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (cmd != 'C')
|
|
||||||
return -1; /* that is not a -M option */
|
|
||||||
|
|
||||||
opt1 = parse_rename_score(&opt);
|
|
||||||
if (*opt != 0)
|
|
||||||
return -1;
|
|
||||||
return opt1;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct diff_queue_struct diff_queued_diff;
|
struct diff_queue_struct diff_queued_diff;
|
||||||
|
|
||||||
void diff_q(struct diff_queue_struct *queue, struct diff_filepair *dp)
|
void diff_q(struct diff_queue_struct *queue, struct diff_filepair *dp)
|
||||||
|
Loading…
Reference in New Issue
Block a user