@@ -4512,17 +4512,12 @@ int diff_opt_parse(struct diff_options *options,
4512
4512
options -> output_format |= DIFF_FORMAT_NUMSTAT ;
4513
4513
else if (!strcmp (arg , "--shortstat" ))
4514
4514
options -> output_format |= DIFF_FORMAT_SHORTSTAT ;
4515
- else if (!strcmp (arg , "-X" ) || !strcmp (arg , "--dirstat" ))
4516
- return parse_dirstat_opt (options , "" );
4517
- else if (skip_prefix (arg , "-X" , & arg ))
4518
- return parse_dirstat_opt (options , arg );
4519
- else if (skip_prefix (arg , "--dirstat=" , & arg ))
4515
+ else if (skip_prefix (arg , "-X" , & arg ) ||
4516
+ skip_to_optional_arg (arg , "--dirstat" , & arg ))
4520
4517
return parse_dirstat_opt (options , arg );
4521
4518
else if (!strcmp (arg , "--cumulative" ))
4522
4519
return parse_dirstat_opt (options , "cumulative" );
4523
- else if (!strcmp (arg , "--dirstat-by-file" ))
4524
- return parse_dirstat_opt (options , "files" );
4525
- else if (skip_prefix (arg , "--dirstat-by-file=" , & arg )) {
4520
+ else if (skip_to_optional_arg (arg , "--dirstat-by-file" , & arg )) {
4526
4521
parse_dirstat_opt (options , "files" );
4527
4522
return parse_dirstat_opt (options , arg );
4528
4523
}
@@ -4544,22 +4539,22 @@ int diff_opt_parse(struct diff_options *options,
4544
4539
return stat_opt (options , av );
4545
4540
4546
4541
/* renames options */
4547
- else if (starts_with (arg , "-B" ) || starts_with ( arg , "--break-rewrites=" ) ||
4548
- ! strcmp (arg , "--break-rewrites" )) {
4542
+ else if (starts_with (arg , "-B" ) ||
4543
+ skip_to_optional_arg (arg , "--break-rewrites" , NULL )) {
4549
4544
if ((options -> break_opt = diff_scoreopt_parse (arg )) == -1 )
4550
4545
return error ("invalid argument to -B: %s" , arg + 2 );
4551
4546
}
4552
- else if (starts_with (arg , "-M" ) || starts_with ( arg , "--find-renames=" ) ||
4553
- ! strcmp (arg , "--find-renames" )) {
4547
+ else if (starts_with (arg , "-M" ) ||
4548
+ skip_to_optional_arg (arg , "--find-renames" , NULL )) {
4554
4549
if ((options -> rename_score = diff_scoreopt_parse (arg )) == -1 )
4555
4550
return error ("invalid argument to -M: %s" , arg + 2 );
4556
4551
options -> detect_rename = DIFF_DETECT_RENAME ;
4557
4552
}
4558
4553
else if (!strcmp (arg , "-D" ) || !strcmp (arg , "--irreversible-delete" )) {
4559
4554
options -> irreversible_delete = 1 ;
4560
4555
}
4561
- else if (starts_with (arg , "-C" ) || starts_with ( arg , "--find-copies=" ) ||
4562
- ! strcmp (arg , "--find-copies" )) {
4556
+ else if (starts_with (arg , "-C" ) ||
4557
+ skip_to_optional_arg (arg , "--find-copies" , NULL )) {
4563
4558
if (options -> detect_rename == DIFF_DETECT_COPY )
4564
4559
options -> flags .find_copies_harder = 1 ;
4565
4560
if ((options -> rename_score = diff_scoreopt_parse (arg )) == -1 )
@@ -4572,11 +4567,10 @@ int diff_opt_parse(struct diff_options *options,
4572
4567
options -> flags .rename_empty = 1 ;
4573
4568
else if (!strcmp (arg , "--no-rename-empty" ))
4574
4569
options -> flags .rename_empty = 0 ;
4575
- else if (!strcmp (arg , "--relative" ))
4576
- options -> flags .relative_name = 1 ;
4577
- else if (skip_prefix (arg , "--relative=" , & arg )) {
4570
+ else if (skip_to_optional_arg_default (arg , "--relative" , & arg , NULL )) {
4578
4571
options -> flags .relative_name = 1 ;
4579
- options -> prefix = arg ;
4572
+ if (arg )
4573
+ options -> prefix = arg ;
4580
4574
}
4581
4575
4582
4576
/* xdiff options */
@@ -4646,9 +4640,7 @@ int diff_opt_parse(struct diff_options *options,
4646
4640
else if (!strcmp (arg , "--no-follow" )) {
4647
4641
options -> flags .follow_renames = 0 ;
4648
4642
options -> flags .default_follow_renames = 0 ;
4649
- } else if (!strcmp (arg , "--color" ))
4650
- options -> use_color = 1 ;
4651
- else if (skip_prefix (arg , "--color=" , & arg )) {
4643
+ } else if (skip_to_optional_arg_default (arg , "--color" , & arg , "always" )) {
4652
4644
int value = git_config_colorbool (NULL , arg );
4653
4645
if (value < 0 )
4654
4646
return error ("option `color' expects \"always\", \"auto\", or \"never\"" );
@@ -4668,14 +4660,9 @@ int diff_opt_parse(struct diff_options *options,
4668
4660
if (cm < 0 )
4669
4661
die ("bad --color-moved argument: %s" , arg );
4670
4662
options -> color_moved = cm ;
4671
- } else if (!strcmp (arg , "--color-words" )) {
4672
- options -> use_color = 1 ;
4673
- options -> word_diff = DIFF_WORDS_COLOR ;
4674
- }
4675
- else if (skip_prefix (arg , "--color-words=" , & arg )) {
4663
+ } else if (skip_to_optional_arg_default (arg , "--color-words" , & options -> word_regex , NULL )) {
4676
4664
options -> use_color = 1 ;
4677
4665
options -> word_diff = DIFF_WORDS_COLOR ;
4678
- options -> word_regex = arg ;
4679
4666
}
4680
4667
else if (!strcmp (arg , "--word-diff" )) {
4681
4668
if (options -> word_diff == DIFF_WORDS_NONE )
@@ -4714,15 +4701,10 @@ int diff_opt_parse(struct diff_options *options,
4714
4701
options -> flags .textconv_set_via_cmdline = 1 ;
4715
4702
} else if (!strcmp (arg , "--no-textconv" ))
4716
4703
options -> flags .allow_textconv = 0 ;
4717
- else if (!strcmp (arg , "--ignore-submodules" )) {
4718
- options -> flags .override_submodule_config = 1 ;
4719
- handle_ignore_submodules_arg (options , "all" );
4720
- } else if (skip_prefix (arg , "--ignore-submodules=" , & arg )) {
4704
+ else if (skip_to_optional_arg_default (arg , "--ignore-submodules" , & arg , "all" )) {
4721
4705
options -> flags .override_submodule_config = 1 ;
4722
4706
handle_ignore_submodules_arg (options , arg );
4723
- } else if (!strcmp (arg , "--submodule" ))
4724
- options -> submodule_format = DIFF_SUBMODULE_LOG ;
4725
- else if (skip_prefix (arg , "--submodule=" , & arg ))
4707
+ } else if (skip_to_optional_arg_default (arg , "--submodule" , & arg , "log" ))
4726
4708
return parse_submodule_opt (options , arg );
4727
4709
else if (skip_prefix (arg , "--ws-error-highlight=" , & arg ))
4728
4710
return parse_ws_error_highlight_opt (options , arg );
0 commit comments