Support GIT_PAGER_IN_USE environment variable
When deciding whether or not to turn on automatic color support, git_config_colorbool checks whether stdout is a tty. However, because we run a pager, if stdout is not a tty, we must check whether it is because we started the pager. This used to be done by checking the pager_in_use variable. This variable was set only when the git program being run started the pager; there was no way for an external program running git indicate that it had already started a pager. This patch allows a program to set GIT_PAGER_IN_USE to a true value to indicate that even though stdout is not a tty, it is because a pager is being used. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Dec 11, 2007 at 01:27 UTC
6e9af863ee76423ec8416ad16140ef5f810783bf
4 files changed
+16
-4
cache.h
+1
-1
@@ -608,7 +608,7 @@ extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char
608
/* pager.c */
609
extern void setup_pager(void);
610
extern char *pager_program;
611
-extern int pager_in_use;
611
+extern int pager_in_use(void);
612
extern int pager_use_color;
613
614
extern char *editor_program;
color.c
+1
-1
@@ -135,7 +135,7 @@ int git_config_colorbool(const char *var, const char *value, int stdout_is_tty)
135
auto_color:
136
if (stdout_is_tty < 0)
137
stdout_is_tty = isatty(1);
138
- if (stdout_is_tty || (pager_in_use && pager_use_color)) {
138
+ if (stdout_is_tty || (pager_in_use() && pager_use_color)) {
139
char *term = getenv("TERM");
140
if (term && strcmp(term, "dumb"))
141
return 1;
environment.c
-1
@@ -31,7 +31,6 @@ size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
31
size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
32
size_t delta_base_cache_limit = 16 * 1024 * 1024;
33
char *pager_program;
34
-int pager_in_use;
34
int pager_use_color = 1;
35
char *editor_program;
36
char *excludes_file;
pager.c
+14
-1
@@ -5,6 +5,8 @@
5
* something different on Windows, for example.
6
*/
7
8
+static int spawned_pager;
9
+
10
static void run_pager(const char *pager)
11
{
12
/*
@@ -41,7 +43,7 @@ void setup_pager(void)
43
else if (!*pager || !strcmp(pager, "cat"))
44
return;
45
44
- pager_in_use = 1; /* means we are emitting to terminal */
46
+ spawned_pager = 1; /* means we are emitting to terminal */
47
48
if (pipe(fd) < 0)
49
return;
@@ -70,3 +72,14 @@ void setup_pager(void)
72
die("unable to execute pager '%s'", pager);
73
exit(255);
74
}
75
+
76
+int pager_in_use(void)
77
+{
78
+ const char *env;
79
+
80
+ if (spawned_pager)
81
+ return 1;
82
+
83
+ env = getenv("GIT_PAGER_IN_USE");
84
+ return env ? git_config_bool("GIT_PAGER_IN_USE", env) : 0;
85
+}