log: do not shorten decoration names too early
The DECORATE_SHORT_REFS option given to load_ref_decorations() affects the way a copy of the refname is stored for each decorated commit, and this forces later steps like current_pointed_by_HEAD() to adjust their behaviour based on this initial settings. Instead, we can always store the full refname and then shorten them when producing the output. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
May 13, 2015 at 12:40 UTC
429ad204136b2de1cfd2e7f7f5b20df211996c9f
1 file changed
+16
-18
log-tree.c
+16
-18
@@ -94,6 +94,8 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
94
struct object *obj;
95
enum decoration_type type = DECORATION_NONE;
96
97
+ assert(cb_data == NULL);
98
+
99
if (starts_with(refname, "refs/replace/")) {
100
unsigned char original_sha1[20];
101
if (!check_replace_refs)
@@ -123,8 +125,6 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
125
else if (!strcmp(refname, "HEAD"))
126
type = DECORATION_REF_HEAD;
127
126
- if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
127
- refname = prettify_refname(refname);
128
add_name_decoration(type, refname, obj);
129
while (obj->type == OBJ_TAG) {
130
obj = ((struct tag *)obj)->tagged;
@@ -151,8 +151,8 @@ void load_ref_decorations(int flags)
151
if (!decoration_loaded) {
152
decoration_loaded = 1;
153
decoration_flags = flags;
154
- for_each_ref(add_ref_decoration, &flags);
155
- head_ref(add_ref_decoration, &flags);
154
+ for_each_ref(add_ref_decoration, NULL);
155
+ head_ref(add_ref_decoration, NULL);
156
for_each_commit_graft(add_graft_decoration, NULL);
157
}
158
}
@@ -199,18 +199,8 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d
199
if (!(rru_flags & REF_ISSYMREF))
200
return NULL;
201
202
- if ((decoration_flags == DECORATE_SHORT_REFS)) {
203
- if (!skip_prefix(branch_name, "refs/heads/", &branch_name))
204
- return NULL;
205
- } else {
206
- /*
207
- * Each decoration has a refname in full; keep
208
- * branch_name also in full, but still make sure
209
- * HEAD is a reasonable ref.
210
- */
211
- if (!starts_with(branch_name, "refs/"))
212
- return NULL;
213
- }
202
+ if (!starts_with(branch_name, "refs/"))
203
+ return NULL;
204
205
/* OK, do we have that ref in the list? */
206
for (list = decoration; list; list = list->next)
@@ -222,6 +212,14 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d
212
return NULL;
213
}
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
+
223
/*
224
* The caller makes sure there is no funny color before calling.
225
* format_decorations_extended makes sure the same after return.
@@ -259,7 +257,7 @@ void format_decorations_extended(struct strbuf *sb,
257
if (decoration->type == DECORATION_REF_TAG)
258
strbuf_addstr(sb, "tag: ");
259
262
- strbuf_addstr(sb, decoration->name);
260
+ show_name(sb, decoration);
261
262
if (current_and_HEAD &&
263
decoration->type == DECORATION_REF_HEAD) {
@@ -268,7 +266,7 @@ void format_decorations_extended(struct strbuf *sb,
266
strbuf_addstr(sb, " -> ");
267
strbuf_addstr(sb, color_reset);
268
strbuf_addstr(sb, decorate_get_color(use_color, current_and_HEAD->type));
271
- strbuf_addstr(sb, current_and_HEAD->name);
269
+ show_name(sb, current_and_HEAD);
270
}
271
strbuf_addstr(sb, color_reset);
272