Code

Merge branch 'maint'
[git.git] / tag.c
diff --git a/tag.c b/tag.c
index 56a49f4fe1f705ee70bc5318a504c35d1bce963e..f62bcdd994509323080683ce19c1a4d8241f9dec 100644 (file)
--- a/tag.c
+++ b/tag.c
@@ -20,17 +20,13 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen)
 
 struct tag *lookup_tag(const unsigned char *sha1)
 {
-        struct object *obj = lookup_object(sha1);
-        if (!obj) {
-                struct tag *ret = alloc_tag_node();
-                created_object(sha1, &ret->object);
-                ret->object.type = OBJ_TAG;
-                return ret;
-        }
+       struct object *obj = lookup_object(sha1);
+       if (!obj)
+               return create_object(sha1, OBJ_TAG, alloc_tag_node());
        if (!obj->type)
                obj->type = OBJ_TAG;
         if (obj->type != OBJ_TAG) {
-                error("Object %s is a %s, not a tree",
+                error("Object %s is a %s, not a tag",
                       sha1_to_hex(sha1), typename(obj->type));
                 return NULL;
         }
@@ -72,9 +68,7 @@ int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
        memcpy(type, type_line + 5, typelen);
        type[typelen] = '\0';
        taglen = sig_line - tag_line - strlen("tag \n");
-       item->tag = xmalloc(taglen + 1);
-       memcpy(item->tag, tag_line + 4, taglen);
-       item->tag[taglen] = '\0';
+       item->tag = xmemdupz(tag_line + 4, taglen);
 
        if (!strcmp(type, blob_type)) {
                item->tagged = &lookup_blob(sha1)->object;