diff: use skip_to_optional_arg_default()
Let's simplify diff option parsing using skip_to_optional_arg_default(). 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
cf81f94da45db8a030073e6ef3370f8498e9ce78
1 file changed
+4
-16
diff.c
+4
-16
@@ -4623,9 +4623,7 @@ int diff_opt_parse(struct diff_options *options,
4623
else if (!strcmp(arg, "--no-follow")) {
4624
options->flags.follow_renames = 0;
4625
options->flags.default_follow_renames = 0;
4626
- } else if (!strcmp(arg, "--color"))
4627
- options->use_color = 1;
4628
- else if (skip_prefix(arg, "--color=", &arg)) {
4626
+ } else if (skip_to_optional_arg_default(arg, "--color", &arg, "always")) {
4627
int value = git_config_colorbool(NULL, arg);
4628
if (value < 0)
4629
return error("option `color' expects \"always\", \"auto\", or \"never\"");
@@ -4645,14 +4643,9 @@ int diff_opt_parse(struct diff_options *options,
4643
if (cm < 0)
4644
die("bad --color-moved argument: %s", arg);
4645
options->color_moved = cm;
4648
- } else if (!strcmp(arg, "--color-words")) {
4649
- options->use_color = 1;
4650
- options->word_diff = DIFF_WORDS_COLOR;
4651
- }
4652
- else if (skip_prefix(arg, "--color-words=", &arg)) {
4646
+ } else if (skip_to_optional_arg_default(arg, "--color-words", &options->word_regex, NULL)) {
4647
options->use_color = 1;
4648
options->word_diff = DIFF_WORDS_COLOR;
4655
- options->word_regex = arg;
4649
}
4650
else if (!strcmp(arg, "--word-diff")) {
4651
if (options->word_diff == DIFF_WORDS_NONE)
@@ -4691,15 +4684,10 @@ int diff_opt_parse(struct diff_options *options,
4684
options->flags.textconv_set_via_cmdline = 1;
4685
} else if (!strcmp(arg, "--no-textconv"))
4686
options->flags.allow_textconv = 0;
4694
- else if (!strcmp(arg, "--ignore-submodules")) {
4695
- options->flags.override_submodule_config = 1;
4696
- handle_ignore_submodules_arg(options, "all");
4697
- } else if (skip_prefix(arg, "--ignore-submodules=", &arg)) {
4687
+ else if (skip_to_optional_arg_default(arg, "--ignore-submodules", &arg, "all")) {
4688
options->flags.override_submodule_config = 1;
4689
handle_ignore_submodules_arg(options, arg);
4700
- } else if (!strcmp(arg, "--submodule"))
4701
- options->submodule_format = DIFF_SUBMODULE_LOG;
4702
- else if (skip_prefix(arg, "--submodule=", &arg))
4690
+ } else if (skip_to_optional_arg_default(arg, "--submodule", &arg, "log"))
4691
return parse_submodule_opt(options, arg);
4692
else if (skip_prefix(arg, "--ws-error-highlight=", &arg))
4693
return parse_ws_error_highlight_opt(options, arg);