aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerrick Stolee <stolee@gmail.com>2026-02-23 12:26:53 +0000
committerJunio C Hamano <gitster@pobox.com>2026-02-23 13:23:41 -0800
commit2d4ab5a885f365cb66156ff4553f88c000dfa307 (patch)
tree01fbe8b58a34f7738576297b69567c28ceba6978
parentdb45e4908d6711ddc3094cb079c85278691c8267 (diff)
downloadgit-2d4ab5a885f365cb66156ff4553f88c000dfa307.tar.xz
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 <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/config.c27
-rwxr-xr-xt/t1300-config.sh11
2 files changed, 22 insertions, 16 deletions
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=<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.raw >actual &&
test_cmp expect actual &&
- test_cmp expecterr err
+ test_must_be_empty err
'
test_expect_success '--type rejects unknown specifiers' '