2 #include "run-command.h"
5 * This is split up from the rest of git so that we can do
6 * something different on Windows.
9 static int spawned_pager
;
12 static void pager_preexec(void)
15 * Work around bug in "less" by not starting it until we
22 select(1, &in
, NULL
, &in
, NULL
);
24 setenv("LESS", "FRSX", 0);
28 static const char *pager_argv
[] = { "sh", "-c", NULL
, NULL
};
29 static struct child_process pager_process
;
31 static void wait_for_pager(void)
35 /* signal EOF to pager */
38 finish_command(&pager_process
);
41 void setup_pager(void)
43 const char *pager
= getenv("GIT_PAGER");
49 git_config(git_default_config
, NULL
);
50 pager
= pager_program
;
53 pager
= getenv("PAGER");
56 else if (!*pager
|| !strcmp(pager
, "cat"))
59 spawned_pager
= 1; /* means we are emitting to terminal */
62 pager_argv
[2] = pager
;
63 pager_process
.argv
= pager_argv
;
64 pager_process
.in
= -1;
66 pager_process
.preexec_cb
= pager_preexec
;
68 if (start_command(&pager_process
))
71 /* original process continues, but writes to the pipe */
72 dup2(pager_process
.in
, 1);
73 dup2(pager_process
.in
, 2);
74 close(pager_process
.in
);
76 /* this makes sure that the parent terminates after the pager */
77 atexit(wait_for_pager
);
80 int pager_in_use(void)
87 env
= getenv("GIT_PAGER_IN_USE");
88 return env
? git_config_bool("GIT_PAGER_IN_USE", env
) : 0;