aboutsummaryrefslogtreecommitdiff
path: root/builtin/config.c
diff options
context:
space:
mode:
authorDerrick Stolee <stolee@gmail.com>2026-02-23 12:26:46 +0000
committerJunio C Hamano <gitster@pobox.com>2026-02-23 13:23:40 -0800
commitd744923fefb294c835d18883bac62f85ff55fc9f (patch)
tree22150fbf4cee2b23808396af08e2e66a69eb2c24 /builtin/config.c
parent1ef1f9d53a1607dd8fd38e0dbae67e405c3b3563 (diff)
downloadgit-d744923fefb294c835d18883bac62f85ff55fc9f.tar.xz
config: format int64s gently
Move the logic for formatting int64 config values into a helper method and use gentle parsing when needed. Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/config.c')
-rw-r--r--builtin/config.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/builtin/config.c b/builtin/config.c
index 4c4c791883..448b148563 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -237,6 +237,25 @@ struct strbuf_list {
int alloc;
};
+static int format_config_int64(struct strbuf *buf,
+ const char *key_,
+ const char *value_,
+ const struct key_value_info *kvi,
+ int gently)
+{
+ int64_t v = 0;
+ if (gently) {
+ if (!git_parse_int64(value_, &v))
+ return -1;
+ } else {
+ /* may die() */
+ v = git_config_int64(key_, value_ ? value_ : "", kvi);
+ }
+
+ strbuf_addf(buf, "%"PRId64, v);
+ return 0;
+}
+
/*
* Format the configuration key-value pair (`key_`, `value_`) and
* append it into strbuf `buf`. Returns a negative value on failure,
@@ -249,8 +268,9 @@ struct strbuf_list {
static int format_config(const struct config_display_options *opts,
struct strbuf *buf, const char *key_,
const char *value_, const struct key_value_info *kvi,
- int gently UNUSED)
+ int gently)
{
+ int res = 0;
if (opts->show_scope)
show_config_scope(opts, kvi, buf);
if (opts->show_origin)
@@ -262,8 +282,7 @@ static int format_config(const struct config_display_options *opts,
strbuf_addch(buf, opts->key_delim);
if (opts->type == TYPE_INT)
- strbuf_addf(buf, "%"PRId64,
- git_config_int64(key_, value_ ? value_ : "", kvi));
+ res = format_config_int64(buf, key_, value_, kvi, gently);
else if (opts->type == TYPE_BOOL)
strbuf_addstr(buf, git_config_bool(key_, value_) ?
"true" : "false");
@@ -309,7 +328,7 @@ static int format_config(const struct config_display_options *opts,
}
}
strbuf_addch(buf, opts->term);
- return 0;
+ return res;
}
static int show_all_config(const char *key_, const char *value_,