Skip to content

Commit 6361824

Browse files
jrngitster
authored andcommitted
Teach git var about GIT_PAGER
Expose the command found by setup_pager() for scripts to use. Scripts can use this to avoid repeating the logic to look for a proper pager in each command. Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 44fcb49 commit 6361824

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

Documentation/git-var.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ GIT_EDITOR::
4444
environment variable, then `core.editor` configuration, then
4545
`$VISUAL`, then `$EDITOR`, and then finally 'vi'.
4646

47+
GIT_PAGER::
48+
Text viewer for use by git commands (e.g., 'less'). The value
49+
is meant to be interpreted by the shell. The order of preference
50+
is the `$GIT_PAGER` environment variable, then `core.pager`
51+
configuration, then `$PAGER`, and then finally 'less'.
52+
4753
Diagnostics
4854
-----------
4955
You don't exist. Go away!::

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ extern const char *git_committer_info(int);
751751
extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);
752752
extern const char *fmt_name(const char *name, const char *email);
753753
extern const char *git_editor(void);
754+
extern const char *git_pager(void);
754755

755756
struct checkout {
756757
const char *base_dir;

pager.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ static void wait_for_pager_signal(int signo)
4444
raise(signo);
4545
}
4646

47-
void setup_pager(void)
47+
const char *git_pager(void)
4848
{
49-
const char *pager = getenv("GIT_PAGER");
49+
const char *pager;
5050

5151
if (!isatty(1))
52-
return;
52+
return NULL;
53+
54+
pager = getenv("GIT_PAGER");
5355
if (!pager) {
5456
if (!pager_program)
5557
git_config(git_default_config, NULL);
@@ -60,6 +62,16 @@ void setup_pager(void)
6062
if (!pager)
6163
pager = "less";
6264
else if (!*pager || !strcmp(pager, "cat"))
65+
pager = NULL;
66+
67+
return pager;
68+
}
69+
70+
void setup_pager(void)
71+
{
72+
const char *pager = git_pager();
73+
74+
if (!pager)
6375
return;
6476

6577
spawned_pager = 1; /* means we are emitting to terminal */

var.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ static const char *editor(int flag)
1818
return pgm;
1919
}
2020

21+
static const char *pager(int flag)
22+
{
23+
const char *pgm = git_pager();
24+
25+
if (!pgm)
26+
pgm = "cat";
27+
return pgm;
28+
}
29+
2130
struct git_var {
2231
const char *name;
2332
const char *(*read)(int);
@@ -26,6 +35,7 @@ static struct git_var git_vars[] = {
2635
{ "GIT_COMMITTER_IDENT", git_committer_info },
2736
{ "GIT_AUTHOR_IDENT", git_author_info },
2837
{ "GIT_EDITOR", editor },
38+
{ "GIT_PAGER", pager },
2939
{ "", NULL },
3040
};
3141

0 commit comments

Comments
 (0)