Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Support GIT_PAGER_IN_USE environment variable
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
peff authored and gitster committed Dec 11, 2007
1 parent 591aa25 commit 6e9af86
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cache.h
Expand Up @@ -608,7 +608,7 @@ extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char
/* pager.c */
extern void setup_pager(void);
extern char *pager_program;
extern int pager_in_use;
extern int pager_in_use(void);
extern int pager_use_color;

extern char *editor_program;
Expand Down
2 changes: 1 addition & 1 deletion color.c
Expand Up @@ -135,7 +135,7 @@ int git_config_colorbool(const char *var, const char *value, int stdout_is_tty)
auto_color:
if (stdout_is_tty < 0)
stdout_is_tty = isatty(1);
if (stdout_is_tty || (pager_in_use && pager_use_color)) {
if (stdout_is_tty || (pager_in_use() && pager_use_color)) {
char *term = getenv("TERM");
if (term && strcmp(term, "dumb"))
return 1;
Expand Down
1 change: 0 additions & 1 deletion environment.c
Expand Up @@ -31,7 +31,6 @@ size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
size_t delta_base_cache_limit = 16 * 1024 * 1024;
char *pager_program;
int pager_in_use;
int pager_use_color = 1;
char *editor_program;
char *excludes_file;
Expand Down
15 changes: 14 additions & 1 deletion pager.c
Expand Up @@ -5,6 +5,8 @@
* something different on Windows, for example.
*/

static int spawned_pager;

static void run_pager(const char *pager)
{
/*
Expand Down Expand Up @@ -41,7 +43,7 @@ void setup_pager(void)
else if (!*pager || !strcmp(pager, "cat"))
return;

pager_in_use = 1; /* means we are emitting to terminal */
spawned_pager = 1; /* means we are emitting to terminal */

if (pipe(fd) < 0)
return;
Expand Down Expand Up @@ -70,3 +72,14 @@ void setup_pager(void)
die("unable to execute pager '%s'", pager);
exit(255);
}

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;
}

0 comments on commit 6e9af86

Please sign in to comment.