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>
This commit is contained in:
parent
c0c08897c4
commit
6a1e1bc0a1
51
pager.c
51
pager.c
@ -159,23 +159,42 @@ int decimal_width(uintmax_t number)
|
|||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
data->want = b;
|
||||||
|
else {
|
||||||
|
data->want = 1;
|
||||||
|
data->value = xstrdup(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
|
/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
|
||||||
int check_pager_config(const char *cmd)
|
int check_pager_config(const char *cmd)
|
||||||
{
|
{
|
||||||
int want = -1;
|
struct pager_command_config_data data;
|
||||||
struct strbuf key = STRBUF_INIT;
|
|
||||||
const char *value = NULL;
|
data.cmd = cmd;
|
||||||
strbuf_addf(&key, "pager.%s", cmd);
|
data.want = -1;
|
||||||
if (git_config_key_is_valid(key.buf) &&
|
data.value = NULL;
|
||||||
!git_config_get_value(key.buf, &value)) {
|
|
||||||
int b = git_config_maybe_bool(key.buf, value);
|
git_config(pager_command_config, &data);
|
||||||
if (b >= 0)
|
|
||||||
want = b;
|
if (data.value)
|
||||||
else {
|
pager_program = data.value;
|
||||||
want = 1;
|
return data.want;
|
||||||
pager_program = xstrdup(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
strbuf_release(&key);
|
|
||||||
return want;
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user