pager: stop loading git_default_config()

In git_pager(), we really only care about getting the value of core.pager. But to do so, we use the git_default_config() callback, which loads many other values. Ordinarily it isn't a big deal to load this config an extra time, as it simply overwrites the values from the previous run. But it's a bad idea here, for two reasons: 1. The pager setup may be called very early in the program, before we have found the git repository. As a result, we may fail to read the correct repo-level config file. This is a problem for core.pager, too, but we should at least try to minimize the pollution to other configured values. 2. Because we call setup_pager() from git.c, basically every builtin command _may_ end up reading this config and getting an implicit git_default_config() setup. Which doesn't sound like a terrible thing, except that we don't do it consistently; it triggers only when stdout is a tty. So if a command forgets to load the default config itself (but depends on it anyway), it may appear to work, and then mysteriously fail when the pager is not in use. We can improve this by loading _just_ the core.pager config from git_pager(). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 12, 2016 at 20:23 UTC 4babb839aaa18b14a5ec9e8994678d75bc120920
2 files changed +8 -4
config.c
-3
@@ -836,9 +836,6 @@ static int git_default_core_config(const char *var, const char *value)
836 return 0;
837 }
838
839 - if (!strcmp(var, "core.pager"))
840 - return git_config_string(&pager_program, var, value);
841 -
839 if (!strcmp(var, "core.editor"))
840 return git_config_string(&editor_program, var, value);
841
pager.c
+8 -1
@@ -35,6 +35,13 @@ static void wait_for_pager_signal(int signo)
35 raise(signo);
36 }
37
38 +static int core_pager_config(const char *var, const char *value, void *data)
39 +{
40 + if (!strcmp(var, "core.pager"))
41 + return git_config_string(&pager_program, var, value);
42 + return 0;
43 +}
44 +
45 const char *git_pager(int stdout_is_tty)
46 {
47 const char *pager;
@@ -45,7 +52,7 @@ const char *git_pager(int stdout_is_tty)
52 pager = getenv("GIT_PAGER");
53 if (!pager) {
54 if (!pager_program)
48 - git_config(git_default_config, NULL);
55 + git_config(core_pager_config, NULL);
56 pager = pager_program;
57 }
58 if (!pager)