From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Steffen Daode Nurpmeso" <sdaoden@googlemail.com>,
"Ingo Brückl" <ib@wupperonline.de>
Subject: [PATCH 04/10] setup_pager: set GIT_PAGER_IN_USE
Date: Wed, 17 Aug 2011 22:02:29 -0700 [thread overview]
Message-ID: <20110818050227.GD2889@sigill.intra.peff.net> (raw)
In-Reply-To: <20110818045821.GA17377@sigill.intra.peff.net>
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>
---
| 8 +-------
| 11 +++++++++++
2 files changed, 12 insertions(+), 7 deletions(-)
--git a/pager.c b/pager.c
index dac358f..975955b 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;
}
--git a/t/t7006-pager.sh b/t/t7006-pager.sh
index 2ac729f..4884e1b 100755
--- a/t/t7006-pager.sh
+++ b/t/t7006-pager.sh
@@ -181,6 +181,17 @@ test_expect_success 'color when writing to a file intended for a pager' '
colorful colorful.log
'
+test_expect_success TTY 'colors are sent to pager for external commands' '
+ test_config alias.externallog "!git log" &&
+ test_config color.ui auto &&
+ (
+ TERM=vt100 &&
+ export TERM &&
+ test_terminal git -p externallog
+ ) &&
+ colorful paginated.out
+'
+
# Use this helper to make it easy for the caller of your
# terminal-using function to specify whether it should fail.
# If you write
--
1.7.6.10.g62f04
next prev parent reply other threads:[~2011-08-18 5:02 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-18 4:58 [PATCH 0/10] color and pager improvements Jeff King
2011-08-18 5:00 ` [PATCH 01/10] t7006: modernize calls to unset Jeff King
2011-08-18 21:05 ` Junio C Hamano
2011-08-18 5:01 ` [PATCH 02/10] test-lib: add helper functions for config Jeff King
2011-08-18 21:10 ` Junio C Hamano
2011-08-18 5:02 ` [PATCH 03/10] t7006: use test_config helpers Jeff King
2011-08-18 5:02 ` Jeff King [this message]
2011-08-18 5:03 ` [PATCH 05/10] diff: refactor COLOR_DIFF from a flag into an int Jeff King
2011-08-18 5:03 ` [PATCH 06/10] git_config_colorbool: refactor stdout_is_tty handling Jeff King
2011-08-18 5:04 ` [PATCH 07/10] color: delay auto-color decision until point of use Jeff King
2011-08-18 21:59 ` Junio C Hamano
2011-08-18 22:28 ` Jeff King
2011-08-18 5:04 ` [PATCH 08/10] config: refactor get_colorbool function Jeff King
2011-08-18 5:05 ` [PATCH 09/10] diff: don't load color config in plumbing Jeff King
2011-08-18 5:05 ` [PATCH 10/10] want_color: automatically fallback to color.ui Jeff King
2011-09-04 2:36 ` Martin von Zweigbergk
2011-09-04 12:53 ` Jeff King
2011-09-05 11:31 ` Steffen Daode Nurpmeso
2011-08-18 21:58 ` [PATCH 0/10] color and pager improvements Jeff King
2011-08-18 21:59 ` [PATCH 11/10] support pager.* for aliases Jeff King
2011-08-18 22:54 ` Junio C Hamano
2011-08-19 3:37 ` Jeff King
2011-08-19 4:18 ` Junio C Hamano
2011-08-19 4:40 ` Jeff King
2011-08-19 5:23 ` Junio C Hamano
2011-08-19 5:43 ` Junio C Hamano
2011-08-19 8:30 ` Jeff King
2011-08-18 22:01 ` [PATCH 12/10] support pager.* for external commands Jeff King
2011-08-18 22:56 ` Junio C Hamano
2012-02-12 0:46 ` Ævar Arnfjörð Bjarmason
2012-02-14 19:13 ` Jeff King
2011-08-18 22:33 ` [PATCH 0/10] color and pager improvements Ingo Brückl
2011-08-18 22:46 ` Jeff King
2011-08-19 6:34 ` Ingo Brückl
2011-08-25 20:25 ` Jeff King
2011-08-18 21:59 ` Steffen Daode Nurpmeso
2011-08-18 22:02 ` Junio C Hamano
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110818050227.GD2889@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=ib@wupperonline.de \
--cc=sdaoden@googlemail.com \
/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.
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 NNTP newsgroup(s).