1313#include "line-log.h"
1414
1515static struct decoration name_decoration = { "object names" };
16+ static int decoration_loaded ;
17+ static int decoration_flags ;
1618
1719static char decoration_colors [][COLOR_MAXLEN ] = {
1820 GIT_COLOR_RESET ,
@@ -92,6 +94,8 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
9294 struct object * obj ;
9395 enum decoration_type type = DECORATION_NONE ;
9496
97+ assert (cb_data == NULL );
98+
9599 if (starts_with (refname , "refs/replace/" )) {
96100 unsigned char original_sha1 [20 ];
97101 if (!check_replace_refs )
@@ -121,8 +125,6 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
121125 else if (!strcmp (refname , "HEAD" ))
122126 type = DECORATION_REF_HEAD ;
123127
124- if (!cb_data || * (int * )cb_data == DECORATE_SHORT_REFS )
125- refname = prettify_refname (refname );
126128 add_name_decoration (type , refname , obj );
127129 while (obj -> type == OBJ_TAG ) {
128130 obj = ((struct tag * )obj )-> tagged ;
@@ -146,11 +148,11 @@ static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)
146148
147149void load_ref_decorations (int flags )
148150{
149- static int loaded ;
150- if (! loaded ) {
151- loaded = 1 ;
152- for_each_ref (add_ref_decoration , & flags );
153- head_ref (add_ref_decoration , & flags );
151+ if (! decoration_loaded ) {
152+ decoration_loaded = 1 ;
153+ decoration_flags = flags ;
154+ for_each_ref (add_ref_decoration , NULL );
155+ head_ref (add_ref_decoration , NULL );
154156 for_each_commit_graft (add_graft_decoration , NULL );
155157 }
156158}
@@ -196,7 +198,8 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d
196198 branch_name = resolve_ref_unsafe ("HEAD" , 0 , unused , & rru_flags );
197199 if (!(rru_flags & REF_ISSYMREF ))
198200 return NULL ;
199- if (!skip_prefix (branch_name , "refs/heads/" , & branch_name ))
201+
202+ if (!starts_with (branch_name , "refs/" ))
200203 return NULL ;
201204
202205 /* OK, do we have that ref in the list? */
@@ -209,6 +212,14 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d
209212 return NULL ;
210213}
211214
215+ static void show_name (struct strbuf * sb , const struct name_decoration * decoration )
216+ {
217+ if (decoration_flags == DECORATE_SHORT_REFS )
218+ strbuf_addstr (sb , prettify_refname (decoration -> name ));
219+ else
220+ strbuf_addstr (sb , decoration -> name );
221+ }
222+
212223/*
213224 * The caller makes sure there is no funny color before calling.
214225 * format_decorations_extended makes sure the same after return.
@@ -246,7 +257,7 @@ void format_decorations_extended(struct strbuf *sb,
246257 if (decoration -> type == DECORATION_REF_TAG )
247258 strbuf_addstr (sb , "tag: " );
248259
249- strbuf_addstr (sb , decoration -> name );
260+ show_name (sb , decoration );
250261
251262 if (current_and_HEAD &&
252263 decoration -> type == DECORATION_REF_HEAD ) {
@@ -255,7 +266,7 @@ void format_decorations_extended(struct strbuf *sb,
255266 strbuf_addstr (sb , " -> " );
256267 strbuf_addstr (sb , color_reset );
257268 strbuf_addstr (sb , decorate_get_color (use_color , current_and_HEAD -> type ));
258- strbuf_addstr (sb , current_and_HEAD -> name );
269+ show_name (sb , current_and_HEAD );
259270 }
260271 strbuf_addstr (sb , color_reset );
261272
0 commit comments