@matheusbsbs / matheus-bagliano / commits / a752412875
Fork 0

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 <ayiehere@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nazri Ramliy committed Jun 19, 2010 at 09:37 UTC a7524128750ebf34fe0639e1e5d7abd03aff0302
1 file changed +32 -8
log-tree.c
+32 -8
@@ -10,29 +10,50 @@
10
11 struct decoration name_decoration = { "object names" };
12
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)
23 {
15 - int plen = strlen(prefix);
24 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;
28 res->next = add_decoration(&name_decoration, obj, res);
29 }
30
31 static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
32 {
33 struct object *obj = parse_object(sha1);
34 + enum decoration_type type = DECORATION_NONE;
35 if (!obj)
36 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 +
49 if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
50 refname = prettify_refname(refname);
30 - add_name_decoration("", refname, obj);
51 + add_name_decoration(type, refname, obj);
52 while (obj->type == OBJ_TAG) {
53 obj = ((struct tag *)obj)->tagged;
54 if (!obj)
55 break;
35 - add_name_decoration("tag: ", refname, obj);
56 + add_name_decoration(DECORATION_REF_TAG, refname, obj);
57 }
58 return 0;
59 }
@@ -70,7 +91,10 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
91 return;
92 prefix = " (";
93 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);
98 prefix = ", ";
99 decoration = decoration->next;
100 }