From dcb347f83780b67ba586fda67a5c494b31354eae Mon Sep 17 00:00:00 2001 From: Andy Koppe Date: Sun, 20 Aug 2023 19:50:06 +0100 Subject: decorate: color each token separately Wrap "tag:" prefixes and the arrows in "HEAD -> branch" decorations in their own color sequences. Otherwise, if --graph is used, tag names or arrows can end up uncolored when %w width formatting breaks a line just before them. This is because --graph resets the color after doing its drawing at the start of a line. Amend test t4207-log-decoration-colors.sh accordingly. Signed-off-by: Andy Koppe Signed-off-by: Junio C Hamano --- log-tree.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'log-tree.c') diff --git a/log-tree.c b/log-tree.c index 7c6d3f1ac3..44f4693567 100644 --- a/log-tree.c +++ b/log-tree.c @@ -342,26 +342,34 @@ void format_decorations(struct strbuf *sb, * appeared, skipping the entry for current. */ if (decoration != current_and_HEAD) { + const char *color = + decorate_get_color(use_color, decoration->type); + if (*prefix) { strbuf_addstr(sb, color_commit); strbuf_addstr(sb, prefix); strbuf_addstr(sb, color_reset); } - strbuf_addstr(sb, decorate_get_color(use_color, decoration->type)); - if (decoration->type == DECORATION_REF_TAG) + if (decoration->type == DECORATION_REF_TAG) { + strbuf_addstr(sb, color); strbuf_addstr(sb, "tag: "); + strbuf_addstr(sb, color_reset); + } + strbuf_addstr(sb, color); show_name(sb, decoration); + strbuf_addstr(sb, color_reset); if (current_and_HEAD && decoration->type == DECORATION_REF_HEAD) { + strbuf_addstr(sb, color); strbuf_addstr(sb, " -> "); strbuf_addstr(sb, color_reset); strbuf_addstr(sb, decorate_get_color(use_color, current_and_HEAD->type)); show_name(sb, current_and_HEAD); + strbuf_addstr(sb, color_reset); } - strbuf_addstr(sb, color_reset); prefix = separator; } -- cgit v1.2.3