Skip to contentSkip to conversation

log: omit tag prefix for color decoration

PATCH In review Andy Koppe 2 participants 3 messages Feb 19, 2023 – Feb 21, 2023

lore
Share & tools
lore

Andy Koppe

author
#0 lore raw

PATCH 1/1 log: omit tag prefix for color decoration

Omit the "tag: " prefix for tags in commit decorations when coloring is enabled. The prefix isn't necessary as such when tags are distinguished by color already, and omitting it saves a bit of space and visual noise.

It also avoids a problem: when the %d or %D placeholders are used while a %w wrapping specifier is in force in a format string, lines can be broken between the prefix and the tag name. In that case, the prefix gets colored correctly, but the tag name gets the default color instead.

Also remove the tag prefix from test t4207 for color decorations, and add --no-color to a test t6002 check of the output of rev-list --bisect that expects tag prefixes to be present.

---

CI run: https://github.com/ak2/git/actions/runs/4211957381

 log-tree.c                       |  3 ++-
 t/t4207-log-decoration-colors.sh | 22 +++++++++++-----------
 t/t6002-rev-list-bisect.sh       |  2 +-
 3 files changed, 14 insertions(+), 13 deletions(-)
log-tree.c +2 -1
index 1dd5fcbf7b..64ea15e0a0 100644
@@ -324,7 +324,8 @@ void format_decorations_extended(struct strbuf *sb,
 			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 (!use_color &&
+			    decoration->type == DECORATION_REF_TAG)
 				strbuf_addstr(sb, "tag: ");
 
 			show_name(sb, decoration);
t/t4207-log-decoration-colors.sh +11 -11
index ded33a82e2..a5ee7b19d7 100755
@@ -55,13 +55,13 @@ test_expect_success 'commit decorations colored correctly' '
 	cat >expect <<-EOF &&
 	${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD -> \
 ${c_reset}${c_branch}main${c_reset}${c_commit}, \
-${c_reset}${c_tag}tag: v1.0${c_reset}${c_commit}, \
-${c_reset}${c_tag}tag: B${c_reset}${c_commit})${c_reset} B
-${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A1${c_reset}${c_commit}, \
+${c_reset}${c_tag}v1.0${c_reset}${c_commit}, \
+${c_reset}${c_tag}B${c_reset}${c_commit})${c_reset} B
+${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}A1${c_reset}${c_commit}, \
 ${c_reset}${c_remoteBranch}other/main${c_reset}${c_commit})${c_reset} A1
 	${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_stash}refs/stash${c_reset}${c_commit})${c_reset} \
 On main: Changes to A.t
-	${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A${c_reset}${c_commit})${c_reset} A
+	${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}A${c_reset}${c_commit})${c_reset} A
 	EOF
 
 	git log --first-parent --no-abbrev --decorate --oneline --color=always --all >actual &&
@@ -78,10 +78,10 @@ test_expect_success 'test coloring with replace-objects' '
 	cat >expect <<-EOF &&
 	${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD -> \
 ${c_reset}${c_branch}main${c_reset}${c_commit}, \
-${c_reset}${c_tag}tag: D${c_reset}${c_commit})${c_reset} D
-	${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: C${c_reset}${c_commit}, \
+${c_reset}${c_tag}D${c_reset}${c_commit})${c_reset} D
+	${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}C${c_reset}${c_commit}, \
 ${c_reset}${c_grafted}replaced${c_reset}${c_commit})${c_reset} B
-	${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A${c_reset}${c_commit})${c_reset} A
+	${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}A${c_reset}${c_commit})${c_reset} A
 EOF
 
 	git log --first-parent --no-abbrev --decorate --oneline --color=always HEAD >actual &&
@@ -102,11 +102,11 @@ test_expect_success 'test coloring with grafted commit' '
 	cat >expect <<-EOF &&
 	${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD -> \
 ${c_reset}${c_branch}main${c_reset}${c_commit}, \
-${c_reset}${c_tag}tag: D${c_reset}${c_commit}, \
+${c_reset}${c_tag}D${c_reset}${c_commit}, \
 ${c_reset}${c_grafted}replaced${c_reset}${c_commit})${c_reset} D
-	${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: v1.0${c_reset}${c_commit}, \
-${c_reset}${c_tag}tag: B${c_reset}${c_commit})${c_reset} B
-	${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A${c_reset}${c_commit})${c_reset} A
+	${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}v1.0${c_reset}${c_commit}, \
+${c_reset}${c_tag}B${c_reset}${c_commit})${c_reset} B
+	${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}A${c_reset}${c_commit})${c_reset} A
 	EOF
 
 	git log --first-parent --no-abbrev --decorate --oneline --color=always HEAD >actual &&
t/t6002-rev-list-bisect.sh +1 -1
index 162cf50778..924923afaa 100755
@@ -305,7 +305,7 @@ test_expect_success '--bisect-all --first-parent' '
 	# expect results to be ordered by distance (descending),
 	# commit hash (ascending)
 	sort -k4,4r -k1,1 expect.unsorted >expect &&
-	git rev-list --bisect-all --first-parent E ^F >actual &&
+	git rev-list --bisect-all --first-parent --no-color E ^F >actual &&
 	test_cmp expect actual
 '
 
Signature · 1 line
2.39.0
#1 lore raw
Quoted 3 lines · Andy Koppe

Omit the "tag: " prefix for tags in commit decorations when coloring is enabled. The prefix isn't necessary as such when tags are distinguished by color already, and omitting it saves a bit of space and visual noise.

As somebody whose color perception is weaker than other people, I am torn about this line of changes. Accessibiilty folks often warn us against designing UI that differentiates two things only by painting them in two different colors "to be inclusive", and the above goes directly against their guidelines.

The only saving grace in this case is that I expect that tags are named very differently from topics in well managed projects, and users can tell withotu "tag:" prefix even in the output without colors, and that si why I said "I am torn", not I am not outright 100% negative, but still I doubt that the upside of shortening 4 display spaces is worth going directly against inclusion advocates.

So...

author
#2 lore raw
Quoted 13 lines · Junio C Hamano
Quoted 3 lines · Andy Koppe

Omit the "tag: " prefix for tags in commit decorations when coloring is enabled. The prefix isn't necessary as such when tags are distinguished by color already, and omitting it saves a bit of space and visual noise.

As somebody whose color perception is weaker than other people, I am torn about this line of changes. Accessibiilty folks often warn us against designing UI that differentiates two things only by painting them in two different colors "to be inclusive", and the above goes directly against their guidelines.

Quoted 6 lines

The only saving grace in this case is that I expect that tags are named very differently from topics in well managed projects, and users can tell withotu "tag:" prefix even in the output without colors, and that si why I said "I am torn", not I am not outright 100% negative, but still I doubt that the upside of shortening 4 display spaces is worth going directly against inclusion advocates.

I can't argue with that, particularly when changing default behavior.

Would you welcome a patch instead that implements a new %r pretty format placeholder alongside %d and %D that lists the refs separated by spaces only, i.e. without parentheses, commas or tag prefixes?

%d
ref names, like the --decorate option of git-log(1)

%D
ref names without the " (", ")" wrapping.

%r
ref names only

(Having looked at the relevant code, I think it should still be a fairly small change.)