config: format bools or strings in helper

Move the logic for formatting bool-or-string config values into a helper. This parsing has always been gentle, so this is not unlocking new behavior. This extraction is only to match the formatting of the other cases that do need a behavior change. Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Feb 23, 2026 at 12:26 UTC 9c7fc23c24cc0cfeaf5fe32a96fbfe2709a3f93d
1 file changed +15 -7
builtin/config.c
+15 -7
@@ -302,6 +302,18 @@ static int format_config_bool_or_int(struct strbuf *buf,
302 return 0;
303 }
304
305 +/* This mode is always gentle. */
306 +static int format_config_bool_or_str(struct strbuf *buf,
307 + const char *value_)
308 +{
309 + int v = git_parse_maybe_bool(value_);
310 + if (v < 0)
311 + strbuf_addstr(buf, value_);
312 + else
313 + strbuf_addstr(buf, v ? "true" : "false");
314 + return 0;
315 +}
316 +
317 /*
318 * Format the configuration key-value pair (`key_`, `value_`) and
319 * append it into strbuf `buf`. Returns a negative value on failure,
@@ -333,13 +345,9 @@ static int format_config(const struct config_display_options *opts,
345 res = format_config_bool(buf, key_, value_, gently);
346 else if (opts->type == TYPE_BOOL_OR_INT)
347 res = format_config_bool_or_int(buf, key_, value_, kvi, gently);
336 - else if (opts->type == TYPE_BOOL_OR_STR) {
337 - int v = git_parse_maybe_bool(value_);
338 - if (v < 0)
339 - strbuf_addstr(buf, value_);
340 - else
341 - strbuf_addstr(buf, v ? "true" : "false");
342 - } else if (opts->type == TYPE_PATH) {
348 + else if (opts->type == TYPE_BOOL_OR_STR)
349 + res = format_config_bool_or_str(buf, value_);
350 + else if (opts->type == TYPE_PATH) {
351 char *v;
352 if (git_config_pathname(&v, key_, value_) < 0)
353 return -1;