13
13
#include "line-log.h"
14
14
15
15
static struct decoration name_decoration = { "object names" };
16
+ static int decoration_loaded ;
17
+ static int decoration_flags ;
16
18
17
19
static char decoration_colors [][COLOR_MAXLEN ] = {
18
20
GIT_COLOR_RESET ,
@@ -92,6 +94,8 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
92
94
struct object * obj ;
93
95
enum decoration_type type = DECORATION_NONE ;
94
96
97
+ assert (cb_data == NULL );
98
+
95
99
if (starts_with (refname , "refs/replace/" )) {
96
100
unsigned char original_sha1 [20 ];
97
101
if (!check_replace_refs )
@@ -121,8 +125,6 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
121
125
else if (!strcmp (refname , "HEAD" ))
122
126
type = DECORATION_REF_HEAD ;
123
127
124
- if (!cb_data || * (int * )cb_data == DECORATE_SHORT_REFS )
125
- refname = prettify_refname (refname );
126
128
add_name_decoration (type , refname , obj );
127
129
while (obj -> type == OBJ_TAG ) {
128
130
obj = ((struct tag * )obj )-> tagged ;
@@ -146,11 +148,11 @@ static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)
146
148
147
149
void load_ref_decorations (int flags )
148
150
{
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 );
154
156
for_each_commit_graft (add_graft_decoration , NULL );
155
157
}
156
158
}
@@ -196,7 +198,8 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d
196
198
branch_name = resolve_ref_unsafe ("HEAD" , 0 , unused , & rru_flags );
197
199
if (!(rru_flags & REF_ISSYMREF ))
198
200
return NULL ;
199
- if (!skip_prefix (branch_name , "refs/heads/" , & branch_name ))
201
+
202
+ if (!starts_with (branch_name , "refs/" ))
200
203
return NULL ;
201
204
202
205
/* 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
209
212
return NULL ;
210
213
}
211
214
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
+
212
223
/*
213
224
* The caller makes sure there is no funny color before calling.
214
225
* format_decorations_extended makes sure the same after return.
@@ -246,7 +257,7 @@ void format_decorations_extended(struct strbuf *sb,
246
257
if (decoration -> type == DECORATION_REF_TAG )
247
258
strbuf_addstr (sb , "tag: " );
248
259
249
- strbuf_addstr (sb , decoration -> name );
260
+ show_name (sb , decoration );
250
261
251
262
if (current_and_HEAD &&
252
263
decoration -> type == DECORATION_REF_HEAD ) {
@@ -255,7 +266,7 @@ void format_decorations_extended(struct strbuf *sb,
255
266
strbuf_addstr (sb , " -> " );
256
267
strbuf_addstr (sb , color_reset );
257
268
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 );
259
270
}
260
271
strbuf_addstr (sb , color_reset );
261
272
0 commit comments