pager: config variable pager.color

enable/disable colored output when the pager is in use

Signed-off-by: Matthias Lederhofer <matled@gmx.net>
Signed-off-by: Junio C Hamano <junkio@cox.net>
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 465eb13..e669003 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -116,6 +116,10 @@
 	Tells `git-apply` how to handle whitespaces, in the same way
 	as the '--whitespace' option. See gitlink:git-apply[1].
 
+pager.color::
+	A boolean to enable/disable colored output when the pager is in
+	use (default is true).
+
 diff.color::
 	When true (or `always`), always use colors in patch.
 	When false (or `never`), never.  When set to `auto`, use
diff --git a/cache.h b/cache.h
index c575b8a..b8c21e0 100644
--- a/cache.h
+++ b/cache.h
@@ -386,6 +386,7 @@
 /* pager.c */
 extern void setup_pager(void);
 extern int pager_in_use;
+extern int pager_use_color;
 
 /* base85 */
 int decode_85(char *dst, char *line, int linelen);
diff --git a/config.c b/config.c
index 0ac6aeb..82b3562 100644
--- a/config.c
+++ b/config.c
@@ -309,6 +309,11 @@
 		return 0;
 	}
 
+	if (!strcmp(var, "pager.color")) {
+		pager_use_color = git_config_bool(var,value);
+		return 0;
+	}
+
 	/* Add other config variables here and to Documentation/config.txt. */
 	return 0;
 }
diff --git a/diff.c b/diff.c
index 6a71376..607c357 100644
--- a/diff.c
+++ b/diff.c
@@ -175,7 +175,7 @@
 			diff_use_color_default = 1; /* bool */
 		else if (!strcasecmp(value, "auto")) {
 			diff_use_color_default = 0;
-			if (isatty(1) || pager_in_use) {
+			if (isatty(1) || (pager_in_use && pager_use_color)) {
 				char *term = getenv("TERM");
 				if (term && strcmp(term, "dumb"))
 					diff_use_color_default = 1;
diff --git a/environment.c b/environment.c
index 42f39d6..87162b2 100644
--- a/environment.c
+++ b/environment.c
@@ -23,6 +23,7 @@
 const char *apply_default_whitespace = NULL;
 int zlib_compression_level = Z_DEFAULT_COMPRESSION;
 int pager_in_use;
+int pager_use_color = 1;
 
 static char *git_dir, *git_object_dir, *git_index_file, *git_refs_dir,
 	*git_graft_file;