Skip to content

Commit

Permalink
Make 'git var GIT_PAGER' always print the configured pager
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Jonathan Nieder <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
jrn authored and gitster committed Feb 15, 2010
1 parent 9fabb6d commit 64778d2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion builtin-var.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions pager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
Expand Down

0 comments on commit 64778d2

Please sign in to comment.