@matheusbsbs / matheus-bagliano / commits / 64778d24a9
Fork 0

Make 'git var GIT_PAGER' always print the configured pager

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>

Jonathan Nieder committed Feb 14, 2010 at 05:59 UTC 64778d24a93ad455e5883120aef350ede20061c4
3 files changed +5 -5
builtin-var.c
+1 -1
@@ -20,7 +20,7 @@ static const char *editor(int flag)
20
21 static const char *pager(int flag)
22 {
23 - const char *pgm = git_pager();
23 + const char *pgm = git_pager(1);
24
25 if (!pgm)
26 pgm = "cat";
cache.h
+1 -1
@@ -775,7 +775,7 @@ extern const char *git_committer_info(int);
775 extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);
776 extern const char *fmt_name(const char *name, const char *email);
777 extern const char *git_editor(void);
778 -extern const char *git_pager(void);
778 +extern const char *git_pager(int stdout_is_tty);
779
780 struct checkout {
781 const char *base_dir;
pager.c
+3 -3
@@ -48,11 +48,11 @@ static void wait_for_pager_signal(int signo)
48 raise(signo);
49 }
50
51 -const char *git_pager(void)
51 +const char *git_pager(int stdout_is_tty)
52 {
53 const char *pager;
54
55 - if (!isatty(1))
55 + if (!stdout_is_tty)
56 return NULL;
57
58 pager = getenv("GIT_PAGER");
@@ -73,7 +73,7 @@ const char *git_pager(void)
73
74 void setup_pager(void)
75 {
76 - const char *pager = git_pager();
76 + const char *pager = git_pager(isatty(1));
77
78 if (!pager)
79 return;