X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=pager.c;h=dac358f047550a07dd8d90b2e410feab3eebd534;hb=452c6d506b1a6dcf24d4ceaa592afc39c1c1a60e;hp=86facec7b417b26a7dbd9b3c1338149fcecd5588;hpb=a07b10c8f930e88386d3b7424f25190af554275e;p=git.git diff --git a/pager.c b/pager.c index 86facec7b..dac358f04 100644 --- a/pager.c +++ b/pager.c @@ -2,6 +2,10 @@ #include "run-command.h" #include "sigchain.h" +#ifndef DEFAULT_PAGER +#define DEFAULT_PAGER "less" +#endif + /* * This is split up from the rest of git so that we can do * something different on Windows. @@ -24,7 +28,7 @@ static void pager_preexec(void) } #endif -static const char *pager_argv[] = { "sh", "-c", NULL, NULL }; +static const char *pager_argv[] = { NULL, NULL }; static struct child_process pager_process; static void wait_for_pager(void) @@ -44,12 +48,14 @@ static void wait_for_pager_signal(int signo) raise(signo); } -void setup_pager(void) +const char *git_pager(int stdout_is_tty) { - const char *pager = getenv("GIT_PAGER"); + const char *pager; - if (!isatty(1)) - return; + if (!stdout_is_tty) + return NULL; + + pager = getenv("GIT_PAGER"); if (!pager) { if (!pager_program) git_config(git_default_config, NULL); @@ -58,14 +64,25 @@ void setup_pager(void) if (!pager) pager = getenv("PAGER"); if (!pager) - pager = "less"; + pager = DEFAULT_PAGER; else if (!*pager || !strcmp(pager, "cat")) + pager = NULL; + + return pager; +} + +void setup_pager(void) +{ + const char *pager = git_pager(isatty(1)); + + if (!pager) return; spawned_pager = 1; /* means we are emitting to terminal */ /* spawn the pager */ - pager_argv[2] = pager; + pager_argv[0] = pager; + pager_process.use_shell = 1; pager_process.argv = pager_argv; pager_process.in = -1; if (!getenv("LESS")) {