aboutsummaryrefslogtreecommitdiffstats
path: root/pager.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-09-12 20:23:52 -0700
committerJunio C Hamano <gitster@pobox.com>2016-09-13 15:45:45 -0700
commit6a1e1bc0a155faa5a095ce00bd06678a1dfa0eea (patch)
treea39d5971e72ad8bbf261b572223f25ebdb4f5425 /pager.c
parentc0c08897c47eb46179c8d2408dc1a91713307842 (diff)
downloadgit-6a1e1bc0a155faa5a095ce00bd06678a1dfa0eea.tar.gz
pager: use callbacks instead of configset
While the cached configset interface is more pleasant to use, it is not appropriate for "early" config like pager setup, which must sometimes do tricky things like reading from ".git/config" even when we have not set up the repository. As a preparatory step to handling these cases better, let's switch back to using the callback interface, which gives us more control. Note that this is essentially a revert of 586f414 (pager.c: replace `git_config()` with `git_config_get_value()`, 2014-08-07), but with some minor style fixups and modernizations. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pager.c')
-rw-r--r--pager.c47
1 files changed, 33 insertions, 14 deletions
diff --git a/pager.c b/pager.c
index 00c8baace0..4811f3f0a1 100644
--- a/pager.c
+++ b/pager.c
@@ -159,23 +159,42 @@ int decimal_width(uintmax_t number)
return width;
}
-/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
-int check_pager_config(const char *cmd)
+struct pager_command_config_data {
+ const char *cmd;
+ int want;
+ char *value;
+};
+
+static int pager_command_config(const char *var, const char *value, void *vdata)
{
- int want = -1;
- struct strbuf key = STRBUF_INIT;
- const char *value = NULL;
- strbuf_addf(&key, "pager.%s", cmd);
- if (git_config_key_is_valid(key.buf) &&
- !git_config_get_value(key.buf, &value)) {
- int b = git_config_maybe_bool(key.buf, value);
+ struct pager_command_config_data *data = vdata;
+ const char *cmd;
+
+ if (skip_prefix(var, "pager.", &cmd) && !strcmp(cmd, data->cmd)) {
+ int b = git_config_maybe_bool(var, value);
if (b >= 0)
- want = b;
+ data->want = b;
else {
- want = 1;
- pager_program = xstrdup(value);
+ data->want = 1;
+ data->value = xstrdup(value);
}
}
- strbuf_release(&key);
- return want;
+
+ return 0;
+}
+
+/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
+int check_pager_config(const char *cmd)
+{
+ struct pager_command_config_data data;
+
+ data.cmd = cmd;
+ data.want = -1;
+ data.value = NULL;
+
+ git_config(pager_command_config, &data);
+
+ if (data.value)
+ pager_program = data.value;
+ return data.want;
}