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

[PATCH 3/4] diff.c: move ws-error-highlight parsing helpers up

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 4, 2016, 22:54 UTC
Message-ID
<20161004225449.6759-4-gitster@pobox.com>
In-Reply-To
<20161004225449.6759-1-gitster@pobox.com>

These need to be usable from git_diff_ui_config() code to help parsing a configuration variable, so move them up.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 diff.c | 74 +++++++++++++++++++++++++++++++++---------------------------------
 1 file changed, 37 insertions(+), 37 deletions(-)
diff --git a/diff.c b/diff.c
index d346378600..bd625cf3f7 100644
--- a/diff.c
+++ b/diff.c
@@ -163,6 +163,43 @@ long parse_algorithm_value(const char *value)
 	return -1;
 }
 
+static int parse_one_token(const char **arg, const char *token)
+{
+	const char *rest;
+	if (skip_prefix(*arg, token, &rest) && (!*rest || *rest == ',')) {
+		*arg = rest;
+		return 1;
+	}
+	return 0;
+}
+
+static int parse_ws_error_highlight(const char *arg)
+{
+	const char *orig_arg = arg;
+	unsigned val = 0;
+
+	while (*arg) {
+		if (parse_one_token(&arg, "none"))
+			val = 0;
+		else if (parse_one_token(&arg, "default"))
+			val = WSEH_NEW;
+		else if (parse_one_token(&arg, "all"))
+			val = WSEH_NEW | WSEH_OLD | WSEH_CONTEXT;
+		else if (parse_one_token(&arg, "new"))
+			val |= WSEH_NEW;
+		else if (parse_one_token(&arg, "old"))
+			val |= WSEH_OLD;
+		else if (parse_one_token(&arg, "context"))
+			val |= WSEH_CONTEXT;
+		else {
+			return -1 - (int)(arg - orig_arg);
+		}
+		if (*arg)
+			arg++;
+	}
+	return val;
+}
+
 /*
  * These are to give UI layer defaults.
  * The core-level commands such as git-diff-files should
@@ -3656,43 +3693,6 @@ static void enable_patch_output(int *fmt) {
 	*fmt |= DIFF_FORMAT_PATCH;
 }
 
-static int parse_one_token(const char **arg, const char *token)
-{
-	const char *rest;
-	if (skip_prefix(*arg, token, &rest) && (!*rest || *rest == ',')) {
-		*arg = rest;
-		return 1;
-	}
-	return 0;
-}
-
-static int parse_ws_error_highlight(const char *arg)
-{
-	const char *orig_arg = arg;
-	unsigned val = 0;
-
-	while (*arg) {
-		if (parse_one_token(&arg, "none"))
-			val = 0;
-		else if (parse_one_token(&arg, "default"))
-			val = WSEH_NEW;
-		else if (parse_one_token(&arg, "all"))
-			val = WSEH_NEW | WSEH_OLD | WSEH_CONTEXT;
-		else if (parse_one_token(&arg, "new"))
-			val |= WSEH_NEW;
-		else if (parse_one_token(&arg, "old"))
-			val |= WSEH_OLD;
-		else if (parse_one_token(&arg, "context"))
-			val |= WSEH_CONTEXT;
-		else {
-			return -1 - (int)(arg - orig_arg);
-		}
-		if (*arg)
-			arg++;
-	}
-	return val;
-}
-
 static int parse_ws_error_highlight_opt(struct diff_options *opt, const char *arg)
 {
 	int val = parse_ws_error_highlight(arg);
-- 
2.10.1-510-g1ef781f2c1
Previous: Junio C HamanoNext: Jeff King
Message 10 of 11 in “color.diff.whitespace unused on removed lines”
  1. Sandro SantilliOct 4, 2016
  2. Jeff KingOct 4, 2016
  3. Sandro SantilliOct 4, 2016
  4. Jeff KingOct 4, 2016
  5. Junio C HamanoOct 4, 2016
  6. 0/4 diff.wsErrorHighlight configuration variableJunio C Hamano, Oct 4, 2016
  7. 1/4 t4015: split out the "setup" part of ws-error-highlight testJunio C Hamano, Oct 4, 2016
  8. 2/4 diff.c: refactor parse_ws_error_highlight()Junio C Hamano, Oct 4, 2016
  9. 4/4 diff: introduce diff.wsErrorHighlight optionJunio C Hamano, Oct 4, 2016
  10. 3/4 diff.c: move ws-error-highlight parsing helpers upJunio C Hamano, Oct 4, 2016
  11. Jeff KingOct 18, 2016

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.