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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Pascal Obry <pascal.obry@xxxxxxxxxx> 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,
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux