should_pack_ref(): new function, extracted from `files_pack_refs()`
[gitweb.git] / pager.c
diff --git a/pager.c b/pager.c
index 4811f3f0a19366773bb82ee7a12d31cce694a7e1..c113d898a4ab184cf5ad5ea04dc66365fdf8a8f8 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -53,7 +53,7 @@ const char *git_pager(int stdout_is_tty)
        pager = getenv("GIT_PAGER");
        if (!pager) {
                if (!pager_program)
-                       git_config(core_pager_config, NULL);
+                       read_early_config(core_pager_config, NULL);
                pager = pager_program;
        }
        if (!pager)
@@ -66,14 +66,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)
@@ -111,9 +135,7 @@ void setup_pager(void)
 
 int pager_in_use(void)
 {
-       const char *env;
-       env = getenv("GIT_PAGER_IN_USE");
-       return env ? git_config_bool("GIT_PAGER_IN_USE", env) : 0;
+       return git_env_bool("GIT_PAGER_IN_USE", 0);
 }
 
 /*
@@ -192,7 +214,7 @@ int check_pager_config(const char *cmd)
        data.want = -1;
        data.value = NULL;
 
-       git_config(pager_command_config, &data);
+       read_early_config(pager_command_config, &data);
 
        if (data.value)
                pager_program = data.value;