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

Re: [PATCH] Use --no-color option on git log commands.

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 26, 2007, 22:30 UTC
Message-ID
<7vr6icej23.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<474B42EC.1000408@wanadoo.fr>
Pascal Obry <pascal.obry@wanadoo.fr> writes:
> When colors are activated on the repository the git log output
> will contain control characters to set/reset the colors.
The patch is good as belt-and-suspender, thanks.

But I suspect that we should make 'true' to mean 'auto' someday in git_config_colorbool(). Crazy people can set 'always' if they really wanted to, but most normal people would not want color unless the output goes to the terminal, I would think.

Something like this, perhaps...
---
 color.c |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/color.c b/color.c
index 09d82ee..060d3cf 100644
--- a/color.c
+++ b/color.c
@@ -118,21 +118,24 @@ bad:
 
 int git_config_colorbool(const char *var, const char *value)
 {
-	if (!value)
-		return 1;
-	if (!strcasecmp(value, "auto")) {
-		if (isatty(1) || (pager_in_use && pager_use_color)) {
-			char *term = getenv("TERM");
-			if (term && strcmp(term, "dumb"))
-				return 1;
-		}
-		return 0;
-	}
-	if (!strcasecmp(value, "never"))
- 		return 0;
-	if (!strcasecmp(value, "always"))
-		return 1;
-	return git_config_bool(var, value);
+	if (value) {
+		if (!strcasecmp(value, "never"))
+			return 0;
+		if (!strcasecmp(value, "always"))
+			return 1;
+		if (!strcasecmp(value, "auto"))
+			goto auto;
+ 	}
+	if (!git_config_bool(var, value))
+ 		return 0;
+auto:
+	/* any normal truth value defaults to 'auto' */
+	if (isatty(1) || (pager_in_use && pager_use_color)) {
+		char *term = getenv("TERM");
+		if (term && strcmp(term, "dumb"))
+			return 1;
+	}
+	return 0;
 }
 
 static int color_vprintf(const char *color, const char *fmt,
Previous: Pascal ObryNext: Pascal Obry
Message 2 of 10 in “Use --no-color option on git log commands.”
  1. Use --no-color option on git log commands.Pascal Obry, Nov 26, 2007
  2. Junio C HamanoNov 26, 2007
  3. Pascal ObryNov 27, 2007
  4. Junio C HamanoNov 28, 2007
  5. "color.diff = true" is not "always" anymore.Junio C Hamano, Nov 28, 2007
  6. Johannes SchindelinNov 28, 2007
  7. Jeff KingNov 28, 2007
  8. Junio C HamanoDec 1, 2007
  9. Jeff KingDec 1, 2007
  10. Junio C HamanoDec 1, 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.