From: Derrick Stolee via GitGitGadget Date: Fri, 13 Feb 2026 23:55:17 GMT Subject: [PATCH v2 12/13] config: format colors gently Message-ID: In-Reply-To: From: Derrick Stolee Move the logic for formatting color config value into a helper method and use gentle parsing when needed. This removes error messages when parsing a list of config values that do not match color formats. Signed-off-by: Derrick Stolee --- builtin/config.c | 27 +++++++++++++++++++++------ t/t1300-config.sh | 9 +-------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 71b685d943..e8c02e5f21 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -354,6 +354,24 @@ static int format_config_expiry_date(struct strbuf *buf, return 0; } +static int format_config_color(struct strbuf *buf, + const char *key_, + const char *value_, + int gently) +{ + char v[COLOR_MAXLEN]; + + if (gently) { + if (color_parse_gently(value_, v) < 0) + return -1; + } else if (git_config_color(v, key_, value_) < 0) { + return -1; + } + + strbuf_addstr(buf, v); + return 0; +} + /* * Format the configuration key-value pair (`key_`, `value_`) and * append it into strbuf `buf`. Returns a negative value on failure, @@ -391,12 +409,9 @@ static int format_config(const struct config_display_options *opts, res = format_config_path(buf, key_, value_, gently); else if (opts->type == TYPE_EXPIRY_DATE) res = format_config_expiry_date(buf, key_, value_, gently); - else if (opts->type == TYPE_COLOR) { - char v[COLOR_MAXLEN]; - if (git_config_color(v, key_, value_) < 0) - return -1; - strbuf_addstr(buf, v); - } else if (value_) { + else if (opts->type == TYPE_COLOR) + res = format_config_color(buf, key_, value_, gently); + else if (value_) { strbuf_addstr(buf, value_); } else { /* Just show the key name; back out delimiter */ diff --git a/t/t1300-config.sh b/t/t1300-config.sh index c134d85d8a..79b2ee203c 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -2553,17 +2553,10 @@ test_expect_success 'list --type=color shows only canonicalizable color values' section.blue= EOF - cat >expecterr <<-EOF && - error: invalid color value: True - error: invalid color value: 1M - error: invalid color value: ~/dir - error: invalid color value: Fri Jun 4 15:46:55 2010 - EOF - git config ${mode_prefix}list --type=color >actual.raw 2>err && test_decode_color actual && test_cmp expect actual && - test_cmp expecterr err + test_must_be_empty err ' test_expect_success '--type rejects unknown specifiers' ' -- gitgitgadget