2 #include "run-command.h"
6 * This is split up from the rest of git so that we can do
7 * something different on Windows.
10 static int spawned_pager;
13 static void pager_preexec(void)
16 * Work around bug in "less" by not starting it until we
23 select(1, &in, NULL, &in, NULL);
25 setenv("LESS", "FRSX", 0);
29 static const char *pager_argv[] = { "sh", "-c", NULL, NULL };
30 static struct child_process pager_process;
32 static void wait_for_pager(void)
36 /* signal EOF to pager */
39 finish_command(&pager_process);
42 static void wait_for_pager_signal(int signo)
49 void setup_pager(void)
51 const char *pager = getenv("GIT_PAGER");
57 git_config(git_default_config, NULL);
58 pager = pager_program;
61 pager = getenv("PAGER");
64 else if (!*pager || !strcmp(pager, "cat"))
67 spawned_pager = 1; /* means we are emitting to terminal */
70 pager_argv[2] = pager;
71 pager_process.argv = pager_argv;
72 pager_process.in = -1;
74 pager_process.preexec_cb = pager_preexec;
76 if (start_command(&pager_process))
79 /* original process continues, but writes to the pipe */
80 dup2(pager_process.in, 1);
82 dup2(pager_process.in, 2);
83 close(pager_process.in);
85 /* this makes sure that the parent terminates after the pager */
86 sigchain_push_common(wait_for_pager_signal);
87 atexit(wait_for_pager);
90 int pager_in_use(void)
97 env = getenv("GIT_PAGER_IN_USE");
98 return env ? git_config_bool("GIT_PAGER_IN_USE", env) : 0;