]> git.ipfire.org Git - thirdparty/git.git/blame - pager.c
add logref support to git-symbolic-ref
[thirdparty/git.git] / pager.c
CommitLineData
f67b45f8
LT
1#include "cache.h"
2
3/*
4 * This is split up from the rest of git so that we might do
5 * something different on Windows, for example.
6 */
7
402461aa 8static void run_pager(const char *pager)
f67b45f8 9{
402461aa 10 execlp(pager, pager, NULL);
34fd1c9a 11 execl("/bin/sh", "sh", "-c", pager, NULL);
f67b45f8
LT
12}
13
14void setup_pager(void)
15{
16 pid_t pid;
17 int fd[2];
c27d205a 18 const char *pager = getenv("GIT_PAGER");
f67b45f8
LT
19
20 if (!isatty(1))
21 return;
c27d205a
ML
22 if (!pager)
23 pager = getenv("PAGER");
402461aa
JS
24 if (!pager)
25 pager = "less";
caef71a5 26 else if (!*pager || !strcmp(pager, "cat"))
402461aa
JS
27 return;
28
85fb65ed
JH
29 pager_in_use = 1; /* means we are emitting to terminal */
30
f67b45f8
LT
31 if (pipe(fd) < 0)
32 return;
33 pid = fork();
34 if (pid < 0) {
35 close(fd[0]);
36 close(fd[1]);
37 return;
38 }
39
40 /* return in the child */
41 if (!pid) {
42 dup2(fd[1], 1);
43 close(fd[0]);
44 close(fd[1]);
45 return;
46 }
47
48 /* The original process turns into the PAGER */
49 dup2(fd[0], 0);
50 close(fd[0]);
51 close(fd[1]);
52
0abc0260 53 setenv("LESS", "FRSX", 0);
402461aa 54 run_pager(pager);
34fd1c9a 55 die("unable to execute pager '%s'", pager);
f67b45f8
LT
56 exit(255);
57}