[PATCH 2/7] Make 'git var GIT_PAGER' always print the configured pager

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jonathan Nieder
Date: Friday, February 19, 2010 - 12:00 am

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 callers to check isatty(1) themselves yet.
Nevertheless, this patch alone is enough to fix 'am --interactive',
since as an interactive command its behavior before before dec543
(2009-10-30) was to always paginate.

There are unfortunately no tests for am --interactive or git svn log
in the test suite, so test suite runs would detect none of this.

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>
---
This commit message should be clearer, I hope.

 builtin-var.c |    2 +-
 cache.h       |    2 +-
 pager.c       |    6 +++---
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/builtin-var.c b/builtin-var.c
index e6ee7bc..70fdb4d 100644
--- a/builtin-var.c
+++ b/builtin-var.c
@@ -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 d478eff..d454b7e 100644
--- 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 2c7e8ec..dac358f 100644
--- 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;
-- 
1.7.0

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH v2 0/7] Re: 'git svn log' no longer uses the pager, Jonathan Nieder, (Thu Feb 18, 11:50 pm)
[PATCH 1/7] Fix 'git var' usage synopsis, Jonathan Nieder, (Thu Feb 18, 11:51 pm)
[PATCH 2/7] Make 'git var GIT_PAGER' always print the conf ..., Jonathan Nieder, (Fri Feb 19, 12:00 am)
[PATCH 3/7] git.1: Clarify the behavior of the --paginate ..., Jonathan Nieder, (Fri Feb 19, 12:06 am)
[PATCH 4/7] git svn: Fix launching of pager, Jonathan Nieder, (Fri Feb 19, 12:09 am)
[PATCH 5/7] am: Fix launching of pager, Jonathan Nieder, (Fri Feb 19, 12:12 am)
[PATCH 6/7] tests: Add tests for automatic use of pager, Jonathan Nieder, (Fri Feb 19, 12:18 am)
[PATCH/RFC 7/7] t7006-pager: if stdout is not a terminal, ..., Jonathan Nieder, (Fri Feb 19, 12:23 am)
[PATCH squash] Simplify test-terminal.perl, Jonathan Nieder, (Sat Feb 20, 2:48 am)
Re: [PATCH 6/7] tests: Add tests for automatic use of pager, Junio C Hamano, (Sat Feb 20, 10:33 am)
[PATCH v2 6/7] tests: Add tests for automatic use of pager, Jonathan Nieder, (Sat Feb 20, 7:03 pm)
[PATCH 8/7] tests: Fix race condition in t7006-pager, Jonathan Nieder, (Mon Feb 22, 1:46 am)
Re: [PATCH 8/7] tests: Fix race condition in t7006-pager, Jonathan Nieder, (Mon Feb 22, 2:12 am)