]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Make 'git var GIT_PAGER' always print the configured pager
authorJonathan Nieder <jrnieder@gmail.com>
Sun, 14 Feb 2010 11:59:59 +0000 (05:59 -0600)
committerJunio C Hamano <gitster@pobox.com>
Mon, 15 Feb 2010 02:23:17 +0000 (18:23 -0800)
Scripted commands that want to use git’s configured pager know better
than ‘git var’ does whether stdout is going to be a tty at the
appropriate time.  Checking isatty(1) as git_pager() does now won’t
cut it, since the output of git var itself is almost never a terminal.
The symptom is that when used by humans, ‘git var GIT_PAGER’ behaves
as it should, but when used by scripts, it always returns ‘cat’!

So avoid tricks with isatty() and just always print the configured
pager.

This does not fix the callers to check isatty(1) themselves yet.
Nevertheless, this patch alone is enough to fix 'am --interactive'.

Thanks to Sebastian Celis for the report and Jeff King for the
analysis.

Reported-by: Sebastian Celis <sebastian@sebastiancelis.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-var.c
cache.h
pager.c

index e6ee7bc0b643d242d3f8962e29cdadcbe8cf4c54..70fdb4dec7e8b0c56ded90ee7f086cc9f16293a1 100644 (file)
@@ -20,7 +20,7 @@ static const char *editor(int flag)
 
 static const char *pager(int flag)
 {
-       const char *pgm = git_pager();
+       const char *pgm = git_pager(1);
 
        if (!pgm)
                pgm = "cat";
diff --git a/cache.h b/cache.h
index d478eff1f323f25a474cf019e0de2254c5ff0360..d454b7e686d6461162a85ef9c5f752eea401f51a 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -775,7 +775,7 @@ extern const char *git_committer_info(int);
 extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);
 extern const char *fmt_name(const char *name, const char *email);
 extern const char *git_editor(void);
-extern const char *git_pager(void);
+extern const char *git_pager(int stdout_is_tty);
 
 struct checkout {
        const char *base_dir;
diff --git a/pager.c b/pager.c
index 2c7e8ecb3c0860b00113e348008415ca28a7ff72..dac358f047550a07dd8d90b2e410feab3eebd534 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -48,11 +48,11 @@ static void wait_for_pager_signal(int signo)
        raise(signo);
 }
 
-const char *git_pager(void)
+const char *git_pager(int stdout_is_tty)
 {
        const char *pager;
 
-       if (!isatty(1))
+       if (!stdout_is_tty)
                return NULL;
 
        pager = getenv("GIT_PAGER");
@@ -73,7 +73,7 @@ const char *git_pager(void)
 
 void setup_pager(void)
 {
-       const char *pager = git_pager();
+       const char *pager = git_pager(isatty(1));
 
        if (!pager)
                return;