Commit 6a1e1bc0 authored by Jeff King's avatar Jeff King Committed by Junio C Hamano

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 586f414a (pager.c:
replace `git_config()` with `git_config_get_value()`,
2014-08-07), but with some minor style fixups and
modernizations.
Signed-off-by: default avatarJeff King <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent c0c08897
......@@ -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;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment