|
10 | 10 |
|
11 | 11 | struct decoration name_decoration = { "object names" };
|
12 | 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) |
14 | 23 | {
|
15 |
| - int plen = strlen(prefix); |
16 | 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; |
20 | 28 | res->next = add_decoration(&name_decoration, obj, res);
|
21 | 29 | }
|
22 | 30 |
|
23 | 31 | static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
|
24 | 32 | {
|
25 | 33 | struct object *obj = parse_object(sha1);
|
| 34 | + enum decoration_type type = DECORATION_NONE; |
26 | 35 | if (!obj)
|
27 | 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 | + |
28 | 49 | if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
|
29 | 50 | refname = prettify_refname(refname);
|
30 |
| - add_name_decoration("", refname, obj); |
| 51 | + add_name_decoration(type, refname, obj); |
31 | 52 | while (obj->type == OBJ_TAG) {
|
32 | 53 | obj = ((struct tag *)obj)->tagged;
|
33 | 54 | if (!obj)
|
34 | 55 | break;
|
35 |
| - add_name_decoration("tag: ", refname, obj); |
| 56 | + add_name_decoration(DECORATION_REF_TAG, refname, obj); |
36 | 57 | }
|
37 | 58 | return 0;
|
38 | 59 | }
|
@@ -70,7 +91,10 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
|
70 | 91 | return;
|
71 | 92 | prefix = " (";
|
72 | 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); |
74 | 98 | prefix = ", ";
|
75 | 99 | decoration = decoration->next;
|
76 | 100 | }
|
|
0 commit comments