Refs other than those with builtin special meaning do not appear in log decorations by default, but they can be made to appear using the decoration filter options. However, they would do so without coloring. Add config option color.decorate.ref to address this, defaulting to bold magenta, which is the same as refs/stash. To implement this, add NAMESPACE_REF with pattern "refs/", but do not set its .include bit, so as to leave it out of the default decoration filter. Document the color.decorate slot on the git-config page and amend t4207-log-decoration-colors.sh to test it. Signed-off-by: Andy Koppe <andy.koppe@xxxxxxxxx> --- Documentation/config/color.txt | 3 +++ commit.h | 1 + log-tree.c | 2 ++ refs.c | 7 +++++++ refs.h | 1 + t/t4207-log-decoration-colors.sh | 9 +++++++-- 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Documentation/config/color.txt b/Documentation/config/color.txt index ba9f56885e3..086efebbe5d 100644 --- a/Documentation/config/color.txt +++ b/Documentation/config/color.txt @@ -92,6 +92,9 @@ color.decorate.<slot>:: the stash ref `grafted`;; grafted commits (used to implement shallow clones) +`ref`;; + any other refs (not shown unless enabled with one of the decoration + filter options such as `--decorate-refs=<pattern>`) `symbol`;; punctuation surrounding the other elements -- diff --git a/commit.h b/commit.h index cb13e4d5baa..f6b2125fc42 100644 --- a/commit.h +++ b/commit.h @@ -54,6 +54,7 @@ enum decoration_type { DECORATION_REF_REMOTE, DECORATION_REF_TAG, DECORATION_REF_STASH, + DECORATION_REF, DECORATION_REF_HEAD, DECORATION_GRAFTED, DECORATION_SYMBOL, diff --git a/log-tree.c b/log-tree.c index 890024f205b..fd99eb88d95 100644 --- a/log-tree.c +++ b/log-tree.c @@ -39,6 +39,7 @@ static char decoration_colors[][COLOR_MAXLEN] = { [DECORATION_REF_REMOTE] = GIT_COLOR_BOLD_RED, [DECORATION_REF_TAG] = GIT_COLOR_BOLD_YELLOW, [DECORATION_REF_STASH] = GIT_COLOR_BOLD_MAGENTA, + [DECORATION_REF] = GIT_COLOR_BOLD_MAGENTA, [DECORATION_REF_HEAD] = GIT_COLOR_BOLD_CYAN, [DECORATION_GRAFTED] = GIT_COLOR_BOLD_BLUE, [DECORATION_SYMBOL] = GIT_COLOR_NIL, @@ -49,6 +50,7 @@ static const char *color_decorate_slots[] = { [DECORATION_REF_REMOTE] = "remoteBranch", [DECORATION_REF_TAG] = "tag", [DECORATION_REF_STASH] = "stash", + [DECORATION_REF] = "ref", [DECORATION_REF_HEAD] = "HEAD", [DECORATION_GRAFTED] = "grafted", [DECORATION_SYMBOL] = "symbol", diff --git a/refs.c b/refs.c index 416c35f0c2f..b03cccab909 100644 --- a/refs.c +++ b/refs.c @@ -142,6 +142,13 @@ struct ref_namespace_info ref_namespace[] = { */ .ref = "refs/rewritten/", }, + [NAMESPACE_REFS] = { + /* + * Catch-all for any other refs. + */ + .ref = "refs/", + .decoration = DECORATION_REF, + }, }; void update_ref_namespace(enum ref_namespace namespace, char *ref) diff --git a/refs.h b/refs.h index 4b054d30fe5..82aecd37a2b 100644 --- a/refs.h +++ b/refs.h @@ -1008,6 +1008,7 @@ enum ref_namespace { NAMESPACE_NOTES, NAMESPACE_PREFETCH, NAMESPACE_REWRITTEN, + NAMESPACE_REFS, /* Must be last */ NAMESPACE__COUNT diff --git a/t/t4207-log-decoration-colors.sh b/t/t4207-log-decoration-colors.sh index f4173b61141..4b51e34f8b2 100755 --- a/t/t4207-log-decoration-colors.sh +++ b/t/t4207-log-decoration-colors.sh @@ -17,6 +17,7 @@ test_expect_success setup ' git config color.decorate.remoteBranch red && git config color.decorate.tag "reverse bold yellow" && git config color.decorate.stash magenta && + git config color.decorate.ref blue && git config color.decorate.grafted black && git config color.decorate.symbol white && git config color.decorate.HEAD cyan && @@ -28,11 +29,13 @@ test_expect_success setup ' c_remoteBranch="<RED>" && c_tag="<BOLD;REVERSE;YELLOW>" && c_stash="<MAGENTA>" && + c_ref="<BLUE>" && c_HEAD="<CYAN>" && c_grafted="<BLACK>" && c_symbol="<WHITE>" && test_commit A && + git update-ref refs/foo A && git clone . other && ( cd other && @@ -65,10 +68,12 @@ ${c_remoteBranch}other/main${c_reset}${c_symbol})${c_reset} A1 ${c_commit}COMMIT_ID${c_reset}${c_symbol} (${c_reset}\ ${c_stash}refs/stash${c_reset}${c_symbol})${c_reset} On main: Changes to A.t ${c_commit}COMMIT_ID${c_reset}${c_symbol} (${c_reset}\ -${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_symbol})${c_reset} A +${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_symbol}, ${c_reset}\ +${c_ref}refs/foo${c_reset}${c_symbol})${c_reset} A EOF - git log --first-parent --no-abbrev --decorate --oneline --color=always --all >actual && + git log --first-parent --no-abbrev --decorate --clear-decorations \ + --oneline --color=always --all >actual && cmp_filtered_decorations ' -- 2.42.GIT