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)
{
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"),
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);
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)) {
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;