]> git.ipfire.org Git - thirdparty/git.git/blobdiff - tag.c
The sixth batch
[thirdparty/git.git] / tag.c
diff --git a/tag.c b/tag.c
index 3d37c1bd251c5f8c5eb06ede72ab57b323888709..71b544467efacd12f36e8c61efdc387db11d1bff 100644 (file)
--- a/tag.c
+++ b/tag.c
@@ -1,9 +1,12 @@
 #include "cache.h"
 #include "tag.h"
+#include "object-store.h"
 #include "commit.h"
 #include "tree.h"
 #include "blob.h"
+#include "alloc.h"
 #include "gpg-interface.h"
+#include "packfile.h"
 
 const char *tag_type = "tag";
 
@@ -62,14 +65,20 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
        return ret;
 }
 
-struct object *deref_tag(struct object *o, const char *warn, int warnlen)
+struct object *deref_tag(struct repository *r, struct object *o, const char *warn, int warnlen)
 {
+       struct object_id *last_oid = NULL;
        while (o && o->type == OBJ_TAG)
-               if (((struct tag *)o)->tagged)
-                       o = parse_object(&((struct tag *)o)->tagged->oid);
-               else
+               if (((struct tag *)o)->tagged) {
+                       last_oid = &((struct tag *)o)->tagged->oid;
+                       o = parse_object(r, last_oid);
+               } else {
+                       last_oid = NULL;
                        o = NULL;
+               }
        if (!o && warn) {
+               if (last_oid && is_promisor_object(last_oid))
+                       return NULL;
                if (!warnlen)
                        warnlen = strlen(warn);
                error("missing object referenced by '%.*s'", warnlen, warn);
@@ -80,7 +89,7 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen)
 struct object *deref_tag_noverify(struct object *o)
 {
        while (o && o->type == OBJ_TAG) {
-               o = parse_object(&o->oid);
+               o = parse_object(the_repository, &o->oid);
                if (o && o->type == OBJ_TAG && ((struct tag *)o)->tagged)
                        o = ((struct tag *)o)->tagged;
                else
@@ -89,12 +98,12 @@ struct object *deref_tag_noverify(struct object *o)
        return o;
 }
 
-struct tag *lookup_tag(const struct object_id *oid)
+struct tag *lookup_tag(struct repository *r, const struct object_id *oid)
 {
-       struct object *obj = lookup_object(oid->hash);
+       struct object *obj = lookup_object(r, oid);
        if (!obj)
-               return create_object(oid->hash, alloc_tag_node());
-       return object_as_type(obj, OBJ_TAG, 0);
+               return create_object(r, oid, alloc_tag_node(r));
+       return object_as_type(r, obj, OBJ_TAG, 0);
 }
 
 static timestamp_t parse_tag_date(const char *buf, const char *tail)
@@ -114,7 +123,15 @@ static timestamp_t parse_tag_date(const char *buf, const char *tail)
        return parse_timestamp(dateptr, NULL, 10);
 }
 
-int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
+void release_tag_memory(struct tag *t)
+{
+       free(t->tag);
+       t->tagged = NULL;
+       t->object.parsed = 0;
+       t->date = 0;
+}
+
+int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, unsigned long size)
 {
        struct object_id oid;
        char type[20];
@@ -124,9 +141,18 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
 
        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;
@@ -142,18 +168,23 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
        bufptr = nl + 1;
 
        if (!strcmp(type, blob_type)) {
-               item->tagged = (struct object *)lookup_blob(&oid);
+               item->tagged = (struct object *)lookup_blob(r, &oid);
        } else if (!strcmp(type, tree_type)) {
-               item->tagged = (struct object *)lookup_tree(&oid);
+               item->tagged = (struct object *)lookup_tree(r, &oid);
        } else if (!strcmp(type, commit_type)) {
-               item->tagged = (struct object *)lookup_commit(&oid);
+               item->tagged = (struct object *)lookup_commit(r, &oid);
        } else if (!strcmp(type, tag_type)) {
-               item->tagged = (struct object *)lookup_tag(&oid);
+               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
@@ -170,6 +201,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
        else
                item->date = 0;
 
+       item->object.parsed = 1;
        return 0;
 }
 
@@ -191,7 +223,14 @@ int parse_tag(struct tag *item)
                return error("Object %s not a tag",
                             oid_to_hex(&item->object.oid));
        }
-       ret = parse_tag_buffer(item, data, size);
+       ret = parse_tag_buffer(the_repository, item, data, size);
        free(data);
        return ret;
 }
+
+struct object_id *get_tagged_oid(struct tag *tag)
+{
+       if (!tag->tagged)
+               die("bad tag");
+       return &tag->tagged->oid;
+}