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 <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Oct 30, 2009 at 20:41 UTC
6361824589bc2d32989a9a33f985d09a368436a3
4 files changed
+32
-3
Documentation/git-var.txt
+6
@@ -44,6 +44,12 @@ GIT_EDITOR::
44
environment variable, then `core.editor` configuration, then
45
`$VISUAL`, then `$EDITOR`, and then finally 'vi'.
46
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
+
53
Diagnostics
54
-----------
55
You don't exist. Go away!::
cache.h
+1
@@ -751,6 +751,7 @@ extern const char *git_committer_info(int);
751
extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);
752
extern const char *fmt_name(const char *name, const char *email);
753
extern const char *git_editor(void);
754
+extern const char *git_pager(void);
755
756
struct checkout {
757
const char *base_dir;
pager.c
+15
-3
@@ -44,12 +44,14 @@ static void wait_for_pager_signal(int signo)
44
raise(signo);
45
}
46
47
-void setup_pager(void)
47
+const char *git_pager(void)
48
{
49
- const char *pager = getenv("GIT_PAGER");
49
+ const char *pager;
50
51
if (!isatty(1))
52
- return;
52
+ return NULL;
53
+
54
+ pager = getenv("GIT_PAGER");
55
if (!pager) {
56
if (!pager_program)
57
git_config(git_default_config, NULL);
@@ -60,6 +62,16 @@ void setup_pager(void)
62
if (!pager)
63
pager = "less";
64
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)
75
return;
76
77
spawned_pager = 1; /* means we are emitting to terminal */
var.c
+10
@@ -18,6 +18,15 @@ static const char *editor(int flag)
18
return pgm;
19
}
20
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
+
30
struct git_var {
31
const char *name;
32
const char *(*read)(int);
@@ -26,6 +35,7 @@ static struct git_var git_vars[] = {
35
{ "GIT_COMMITTER_IDENT", git_committer_info },
36
{ "GIT_AUTHOR_IDENT", git_author_info },
37
{ "GIT_EDITOR", editor },
38
+ { "GIT_PAGER", pager },
39
{ "", NULL },
40
};
41