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

[PATCH] parse_color: fix return value for numeric color values 0-8

From
Jeff King <peff@peff.net>
Date
Jan 20, 2015, 22:14 UTC
Message-ID
<20150120221447.GB18778@peff.net>
In-Reply-To
<CACBZZX5s1rZ3exktbisseJSjF8-0=8ByMpBpARy6h+=iP7wEyA@mail.gmail.com>
On Tue, Jan 20, 2015 at 10:49:32PM +0100, Ævar Arnfjörð Bjarmason wrote:
Show 13 quoted lines
> I've had this in my .gitconfig since 2010 which was broken by Jeff's
> v2.1.3-24-g695d95d:
> 
>     ;; Don't be so invasive about coloring ^M when I'm editing files
> that
>     ;; are supposed to have \r\n.
>     [color "diff"]
>        whitespace = 0
>
> [...]
> Maybe breaking this is OK (but I can't find what the replacement is),
> but the config or the the changelog doesn't mention breaking existing
> config settings.

Eek. Definitely an unintended regression. The fix is below. Thanks for reporting (and especially for catching during the -rc period!).

You should not need it, but for reference, using "0" is the same as "black" (both in old git and new).

-- >8 -- When commit 695d95d refactored the color parsing, it missed a "return 0" when parsing literal numbers 0-8 (which represent basic ANSI colors), leading us to report these colors as an error.

Signed-off-by: Jeff King <peff@peff.net>
---
 color.c          | 1 +
 t/t4026-color.sh | 4 ++++
 2 files changed, 5 insertions(+)
diff --git a/color.c b/color.c
index 809b359..9027352 100644
--- a/color.c
+++ b/color.c
@@ -112,6 +112,7 @@ static int parse_color(struct color *out, const char *name, int len)
 		} else if (val < 8) {
 			out->type = COLOR_ANSI;
 			out->value = val;
+			return 0;
 		} else if (val < 256) {
 			out->type = COLOR_256;
 			out->value = val;
diff --git a/t/t4026-color.sh b/t/t4026-color.sh
index 267c43b..4d20fea 100755
--- a/t/t4026-color.sh
+++ b/t/t4026-color.sh
@@ -60,6 +60,10 @@ test_expect_success 'absurdly long color specification' '
 	  "[1;2;4;5;7;22;24;25;27;38;2;255;255;255;48;2;255;255;255m"
 '
 
+test_expect_success '0-7 are aliases for basic ANSI color names' '
+	color "0 7" "[30;47m"
+'
+
 test_expect_success '256 colors' '
 	color "254 bold 255" "[1;38;5;254;48;5;255m"
 '
-- 
2.2.1.425.g441bb3c
Previous: Ævar Arnfjörð BjarmasonNext: Junio C Hamano
Message 4 of 7 in “[ANNOUNCE] Git v2.3.0-rc0”
  1. Junio C HamanoJan 12, 2015
  2. Christian NeukirchenJan 14, 2015
  3. Ævar Arnfjörð BjarmasonJan 20, 2015
  4. parse_color: fix return value for numeric color values 0-8Jeff King, Jan 20, 2015
  5. Junio C HamanoJan 20, 2015
  6. Jeff KingJan 21, 2015
  7. Junio C HamanoJan 21, 2015

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.