diff-parseopt: convert -B|--break-rewrites

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:
Nguyễn Thái Ngọc Duy 2019-02-21 18:16:13 +07:00 коммит произвёл Junio C Hamano
Родитель af2f368091
Коммит ced4e179fe
1 изменённых файлов: 36 добавлений и 26 удалений

62
diff.c
Просмотреть файл

@ -4841,6 +4841,30 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)
return 1;
}
static int diff_opt_break_rewrites(const struct option *opt,
const char *arg, int unset)
{
int *break_opt = opt->value;
int opt1, opt2;
BUG_ON_OPT_NEG(unset);
if (!arg)
arg = "";
opt1 = parse_rename_score(&arg);
if (*arg == 0)
opt2 = 0;
else if (*arg != '/')
return error(_("%s expects <n>/<m> form"), opt->long_name);
else {
arg++;
opt2 = parse_rename_score(&arg);
}
if (*arg != 0)
return error(_("%s expects <n>/<m> form"), opt->long_name);
*break_opt = opt1 | (opt2 << 16);
return 0;
}
static int diff_opt_char(const struct option *opt,
const char *arg, int unset)
{
@ -5011,6 +5035,12 @@ static void prep_parse_options(struct diff_options *options)
N_("specify the character to indicate a context instead of ' '"),
PARSE_OPT_NONEG, diff_opt_char),
OPT_GROUP(N_("Diff rename options")),
OPT_CALLBACK_F('B', "break-rewrites", &options->break_opt, N_("<n>[/<m>]"),
N_("break complete rewrite changes into pairs of delete and create"),
PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
diff_opt_break_rewrites),
OPT_GROUP(N_("Diff other options")),
{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
N_("Output to a specific file"),
@ -5044,12 +5074,7 @@ int diff_opt_parse(struct diff_options *options,
return ac;
/* renames options */
if (starts_with(arg, "-B") ||
skip_to_optional_arg(arg, "--break-rewrites", NULL)) {
if ((options->break_opt = diff_scoreopt_parse(arg)) == -1)
return error("invalid argument to -B: %s", arg+2);
}
else if (starts_with(arg, "-M") ||
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);
@ -5328,17 +5353,14 @@ int parse_rename_score(const char **cp_p)
static int diff_scoreopt_parse(const char *opt)
{
int opt1, opt2, cmd;
int opt1, cmd;
if (*opt++ != '-')
return -1;
cmd = *opt++;
if (cmd == '-') {
/* convert the long-form arguments into short-form versions */
if (skip_prefix(opt, "break-rewrites", &opt)) {
if (*opt == 0 || *opt++ == '=')
cmd = 'B';
} else if (skip_prefix(opt, "find-copies", &opt)) {
if (skip_prefix(opt, "find-copies", &opt)) {
if (*opt == 0 || *opt++ == '=')
cmd = 'C';
} else if (skip_prefix(opt, "find-renames", &opt)) {
@ -5346,25 +5368,13 @@ static int diff_scoreopt_parse(const char *opt)
cmd = 'M';
}
}
if (cmd != 'M' && cmd != 'C' && cmd != 'B')
return -1; /* that is not a -M, -C, or -B option */
if (cmd != 'M' && cmd != 'C')
return -1; /* that is not a -M, or -C option */
opt1 = parse_rename_score(&opt);
if (cmd != 'B')
opt2 = 0;
else {
if (*opt == 0)
opt2 = 0;
else if (*opt != '/')
return -1; /* we expect -B80/99 or -B80 */
else {
opt++;
opt2 = parse_rename_score(&opt);
}
}
if (*opt != 0)
return -1;
return opt1 | (opt2 << 16);
return opt1;
}
struct diff_queue_struct diff_queued_diff;