diff: use skip_to_optional_arg()
Let's simplify diff option parsing using skip_to_optional_arg(). Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Dec 9, 2017 at 21:40 UTC
948cbe6703d0d1e3ba65fd10037bafd1b8b87696
1 file changed
+9
-14
diff.c
+9
-14
@@ -4508,17 +4508,12 @@ int diff_opt_parse(struct diff_options *options,
4508
options->output_format |= DIFF_FORMAT_NUMSTAT;
4509
else if (!strcmp(arg, "--shortstat"))
4510
options->output_format |= DIFF_FORMAT_SHORTSTAT;
4511
- else if (!strcmp(arg, "-X") || !strcmp(arg, "--dirstat"))
4512
- return parse_dirstat_opt(options, "");
4513
- else if (skip_prefix(arg, "-X", &arg))
4514
- return parse_dirstat_opt(options, arg);
4515
- else if (skip_prefix(arg, "--dirstat=", &arg))
4511
+ else if (skip_prefix(arg, "-X", &arg) ||
4512
+ skip_to_optional_arg(arg, "--dirstat", &arg))
4513
return parse_dirstat_opt(options, arg);
4514
else if (!strcmp(arg, "--cumulative"))
4515
return parse_dirstat_opt(options, "cumulative");
4519
- else if (!strcmp(arg, "--dirstat-by-file"))
4520
- return parse_dirstat_opt(options, "files");
4521
- else if (skip_prefix(arg, "--dirstat-by-file=", &arg)) {
4516
+ else if (skip_to_optional_arg(arg, "--dirstat-by-file", &arg)) {
4517
parse_dirstat_opt(options, "files");
4518
return parse_dirstat_opt(options, arg);
4519
}
@@ -4540,13 +4535,13 @@ int diff_opt_parse(struct diff_options *options,
4535
return stat_opt(options, av);
4536
4537
/* renames options */
4543
- else if (starts_with(arg, "-B") || starts_with(arg, "--break-rewrites=") ||
4544
- !strcmp(arg, "--break-rewrites")) {
4538
+ else if (starts_with(arg, "-B") ||
4539
+ skip_to_optional_arg(arg, "--break-rewrites", NULL)) {
4540
if ((options->break_opt = diff_scoreopt_parse(arg)) == -1)
4541
return error("invalid argument to -B: %s", arg+2);
4542
}
4548
- else if (starts_with(arg, "-M") || starts_with(arg, "--find-renames=") ||
4549
- !strcmp(arg, "--find-renames")) {
4543
+ else if (starts_with(arg, "-M") ||
4544
+ skip_to_optional_arg(arg, "--find-renames", NULL)) {
4545
if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
4546
return error("invalid argument to -M: %s", arg+2);
4547
options->detect_rename = DIFF_DETECT_RENAME;
@@ -4554,8 +4549,8 @@ int diff_opt_parse(struct diff_options *options,
4549
else if (!strcmp(arg, "-D") || !strcmp(arg, "--irreversible-delete")) {
4550
options->irreversible_delete = 1;
4551
}
4557
- else if (starts_with(arg, "-C") || starts_with(arg, "--find-copies=") ||
4558
- !strcmp(arg, "--find-copies")) {
4552
+ else if (starts_with(arg, "-C") ||
4553
+ skip_to_optional_arg(arg, "--find-copies", NULL)) {
4554
if (options->detect_rename == DIFF_DETECT_COPY)
4555
options->flags.find_copies_harder = 1;
4556
if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)