Merge branch 'cc/apply-am'
[gitweb.git] / pager.c
diff --git a/pager.c b/pager.c
index 4bc048148e043eabf1315bbcbae8ea4c6363b330..6470b8180df7e0de51a0d71ac47f8c078d226923 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -63,14 +63,38 @@ const char *git_pager(int stdout_is_tty)
        return pager;
 }
 
+static void setup_pager_env(struct argv_array *env)
+{
+       const char **argv;
+       int i;
+       char *pager_env = xstrdup(PAGER_ENV);
+       int n = split_cmdline(pager_env, &argv);
+
+       if (n < 0)
+               die("malformed build-time PAGER_ENV: %s",
+                       split_cmdline_strerror(n));
+
+       for (i = 0; i < n; i++) {
+               char *cp = strchr(argv[i], '=');
+
+               if (!cp)
+                       die("malformed build-time PAGER_ENV");
+
+               *cp = '\0';
+               if (!getenv(argv[i])) {
+                       *cp = '=';
+                       argv_array_push(env, argv[i]);
+               }
+       }
+       free(pager_env);
+       free(argv);
+}
+
 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");
+       setup_pager_env(&pager_process->env_array);
 }
 
 void setup_pager(void)