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>

Tanay Abhra committed Aug 7, 2014 at 09:21 UTC 586f414a89d13fc0ea38121528c863f3726bc18b
1 file changed +13 -27
pager.c
+13 -27
@@ -6,12 +6,6 @@
6 #define DEFAULT_PAGER "less"
7 #endif
8
9 -struct pager_config {
10 - const char *cmd;
11 - int want;
12 - char *value;
13 -};
14 -
9 /*
10 * This is split up from the rest of git so that we can do
11 * something different on Windows.
@@ -155,30 +149,22 @@ int decimal_width(int number)
149 return width;
150 }
151
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)
154 {
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);
161 if (b >= 0)
164 - c->want = b;
162 + want = b;
163 else {
166 - c->want = 1;
167 - c->value = xstrdup(value);
164 + want = 1;
165 + pager_program = xstrdup(value);
166 }
167 }
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;
170 }