From: Derrick Stolee Date: Mon, 23 Feb 2026 12:26:53 +0000 (+0000) Subject: config: format colors quietly X-Git-Tag: v2.54.0-rc0~114^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2d4ab5a885f365cb66156ff4553f88c000dfa307;p=thirdparty%2Fgit.git config: format colors quietly Move the logic for formatting color config value into a helper method and use quiet 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 Signed-off-by: Junio C Hamano --- diff --git a/builtin/config.c b/builtin/config.c index ee77ddc87c..45304076dc 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -351,6 +351,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_quietly(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, @@ -388,12 +406,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 72bdd6ab03..128971ee12 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -2579,19 +2579,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 - error: invalid color value: :(optional)no-such-path - error: invalid color value: :(optional)expect - 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' '