@@ -4512,17 +4512,12 @@ int diff_opt_parse(struct diff_options *options,
45124512 options -> output_format |= DIFF_FORMAT_NUMSTAT ;
45134513 else if (!strcmp (arg , "--shortstat" ))
45144514 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 ))
45204517 return parse_dirstat_opt (options , arg );
45214518 else if (!strcmp (arg , "--cumulative" ))
45224519 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 )) {
45264521 parse_dirstat_opt (options , "files" );
45274522 return parse_dirstat_opt (options , arg );
45284523 }
@@ -4544,22 +4539,22 @@ int diff_opt_parse(struct diff_options *options,
45444539 return stat_opt (options , av );
45454540
45464541 /* 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 )) {
45494544 if ((options -> break_opt = diff_scoreopt_parse (arg )) == -1 )
45504545 return error ("invalid argument to -B: %s" , arg + 2 );
45514546 }
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 )) {
45544549 if ((options -> rename_score = diff_scoreopt_parse (arg )) == -1 )
45554550 return error ("invalid argument to -M: %s" , arg + 2 );
45564551 options -> detect_rename = DIFF_DETECT_RENAME ;
45574552 }
45584553 else if (!strcmp (arg , "-D" ) || !strcmp (arg , "--irreversible-delete" )) {
45594554 options -> irreversible_delete = 1 ;
45604555 }
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 )) {
45634558 if (options -> detect_rename == DIFF_DETECT_COPY )
45644559 options -> flags .find_copies_harder = 1 ;
45654560 if ((options -> rename_score = diff_scoreopt_parse (arg )) == -1 )
@@ -4572,11 +4567,10 @@ int diff_opt_parse(struct diff_options *options,
45724567 options -> flags .rename_empty = 1 ;
45734568 else if (!strcmp (arg , "--no-rename-empty" ))
45744569 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 )) {
45784571 options -> flags .relative_name = 1 ;
4579- options -> prefix = arg ;
4572+ if (arg )
4573+ options -> prefix = arg ;
45804574 }
45814575
45824576 /* xdiff options */
@@ -4646,9 +4640,7 @@ int diff_opt_parse(struct diff_options *options,
46464640 else if (!strcmp (arg , "--no-follow" )) {
46474641 options -> flags .follow_renames = 0 ;
46484642 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" )) {
46524644 int value = git_config_colorbool (NULL , arg );
46534645 if (value < 0 )
46544646 return error ("option `color' expects \"always\", \"auto\", or \"never\"" );
@@ -4668,14 +4660,9 @@ int diff_opt_parse(struct diff_options *options,
46684660 if (cm < 0 )
46694661 die ("bad --color-moved argument: %s" , arg );
46704662 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 )) {
46764664 options -> use_color = 1 ;
46774665 options -> word_diff = DIFF_WORDS_COLOR ;
4678- options -> word_regex = arg ;
46794666 }
46804667 else if (!strcmp (arg , "--word-diff" )) {
46814668 if (options -> word_diff == DIFF_WORDS_NONE )
@@ -4714,15 +4701,10 @@ int diff_opt_parse(struct diff_options *options,
47144701 options -> flags .textconv_set_via_cmdline = 1 ;
47154702 } else if (!strcmp (arg , "--no-textconv" ))
47164703 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" )) {
47214705 options -> flags .override_submodule_config = 1 ;
47224706 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" ))
47264708 return parse_submodule_opt (options , arg );
47274709 else if (skip_prefix (arg , "--ws-error-highlight=" , & arg ))
47284710 return parse_ws_error_highlight_opt (options , arg );
0 commit comments