Skip to content

Commit 586f414

Browse files
tanayabhgitster
authored andcommitted
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 <[email protected]> Reviewed-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5801d3b commit 586f414

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

pager.c

+13-27
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
#define DEFAULT_PAGER "less"
77
#endif
88

9-
struct pager_config {
10-
const char *cmd;
11-
int want;
12-
char *value;
13-
};
14-
159
/*
1610
* This is split up from the rest of git so that we can do
1711
* something different on Windows.
@@ -155,30 +149,22 @@ int decimal_width(int number)
155149
return width;
156150
}
157151

158-
static int pager_command_config(const char *var, const char *value, void *data)
152+
/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
153+
int check_pager_config(const char *cmd)
159154
{
160-
struct pager_config *c = data;
161-
if (starts_with(var, "pager.") && !strcmp(var + 6, c->cmd)) {
162-
int b = git_config_maybe_bool(var, value);
155+
int want = -1;
156+
struct strbuf key = STRBUF_INIT;
157+
const char *value = NULL;
158+
strbuf_addf(&key, "pager.%s", cmd);
159+
if (!git_config_get_value(key.buf, &value)) {
160+
int b = git_config_maybe_bool(key.buf, value);
163161
if (b >= 0)
164-
c->want = b;
162+
want = b;
165163
else {
166-
c->want = 1;
167-
c->value = xstrdup(value);
164+
want = 1;
165+
pager_program = xstrdup(value);
168166
}
169167
}
170-
return 0;
171-
}
172-
173-
/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
174-
int check_pager_config(const char *cmd)
175-
{
176-
struct pager_config c;
177-
c.cmd = cmd;
178-
c.want = -1;
179-
c.value = NULL;
180-
git_config(pager_command_config, &c);
181-
if (c.value)
182-
pager_program = c.value;
183-
return c.want;
168+
strbuf_release(&key);
169+
return want;
184170
}

0 commit comments

Comments
 (0)