Merge branch 'ss/msvc' into maint
[gitweb.git] / pager.c
diff --git a/pager.c b/pager.c
index 5dbcc5ace395b0fb5d2fec09e8d53c7f1bce3fb2..4bc048148e043eabf1315bbcbae8ea4c6363b330 100644 (file)
--- a/pager.c
+++ b/pager.c
 
 static struct child_process pager_process = CHILD_PROCESS_INIT;
 
-static void wait_for_pager(void)
+static void wait_for_pager(int in_signal)
 {
-       fflush(stdout);
-       fflush(stderr);
+       if (!in_signal) {
+               fflush(stdout);
+               fflush(stderr);
+       }
        /* signal EOF to pager */
        close(1);
        close(2);
-       finish_command(&pager_process);
+       if (in_signal)
+               finish_command_in_signal(&pager_process);
+       else
+               finish_command(&pager_process);
+}
+
+static void wait_for_pager_atexit(void)
+{
+       wait_for_pager(0);
 }
 
 static void wait_for_pager_signal(int signo)
 {
-       wait_for_pager();
+       wait_for_pager(1);
        sigchain_pop(signo);
        raise(signo);
 }
@@ -53,6 +63,16 @@ const char *git_pager(int stdout_is_tty)
        return pager;
 }
 
+void prepare_pager_args(struct child_process *pager_process, const char *pager)
+{
+       argv_array_push(&pager_process->args, pager);
+       pager_process->use_shell = 1;
+       if (!getenv("LESS"))
+               argv_array_push(&pager_process->env_array, "LESS=FRX");
+       if (!getenv("LV"))
+               argv_array_push(&pager_process->env_array, "LV=-c");
+}
+
 void setup_pager(void)
 {
        const char *pager = git_pager(isatty(1));
@@ -69,13 +89,8 @@ void setup_pager(void)
        setenv("GIT_PAGER_IN_USE", "true", 1);
 
        /* spawn the pager */
-       argv_array_push(&pager_process.args, pager);
-       pager_process.use_shell = 1;
+       prepare_pager_args(&pager_process, pager);
        pager_process.in = -1;
-       if (!getenv("LESS"))
-               argv_array_push(&pager_process.env_array, "LESS=FRX");
-       if (!getenv("LV"))
-               argv_array_push(&pager_process.env_array, "LV=-c");
        argv_array_push(&pager_process.env_array, "GIT_PAGER_IN_USE");
        if (start_command(&pager_process))
                return;
@@ -88,7 +103,7 @@ void setup_pager(void)
 
        /* this makes sure that the parent terminates after the pager */
        sigchain_push_common(wait_for_pager_signal);
-       atexit(wait_for_pager);
+       atexit(wait_for_pager_atexit);
 }
 
 int pager_in_use(void)
@@ -148,7 +163,8 @@ int check_pager_config(const char *cmd)
        struct strbuf key = STRBUF_INIT;
        const char *value = NULL;
        strbuf_addf(&key, "pager.%s", cmd);
-       if (!git_config_get_value(key.buf, &value)) {
+       if (git_config_key_is_valid(key.buf) &&
+           !git_config_get_value(key.buf, &value)) {
                int b = git_config_maybe_bool(key.buf, value);
                if (b >= 0)
                        want = b;