Skip to content

Commit 948cbe6

Browse files
chriscoolgitster
authored andcommitted
diff: use skip_to_optional_arg()
Let's simplify diff option parsing using skip_to_optional_arg(). Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 72885a6 commit 948cbe6

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

diff.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4508,17 +4508,12 @@ int diff_opt_parse(struct diff_options *options,
45084508
options->output_format |= DIFF_FORMAT_NUMSTAT;
45094509
else if (!strcmp(arg, "--shortstat"))
45104510
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))
45164513
return parse_dirstat_opt(options, arg);
45174514
else if (!strcmp(arg, "--cumulative"))
45184515
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)) {
45224517
parse_dirstat_opt(options, "files");
45234518
return parse_dirstat_opt(options, arg);
45244519
}
@@ -4540,22 +4535,22 @@ int diff_opt_parse(struct diff_options *options,
45404535
return stat_opt(options, av);
45414536

45424537
/* 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)) {
45454540
if ((options->break_opt = diff_scoreopt_parse(arg)) == -1)
45464541
return error("invalid argument to -B: %s", arg+2);
45474542
}
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)) {
45504545
if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
45514546
return error("invalid argument to -M: %s", arg+2);
45524547
options->detect_rename = DIFF_DETECT_RENAME;
45534548
}
45544549
else if (!strcmp(arg, "-D") || !strcmp(arg, "--irreversible-delete")) {
45554550
options->irreversible_delete = 1;
45564551
}
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)) {
45594554
if (options->detect_rename == DIFF_DETECT_COPY)
45604555
options->flags.find_copies_harder = 1;
45614556
if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)

0 commit comments

Comments
 (0)