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

Re: [PATCH 2/3] git config --get-colorbool

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 6, 2007, 06:12 UTC
Message-ID
<7vve7cgxmw.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20071206053059.GF5499@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 22 quoted lines
> [Eric Wong cc'd because of git-svn relevance]
>
> On Wed, Dec 05, 2007 at 06:05:04PM -0800, Junio C Hamano wrote:
>
>> This adds an option to help scripts find out color settings from
>> the configuration file.
>> 
>>     git config --get-colorbool color.diff
>> 
>> inspects color.diff variable, and exits with status 0 (i.e. success) if
>> color is to be used.  It exits with status 1 otherwise.
>
> There is no way to differentiate between "do not use color" and "no
> value found". This makes it impossible to use this to implement the
> required "try color.diff, fallback to diff.color" behavior.
>
> We could simply make it
>
>   git config --get-colorbool diff
>
> which would check both (and when diff.color support is finally dropped,
> just remove it from there).

I thought about this a bit and thought that it would probably be a good workaround to teach "--get-colorbool that diff.color is a deprecated synonym to color.diff, like this.

-- >8 -- config --get-colorbool: diff.color is a deprecated synonym to color.diff

The applications can ask for color.diff but the configuration of old timer users can still instruct it to use color with diff.color this way.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-config.c |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/builtin-config.c b/builtin-config.c
index d10b03f..e4a12e3 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -210,11 +210,17 @@ static int get_color(int argc, const char **argv)
 
 static int stdout_is_tty;
 static int get_colorbool_found;
+static int get_diff_color_found;
 static int git_get_colorbool_config(const char *var, const char *value)
 {
-	if (!strcmp(var, get_color_slot))
+	if (!strcmp(var, get_color_slot)) {
 		get_colorbool_found =
 			git_config_colorbool(var, value, stdout_is_tty);
+	}
+	if (!strcmp(var, "diff.color")) {
+		get_diff_color_found =
+			git_config_colorbool(var, value, stdout_is_tty);
+	}
 	return 0;
 }
 
@@ -233,10 +239,18 @@ static int get_colorbool(int argc, const char **argv)
 		stdout_is_tty = isatty(1);
 	else
 		usage(git_config_set_usage);
-	get_colorbool_found = 0;
+	get_colorbool_found = -1;
+	get_diff_color_found = -1;
 	get_color_slot = argv[0];
 	git_config(git_get_colorbool_config);
 
+	if (get_colorbool_found < 0) {
+		if (!strcmp(get_color_slot, "color.diff"))
+			get_colorbool_found = get_diff_color_found;
+		if (get_colorbool_found < 0)
+			get_colorbool_found = 0;
+	}
+
 	if (argc == 1) {
 		return get_colorbool_found ? 0 : 1;
 	} else {
Previous: Jeff KingNext: Jeff King
Message 15 of 18 in “Color support for "git-add -i"”
  1. Color support for "git-add -i"Junio C Hamano, Dec 5, 2007
  2. Johannes SixtDec 5, 2007
  3. Wincent ColaiutaDec 5, 2007
  4. Junio C HamanoDec 5, 2007
  5. 1/3 Documentation: color.* = true means "auto"Junio C Hamano, Dec 6, 2007
  6. 2/3 git config --get-colorboolJunio C Hamano, Dec 6, 2007
  7. 3/3 Color support for "git-add -i"Junio C Hamano, Dec 6, 2007
  8. 0/3 Reroll colorized "git add -i"Junio C Hamano, Dec 6, 2007
  9. Jeff KingDec 6, 2007
  10. Wincent ColaiutaDec 6, 2007
  11. Junio C HamanoDec 6, 2007
  12. Wincent ColaiutaDec 7, 2007
  13. Jeff KingDec 6, 2007
  14. Jeff KingDec 6, 2007
  15. Junio C HamanoDec 6, 2007
  16. Jeff KingDec 6, 2007
  17. Eric WongDec 6, 2007
  18. Wincent ColaiutaDec 5, 2007

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.