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

Re: [PATCH] pager: config variable pager.color

From
Junio C Hamano <junkio@cox.net>
Date
Jul 31, 2006, 00:43 UTC
Message-ID
<7vd5bmbo46.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<E1G6zPH-00062L-Je@moooo.ath.cx>
Matthias Lederhofer <matled@gmx.net> writes:
Show 7 quoted lines
> Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
>> Why? The three users of cmd_log_walk() need to call setup_pager() 
>> explicitely, when cmd_log_walk() can do it for them?
>
> The explanation is below the commit message:
> "setup_pager has to be called before git_diff_ui_config because the
> latter uses pager_use_color initialized by setup_pager."

If that is the reason, perhaps we could restructure the setting and use of of diff_use_color_default like the attached, which would be cleaner.

-- >8 --
diff --git a/cache.h b/cache.h
index 8891073..913be6a 100644
--- a/cache.h
+++ b/cache.h
@@ -392,6 +392,7 @@ extern int receive_keep_pack(int fd[2], 
 /* 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/diff.c b/diff.c
index 6198a61..043ecb1 100644
--- a/diff.c
+++ b/diff.c
@@ -173,14 +173,8 @@ int git_diff_ui_config(const char *var, 
 	if (!strcmp(var, "diff.color")) {
 		if (!value)
 			diff_use_color_default = 1; /* bool */
-		else if (!strcasecmp(value, "auto")) {
-			diff_use_color_default = 0;
-			if (isatty(1) || pager_in_use) {
-				char *term = getenv("TERM");
-				if (term && strcmp(term, "dumb"))
-					diff_use_color_default = 1;
-			}
-		}
+		else if (!strcasecmp(value, "auto"))
+			diff_use_color_default = -1; /* decide in setup */
 		else if (!strcasecmp(value, "never"))
 			diff_use_color_default = 0;
 		else if (!strcasecmp(value, "always"))
@@ -1509,6 +1503,14 @@ void diff_setup(struct diff_options *opt
 
 	options->change = diff_change;
 	options->add_remove = diff_addremove;
+	if (diff_use_color_default < 0) {
+		diff_use_color_default = 0;
+		if (isatty(1) || (pager_in_use && pager_use_color)) {
+			char *term = getenv("TERM");
+			if (term && strcmp(term, "dumb"))
+				diff_use_color_default = 1;
+		}
+	}
 	options->color_diff = diff_use_color_default;
 	options->detect_rename = diff_detect_rename_default;
 }
diff --git a/environment.c b/environment.c
index 558801a..1ce3411 100644
--- a/environment.c
+++ b/environment.c
@@ -23,6 +23,7 @@ int shared_repository = PERM_UMASK;
 const char *apply_default_whitespace = NULL;
 int zlib_compression_level = Z_DEFAULT_COMPRESSION;
 int pager_in_use;
+int pager_use_color = 1;
 
 static int dyn_git_object_dir, dyn_git_index_file, dyn_git_graft_file;
 static char *git_dir, *git_object_dir, *git_index_file, *git_refs_dir,
diff --git a/pager.c b/pager.c
index 3f753f6..e86ea9e 100644
--- a/pager.c
+++ b/pager.c
@@ -14,6 +14,10 @@ static int git_pager_config(const char *
 			pager = strdup(value);
 		return 0;
 	}
+	if (!strcmp(var, "pager.color")) {
+		pager_use_color = git_config_bool(var, value);
+		return 0;
+	}
 	return 0;
 }
 
Previous: Johannes SchindelinNext: Juergen Ruehle
Message 5 of 8 in “pager: config variable pager.color”
  1. pager: config variable pager.colorMatthias Lederhofer, Jul 29, 2006
  2. Johannes SchindelinJul 29, 2006
  3. Matthias LederhoferJul 30, 2006
  4. Johannes SchindelinJul 30, 2006
  5. Junio C HamanoJul 31, 2006
  6. Juergen RuehleJul 31, 2006
  7. Junio C HamanoJul 31, 2006
  8. Matthias LederhoferJul 31, 2006

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.