git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 4/7] diff: use skip_to_optional_arg_default()

From
Christian Couder <christian.couder@gmail.com>
Date
Dec 9, 2017, 20:40 UTC
Message-ID
<20171209204013.10997-4-chriscool@tuxfamily.org>
In-Reply-To
<20171209204013.10997-1-chriscool@tuxfamily.org>
From: Christian Couder <christian.couder@gmail.com>

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>
---
 diff.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)
diff --git a/diff.c b/diff.c
index 464a53adb5..28e1ab168f 100644
--- a/diff.c
+++ b/diff.c
@@ -4623,9 +4623,7 @@ int diff_opt_parse(struct diff_options *options,
 	else if (!strcmp(arg, "--no-follow")) {
 		options->flags.follow_renames = 0;
 		options->flags.default_follow_renames = 0;
-	} else if (!strcmp(arg, "--color"))
-		options->use_color = 1;
-	else if (skip_prefix(arg, "--color=", &arg)) {
+	} else if (skip_to_optional_arg_default(arg, "--color", &arg, "always")) {
 		int value = git_config_colorbool(NULL, arg);
 		if (value < 0)
 			return error("option `color' expects \"always\", \"auto\", or \"never\"");
@@ -4645,14 +4643,9 @@ int diff_opt_parse(struct diff_options *options,
 		if (cm < 0)
 			die("bad --color-moved argument: %s", arg);
 		options->color_moved = cm;
-	} else if (!strcmp(arg, "--color-words")) {
-		options->use_color = 1;
-		options->word_diff = DIFF_WORDS_COLOR;
-	}
-	else if (skip_prefix(arg, "--color-words=", &arg)) {
+	} else if (skip_to_optional_arg_default(arg, "--color-words", &options->word_regex, NULL)) {
 		options->use_color = 1;
 		options->word_diff = DIFF_WORDS_COLOR;
-		options->word_regex = arg;
 	}
 	else if (!strcmp(arg, "--word-diff")) {
 		if (options->word_diff == DIFF_WORDS_NONE)
@@ -4691,15 +4684,10 @@ int diff_opt_parse(struct diff_options *options,
 		options->flags.textconv_set_via_cmdline = 1;
 	} else if (!strcmp(arg, "--no-textconv"))
 		options->flags.allow_textconv = 0;
-	else if (!strcmp(arg, "--ignore-submodules")) {
-		options->flags.override_submodule_config = 1;
-		handle_ignore_submodules_arg(options, "all");
-	} else if (skip_prefix(arg, "--ignore-submodules=", &arg)) {
+	else if (skip_to_optional_arg_default(arg, "--ignore-submodules", &arg, "all")) {
 		options->flags.override_submodule_config = 1;
 		handle_ignore_submodules_arg(options, arg);
-	} else if (!strcmp(arg, "--submodule"))
-		options->submodule_format = DIFF_SUBMODULE_LOG;
-	else if (skip_prefix(arg, "--submodule=", &arg))
+	} else if (skip_to_optional_arg_default(arg, "--submodule", &arg, "log"))
 		return parse_submodule_opt(options, arg);
 	else if (skip_prefix(arg, "--ws-error-highlight=", &arg))
 		return parse_ws_error_highlight_opt(options, arg);
-- 
2.15.1.361.g8b07d831d0
Previous: Christian CouderNext: Christian Couder
Message 4 of 11 in “git-compat-util: introduce skip_to_optional_arg()”
  1. 1/7 git-compat-util: introduce skip_to_optional_arg()Christian Couder, Dec 9, 2017
  2. 2/7 index-pack: use skip_to_optional_arg()Christian Couder, Dec 9, 2017
  3. 3/7 diff: use skip_to_optional_arg()Christian Couder, Dec 9, 2017
  4. 4/7 diff: use skip_to_optional_arg_default()Christian Couder, Dec 9, 2017
  5. 5/7 diff: use skip_to_optional_arg_default() in parsing --relativeChristian Couder, Dec 9, 2017
  6. 6/7 diff: add tests for --relative without optional prefix valueChristian Couder, Dec 9, 2017
  7. 7/7 t4045: reindent to make helpers readableChristian Couder, Dec 9, 2017
  8. Jeff KingDec 10, 2017
  9. Jeff KingDec 10, 2017
  10. Christian CouderDec 11, 2017
  11. Junio C HamanoDec 11, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.