aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorDerrick Stolee <stolee@gmail.com>2026-02-23 12:26:49 +0000
committerJunio C Hamano <gitster@pobox.com>2026-02-23 13:23:41 -0800
commit9c7fc23c24cc0cfeaf5fe32a96fbfe2709a3f93d (patch)
treeb0026dca5bc3011b90f417a6e902236443de492f /builtin
parent5fb7bdcca98e63fedee22f16a34ab5fadbee54e0 (diff)
downloadgit-9c7fc23c24cc0cfeaf5fe32a96fbfe2709a3f93d.tar.xz
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>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/config.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/builtin/config.c b/builtin/config.c
index 491a880e56..79c139c5b0 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -302,6 +302,18 @@ static int format_config_bool_or_int(struct strbuf *buf,
return 0;
}
+/* This mode is always gentle. */
+static int format_config_bool_or_str(struct strbuf *buf,
+ const char *value_)
+{
+ int v = git_parse_maybe_bool(value_);
+ if (v < 0)
+ strbuf_addstr(buf, value_);
+ else
+ strbuf_addstr(buf, v ? "true" : "false");
+ return 0;
+}
+
/*
* Format the configuration key-value pair (`key_`, `value_`) and
* 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,
res = format_config_bool(buf, key_, value_, gently);
else if (opts->type == TYPE_BOOL_OR_INT)
res = format_config_bool_or_int(buf, key_, value_, kvi, gently);
- else if (opts->type == TYPE_BOOL_OR_STR) {
- int v = git_parse_maybe_bool(value_);
- if (v < 0)
- strbuf_addstr(buf, value_);
- else
- strbuf_addstr(buf, v ? "true" : "false");
- } else if (opts->type == TYPE_PATH) {
+ else if (opts->type == TYPE_BOOL_OR_STR)
+ res = format_config_bool_or_str(buf, value_);
+ else if (opts->type == TYPE_PATH) {
char *v;
if (git_config_pathname(&v, key_, value_) < 0)
return -1;