pager.c: replace git_config()
with git_config_get_value()
Use `git_config_get_value()` instead of `git_config()` to take advantage of the config-set API which provides a cleaner control flow. Signed-off-by: Tanay Abhra <tanayabh@gmail.com> Reviewed-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
5801d3b416
commit
586f414a89
44
pager.c
44
pager.c
@ -6,12 +6,6 @@
|
|||||||
#define DEFAULT_PAGER "less"
|
#define DEFAULT_PAGER "less"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct pager_config {
|
|
||||||
const char *cmd;
|
|
||||||
int want;
|
|
||||||
char *value;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is split up from the rest of git so that we can do
|
* This is split up from the rest of git so that we can do
|
||||||
* something different on Windows.
|
* something different on Windows.
|
||||||
@ -155,30 +149,22 @@ int decimal_width(int number)
|
|||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pager_command_config(const char *var, const char *value, void *data)
|
|
||||||
{
|
|
||||||
struct pager_config *c = data;
|
|
||||||
if (starts_with(var, "pager.") && !strcmp(var + 6, c->cmd)) {
|
|
||||||
int b = git_config_maybe_bool(var, value);
|
|
||||||
if (b >= 0)
|
|
||||||
c->want = b;
|
|
||||||
else {
|
|
||||||
c->want = 1;
|
|
||||||
c->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)
|
||||||
{
|
{
|
||||||
struct pager_config c;
|
int want = -1;
|
||||||
c.cmd = cmd;
|
struct strbuf key = STRBUF_INIT;
|
||||||
c.want = -1;
|
const char *value = NULL;
|
||||||
c.value = NULL;
|
strbuf_addf(&key, "pager.%s", cmd);
|
||||||
git_config(pager_command_config, &c);
|
if (!git_config_get_value(key.buf, &value)) {
|
||||||
if (c.value)
|
int b = git_config_maybe_bool(key.buf, value);
|
||||||
pager_program = c.value;
|
if (b >= 0)
|
||||||
return c.want;
|
want = b;
|
||||||
|
else {
|
||||||
|
want = 1;
|
||||||
|
pager_program = xstrdup(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
strbuf_release(&key);
|
||||||
|
return want;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user