Skip to content

Commit f35b681

Browse files
committed
config: format colors gently
Move the logic for formatting color config value into a helper method and use gentle parsing when needed. Signed-off-by: Derrick Stolee <stolee@gmail.com>
1 parent 976712e commit f35b681

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

builtin/config.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,24 @@ static int format_config_expiry_date(struct strbuf *buf,
354354
return 0;
355355
}
356356

357+
static int format_config_color(struct strbuf *buf,
358+
const char *key_,
359+
const char *value_,
360+
int gently)
361+
{
362+
char v[COLOR_MAXLEN];
363+
364+
if (gently) {
365+
if (color_parse_gently(value_, v) < 0)
366+
return -1;
367+
} else if (git_config_color(v, key_, value_) < 0) {
368+
return -1;
369+
}
370+
371+
strbuf_addstr(buf, v);
372+
return 0;
373+
}
374+
357375
/*
358376
* Format the configuration key-value pair (`key_`, `value_`) and
359377
* 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,
391409
res = format_config_path(buf, key_, value_, gently);
392410
else if (opts->type == TYPE_EXPIRY_DATE)
393411
res = format_config_expiry_date(buf, key_, value_, gently);
394-
else if (opts->type == TYPE_COLOR) {
395-
char v[COLOR_MAXLEN];
396-
if (git_config_color(v, key_, value_) < 0)
397-
return -1;
398-
strbuf_addstr(buf, v);
399-
} else if (value_) {
412+
else if (opts->type == TYPE_COLOR)
413+
res = format_config_color(buf, key_, value_, gently);
414+
else if (value_) {
400415
strbuf_addstr(buf, value_);
401416
} else {
402417
/* Just show the key name; back out delimiter */

0 commit comments

Comments
 (0)