From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Eric Wong <normalperson@yhbt.net>, git@vger.kernel.org
Subject: Re: v1.5.4 plans
Date: Tue, 11 Dec 2007 01:27:33 -0500 [thread overview]
Message-ID: <20071211062733.GA21768@coredump.intra.peff.net> (raw)
In-Reply-To: <20071211061743.GA21718@coredump.intra.peff.net>
Subject: [PATCH 1/2] 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>
---
A few notes:
We could also just put the color.pager logic in git-svn, or in Git.pm,
and have it impact the stdout_is_tty argument; but the whole point of
--get-colorbool is to consolidate that logic.
We convert pager_in_use to a function; we could also just set the
variable early on, but I think this lazy evaluation is more robust.
This might have uses besides --get-colorbool (e.g., wrapper scripts
which start their own pager can still have git sub-commands understand
whether to turn on color).
cache.h | 2 +-
color.c | 2 +-
environment.c | 1 -
| 15 ++++++++++++++-
4 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/cache.h b/cache.h
index 1bcb3df..27d90fe 100644
--- 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;
diff --git a/color.c b/color.c
index 7bd424a..7f66c29 100644
--- a/color.c
+++ b/color.c
@@ -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;
diff --git a/environment.c b/environment.c
index f3e3d41..18a1c4e 100644
--- a/environment.c
+++ b/environment.c
@@ -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;
--git a/pager.c b/pager.c
index fb7a1a6..0376953 100644
--- a/pager.c
+++ b/pager.c
@@ -5,6 +5,8 @@
* something different on Windows, for example.
*/
+static int spawned_pager;
+
static void run_pager(const char *pager)
{
/*
@@ -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;
@@ -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;
+}
--
1.5.3.7.2230.g796d07-dirty
next prev parent reply other threads:[~2007-12-11 6:27 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-22 6:11 What's in git/spearce.git (stable) Shawn O. Pearce
2007-11-01 5:39 ` What's in git.git (stable) Junio C Hamano
2007-11-04 3:52 ` Junio C Hamano
2007-11-08 8:06 ` Junio C Hamano
2007-11-08 11:38 ` Pierre Habouzit
2007-11-12 7:06 ` Junio C Hamano
2007-11-15 0:20 ` Junio C Hamano
2007-11-17 21:00 ` Junio C Hamano
2007-11-25 20:45 ` Junio C Hamano
2007-12-01 2:05 ` Junio C Hamano
2007-12-04 8:43 ` Junio C Hamano
2007-12-05 10:57 ` Junio C Hamano
2007-12-07 9:50 ` Junio C Hamano
2007-12-09 10:32 ` Junio C Hamano
2007-12-10 22:37 ` v1.5.4 plans Junio C Hamano
2007-12-10 23:49 ` Jeff King
2007-12-11 1:27 ` Junio C Hamano
2007-12-11 5:02 ` Junio C Hamano
2007-12-11 6:39 ` Jeff King
2007-12-11 6:47 ` Junio C Hamano
2007-12-11 6:54 ` Jeff King
2007-12-11 7:00 ` Junio C Hamano
2007-12-11 7:03 ` Jeff King
2007-12-11 6:17 ` Jeff King
2007-12-11 6:27 ` Jeff King [this message]
2007-12-11 6:28 ` [PATCH 2/2] git-svn: get color config from --get-colorbool Jeff King
2007-12-12 18:27 ` Eric Wong
2007-12-11 7:01 ` v1.5.4 plans Jeff King
2007-12-11 7:05 ` Andreas Ericsson
2007-12-11 12:53 ` Jeff King
2007-12-11 3:53 ` Nicolas Pitre
2007-12-11 12:57 ` Johannes Schindelin
2007-12-11 13:59 ` Nicolas Pitre
2007-12-11 15:24 ` Kristian Høgsberg
2007-12-11 19:13 ` Junio C Hamano
2007-12-12 18:40 ` Eric Wong
2007-12-12 19:50 ` Junio C Hamano
2007-12-12 22:21 ` David D. Kilzer
2007-12-31 3:56 ` David D. Kilzer
2007-12-31 20:07 ` [PATCH] Fix race condition in t9119-git-svn-info.sh David D. Kilzer
2007-12-31 22:29 ` Junio C Hamano
2007-12-31 23:33 ` [PATCH] Remove duplication " David D. Kilzer
2008-01-02 3:43 ` Eric Wong
2008-01-02 3:54 ` David D. Kilzer
2008-01-02 5:57 ` Junio C Hamano
2008-01-02 10:27 ` Junio C Hamano
2007-12-13 2:47 ` What's in git.git (stable frozen) Junio C Hamano
2007-12-13 3:09 ` [PATCH] git-commit: squelch needless message during an empty merge Junio C Hamano
2007-12-13 4:34 ` Jeff King
2007-12-13 7:46 ` Johannes Sixt
2007-12-17 8:40 ` What's in git.git (stable frozen) Junio C Hamano
2007-12-23 9:21 ` Junio C Hamano
2008-01-05 10:46 ` Junio C Hamano
2008-01-05 21:21 ` Dan McGee
2008-01-06 2:56 ` Junio C Hamano
2008-01-06 3:06 ` Junio C Hamano
2008-01-06 3:08 ` Dan McGee
2008-01-06 10:33 ` Junio C Hamano
[not found] ` <e5bfff550801050507x369976b7sd5e112451bc90331@mail.gmail.com>
2008-01-05 22:11 ` Junio C Hamano
2008-01-06 4:24 ` Jeff King
2008-01-06 4:29 ` Jeff King
2008-01-06 10:51 ` Junio C Hamano
2008-01-06 11:17 ` Jeff King
2008-01-06 12:32 ` Junio C Hamano
2008-01-06 20:59 ` Jeff King
2008-01-06 21:22 ` Junio C Hamano
2008-01-07 1:48 ` Jeff King
2008-01-07 8:27 ` Junio C Hamano
2008-01-07 21:58 ` Paul Mackerras
2008-01-07 22:05 ` Christian Stimming
2008-01-07 22:14 ` Junio C Hamano
2007-12-17 21:52 ` Steffen Prohaska
-- strict thread matches above, loose matches on Subject: below --
2007-12-02 22:04 v1.5.4 plans Junio C Hamano
2007-12-02 22:33 ` Jakub Narebski
2007-12-02 22:41 ` Junio C Hamano
2007-12-02 23:39 ` David Symonds
2007-12-03 2:32 ` Junio C Hamano
2007-12-03 18:06 ` Nicolas Pitre
2007-12-03 21:23 ` Junio C Hamano
2007-12-04 0:48 ` Russell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071211062733.GA21768@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=normalperson@yhbt.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).