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>
maint
Nazri Ramliy 2010-06-19 09:37:34 +08:00 committed by Junio C Hamano
parent eb3005e274
commit a752412875
1 changed files with 32 additions and 8 deletions

View File

@ -10,29 +10,50 @@


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


static void add_name_decoration(const char *prefix, const char *name, struct object *obj) enum decoration_type {
DECORATION_NONE = 0,
DECORATION_REF_LOCAL,
DECORATION_REF_REMOTE,
DECORATION_REF_TAG,
DECORATION_REF_STASH,
DECORATION_REF_HEAD,
};

static void add_name_decoration(enum decoration_type type, const char *name, struct object *obj)
{ {
int plen = strlen(prefix);
int nlen = strlen(name); int nlen = strlen(name);
struct name_decoration *res = xmalloc(sizeof(struct name_decoration) + plen + nlen); struct name_decoration *res = xmalloc(sizeof(struct name_decoration) + nlen);
memcpy(res->name, prefix, plen); memcpy(res->name, name, nlen + 1);
memcpy(res->name + plen, name, nlen + 1); res->type = type;
res->next = add_decoration(&name_decoration, obj, res); res->next = add_decoration(&name_decoration, obj, res);
} }


static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data) static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
{ {
struct object *obj = parse_object(sha1); struct object *obj = parse_object(sha1);
enum decoration_type type = DECORATION_NONE;
if (!obj) if (!obj)
return 0; return 0;

if (!prefixcmp(refname, "refs/heads"))
type = DECORATION_REF_LOCAL;
else if (!prefixcmp(refname, "refs/remotes"))
type = DECORATION_REF_REMOTE;
else if (!prefixcmp(refname, "refs/tags"))
type = DECORATION_REF_TAG;
else if (!prefixcmp(refname, "refs/stash"))
type = DECORATION_REF_STASH;
else if (!prefixcmp(refname, "HEAD"))
type = DECORATION_REF_HEAD;

if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS) if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
refname = prettify_refname(refname); refname = prettify_refname(refname);
add_name_decoration("", refname, obj); add_name_decoration(type, refname, obj);
while (obj->type == OBJ_TAG) { while (obj->type == OBJ_TAG) {
obj = ((struct tag *)obj)->tagged; obj = ((struct tag *)obj)->tagged;
if (!obj) if (!obj)
break; break;
add_name_decoration("tag: ", refname, obj); add_name_decoration(DECORATION_REF_TAG, refname, obj);
} }
return 0; return 0;
} }
@ -70,7 +91,10 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
return; return;
prefix = " ("; prefix = " (";
while (decoration) { while (decoration) {
printf("%s%s", prefix, decoration->name); printf("%s", prefix);
if (decoration->type == DECORATION_REF_TAG)
printf("tag: ");
printf("%s", decoration->name);
prefix = ", "; prefix = ", ";
decoration = decoration->next; decoration = decoration->next;
} }