Skip to content

Commit a752412

Browse files
nazrigitster
authored andcommitted
log-tree.c: Use struct name_decoration's type for classifying decoration
The "tag: " prefix is no longer prepended to the name of the decoration. It is now printed conditionally by show_decorations if the decoration type is DECORATION_REF_TAG. Signed-off-by: Nazri Ramliy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eb3005e commit a752412

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

log-tree.c

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,50 @@
1010

1111
struct decoration name_decoration = { "object names" };
1212

13-
static void add_name_decoration(const char *prefix, const char *name, struct object *obj)
13+
enum decoration_type {
14+
DECORATION_NONE = 0,
15+
DECORATION_REF_LOCAL,
16+
DECORATION_REF_REMOTE,
17+
DECORATION_REF_TAG,
18+
DECORATION_REF_STASH,
19+
DECORATION_REF_HEAD,
20+
};
21+
22+
static void add_name_decoration(enum decoration_type type, const char *name, struct object *obj)
1423
{
15-
int plen = strlen(prefix);
1624
int nlen = strlen(name);
17-
struct name_decoration *res = xmalloc(sizeof(struct name_decoration) + plen + nlen);
18-
memcpy(res->name, prefix, plen);
19-
memcpy(res->name + plen, name, nlen + 1);
25+
struct name_decoration *res = xmalloc(sizeof(struct name_decoration) + nlen);
26+
memcpy(res->name, name, nlen + 1);
27+
res->type = type;
2028
res->next = add_decoration(&name_decoration, obj, res);
2129
}
2230

2331
static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
2432
{
2533
struct object *obj = parse_object(sha1);
34+
enum decoration_type type = DECORATION_NONE;
2635
if (!obj)
2736
return 0;
37+
38+
if (!prefixcmp(refname, "refs/heads"))
39+
type = DECORATION_REF_LOCAL;
40+
else if (!prefixcmp(refname, "refs/remotes"))
41+
type = DECORATION_REF_REMOTE;
42+
else if (!prefixcmp(refname, "refs/tags"))
43+
type = DECORATION_REF_TAG;
44+
else if (!prefixcmp(refname, "refs/stash"))
45+
type = DECORATION_REF_STASH;
46+
else if (!prefixcmp(refname, "HEAD"))
47+
type = DECORATION_REF_HEAD;
48+
2849
if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
2950
refname = prettify_refname(refname);
30-
add_name_decoration("", refname, obj);
51+
add_name_decoration(type, refname, obj);
3152
while (obj->type == OBJ_TAG) {
3253
obj = ((struct tag *)obj)->tagged;
3354
if (!obj)
3455
break;
35-
add_name_decoration("tag: ", refname, obj);
56+
add_name_decoration(DECORATION_REF_TAG, refname, obj);
3657
}
3758
return 0;
3859
}
@@ -70,7 +91,10 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
7091
return;
7192
prefix = " (";
7293
while (decoration) {
73-
printf("%s%s", prefix, decoration->name);
94+
printf("%s", prefix);
95+
if (decoration->type == DECORATION_REF_TAG)
96+
printf("tag: ");
97+
printf("%s", decoration->name);
7498
prefix = ", ";
7599
decoration = decoration->next;
76100
}

0 commit comments

Comments
 (0)