t0061: run_command executes scripts without a #! line
[gitweb.git] / pager.c
diff --git a/pager.c b/pager.c
index f97a8bdc90bf88a686c0e7ed84b4be1df52d7fdd..c113d898a4ab184cf5ad5ea04dc66365fdf8a8f8 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -43,37 +43,6 @@ static int core_pager_config(const char *var, const char *value, void *data)
        return 0;
 }
 
-static void read_early_config(config_fn_t cb, void *data)
-{
-       git_config_with_options(cb, data, NULL, 1);
-
-       /*
-        * Note that this is a really dirty hack that does the wrong thing in
-        * many cases. The crux of the problem is that we cannot run
-        * setup_git_directory() early on in git's setup, so we have no idea if
-        * we are in a repository or not, and therefore are not sure whether
-        * and how to read repository-local config.
-        *
-        * So if we _aren't_ in a repository (or we are but we would reject its
-        * core.repositoryformatversion), we'll read whatever is in .git/config
-        * blindly. Similarly, if we _are_ in a repository, but not at the
-        * root, we'll fail to find .git/config (because it's really
-        * ../.git/config, etc). See t7006 for a complete set of failures.
-        *
-        * However, we have historically provided this hack because it does
-        * work some of the time (namely when you are at the top-level of a
-        * valid repository), and would rarely make things worse (i.e., you do
-        * not generally have a .git/config file sitting around).
-        */
-       if (!startup_info->have_repository) {
-               struct git_config_source repo_config;
-
-               memset(&repo_config, 0, sizeof(repo_config));
-               repo_config.file = ".git/config";
-               git_config_with_options(cb, data, &repo_config, 1);
-       }
-}
-
 const char *git_pager(int stdout_is_tty)
 {
        const char *pager;
@@ -97,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)
@@ -142,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);
 }
 
 /*