]> git.ipfire.org Git - thirdparty/git.git/blobdiff - tag.c
Merge branch 'js/default-branch-name'
[thirdparty/git.git] / tag.c
diff --git a/tag.c b/tag.c
index 1db663d71623a493286c90b13532c7d1cf73f517..1ed2684e45bd50d051ade60cc6b66c8c44fbed59 100644 (file)
--- a/tag.c
+++ b/tag.c
@@ -100,11 +100,10 @@ struct object *deref_tag_noverify(struct object *o)
 
 struct tag *lookup_tag(struct repository *r, const struct object_id *oid)
 {
-       struct object *obj = lookup_object(r, oid->hash);
+       struct object *obj = lookup_object(r, oid);
        if (!obj)
-               return create_object(r, oid->hash,
-                                    alloc_tag_node(r));
-       return object_as_type(r, obj, OBJ_TAG, 0);
+               return create_object(r, oid, alloc_tag_node(r));
+       return object_as_type(obj, OBJ_TAG, 0);
 }
 
 static timestamp_t parse_tag_date(const char *buf, const char *tail)
@@ -142,9 +141,18 @@ int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, u
 
        if (item->object.parsed)
                return 0;
-       item->object.parsed = 1;
 
-       if (size < GIT_SHA1_HEXSZ + 24)
+       if (item->tag) {
+               /*
+                * Presumably left over from a previous failed parse;
+                * clear it out in preparation for re-parsing (we'll probably
+                * hit the same error, which lets us tell our current caller
+                * about the problem).
+                */
+               FREE_AND_NULL(item->tag);
+       }
+
+       if (size < the_hash_algo->hexsz + 24)
                return -1;
        if (memcmp("object ", bufptr, 7) || parse_oid_hex(bufptr + 7, &oid, &bufptr) || *bufptr++ != '\n')
                return -1;
@@ -168,10 +176,15 @@ int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, u
        } else if (!strcmp(type, tag_type)) {
                item->tagged = (struct object *)lookup_tag(r, &oid);
        } else {
-               error("Unknown type %s", type);
-               item->tagged = NULL;
+               return error("unknown tag type '%s' in %s",
+                            type, oid_to_hex(&item->object.oid));
        }
 
+       if (!item->tagged)
+               return error("bad tag pointer to %s in %s",
+                            oid_to_hex(&oid),
+                            oid_to_hex(&item->object.oid));
+
        if (bufptr + 4 < tail && starts_with(bufptr, "tag "))
                ;               /* good */
        else
@@ -188,6 +201,7 @@ int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, u
        else
                item->date = 0;
 
+       item->object.parsed = 1;
        return 0;
 }
 
@@ -213,3 +227,10 @@ int parse_tag(struct tag *item)
        free(data);
        return ret;
 }
+
+struct object_id *get_tagged_oid(struct tag *tag)
+{
+       if (!tag->tagged)
+               die("bad tag");
+       return &tag->tagged->oid;
+}