summaryrefslogtreecommitdiff
path: root/pager.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2011-08-17 22:02:29 -0700
committerJunio C Hamano <gitster@pobox.com>2011-08-18 14:17:12 -0700
commit2e6c012e10fd866eb3259de3a929e0296daabbaf (patch)
treec53fe1c1082bfd909d26e2f59f98466658a20095 /pager.c
parent8d68a6d59378760c6bd5c7e0af75fe71c6ed78e7 (diff)
downloadgit-2e6c012e10fd866eb3259de3a929e0296daabbaf.tar.gz
setup_pager: set GIT_PAGER_IN_USE
We have always set a global "spawned_pager" variable when we start the pager. This lets us make the auto-color decision later in the program as as "we are outputting to a terminal, or to a pager which can handle colors". Commit 6e9af86 added support for the GIT_PAGER_IN_USE environment variable. An external program calling git (e.g., git-svn) could set this variable to indicate that it had already started the pager, and that the decision about auto-coloring should take that into account. However, 6e9af86 failed to do the reverse, which is to tell external programs when git itself has started the pager. Thus a git command implemented as an external script that has the pager turned on (e.g., "git -p stash show") would not realize it was going to a pager, and would suppress colors. This patch remedies that; we always set GIT_PAGER_IN_USE when we start the pager, and the value is respected by both this program and any spawned children. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pager.c')
-rw-r--r--pager.c8
1 files changed, 1 insertions, 7 deletions
diff --git a/pager.c b/pager.c
index dac358f047..975955ba82 100644
--- a/pager.c
+++ b/pager.c
@@ -11,8 +11,6 @@
* something different on Windows.
*/
-static int spawned_pager;
-
#ifndef WIN32
static void pager_preexec(void)
{
@@ -78,7 +76,7 @@ void setup_pager(void)
if (!pager)
return;
- spawned_pager = 1; /* means we are emitting to terminal */
+ setenv("GIT_PAGER_IN_USE", "true", 1);
/* spawn the pager */
pager_argv[0] = pager;
@@ -109,10 +107,6 @@ void setup_pager(void)
int pager_in_use(void)
{
const char *env;
-
- if (spawned_pager)
- return 1;
-
env = getenv("GIT_PAGER_IN_USE");
return env ? git_config_bool("GIT_PAGER_IN_USE", env) : 0;
}