summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 591aa25)
raw | patch | inline | side by side (parent: 591aa25)
author | Jeff King <peff@peff.net> | |
Tue, 11 Dec 2007 06:27:33 +0000 (01:27 -0500) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 11 Dec 2007 08:42:05 +0000 (00:42 -0800) |
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>
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>
cache.h | patch | blob | history | |
color.c | patch | blob | history | |
environment.c | patch | blob | history | |
pager.c | patch | blob | history |
index 1bcb3df7a20b7eb90c15807b92ae0e016266d5fd..27d90fe543b97eac91f61bf96f170c32d735e44d 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -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;
index 7bd424a8f6012859f40f2aa6210e7d4ce7686dc0..7f66c29fae57abceda30b1257c2a66626f3be0b2 100644 (file)
--- a/color.c
+++ b/color.c
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;
diff --git a/environment.c b/environment.c
index f3e3d4138d463520dbe6d709dfbe0803b619456d..18a1c4eec49bfddcb81d6669c83f8f97a218d7bf 100644 (file)
--- a/environment.c
+++ b/environment.c
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;
index fb7a1a625abf07b0d896a270286ee422a700c14c..0376953cb1b8a4095346e0d12ecef6e7db9c48c9 100644 (file)
--- a/pager.c
+++ b/pager.c
* something different on Windows, for example.
*/
+static int spawned_pager;
+
static void run_pager(const char *pager)
{
/*
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;
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;
+}