git-svn: make it play nicely with submodules
[gitweb.git] / tag.c
diff --git a/tag.c b/tag.c
index f789744ccaf5d5fb6f63ba0911a869492affc162..5b0ac62ed846188ad44ceac41d278ff37ec8bd9d 100644 (file)
--- a/tag.c
+++ b/tag.c
@@ -4,9 +4,6 @@
 #include "tree.h"
 #include "blob.h"
 
-#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----"
-#define PGP_MESSAGE "-----BEGIN PGP MESSAGE-----"
-
 const char *tag_type = "tag";
 
 struct object *deref_tag(struct object *o, const char *warn, int warnlen)
@@ -24,19 +21,24 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen)
        return o;
 }
 
+struct object *deref_tag_noverify(struct object *o)
+{
+       while (o && o->type == OBJ_TAG) {
+               o = parse_object(o->sha1);
+               if (o && o->type == OBJ_TAG && ((struct tag *)o)->tagged)
+                       o = ((struct tag *)o)->tagged;
+               else
+                       o = NULL;
+       }
+       return o;
+}
+
 struct tag *lookup_tag(const unsigned char *sha1)
 {
        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 tag",
-                     sha1_to_hex(sha1), typename(obj->type));
-               return NULL;
-       }
-       return (struct tag *) obj;
+               return create_object(sha1, alloc_tag_node());
+       return object_as_type(obj, OBJ_TAG, 0);
 }
 
 static unsigned long parse_tag_date(const char *buf, const char *tail)
@@ -56,7 +58,7 @@ static unsigned long parse_tag_date(const char *buf, const char *tail)
        return strtoul(dateptr, NULL, 10);
 }
 
-int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
+int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
 {
        unsigned char sha1[20];
        char type[20];
@@ -74,7 +76,7 @@ int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
                return -1;
        bufptr += 48; /* "object " + sha1 + "\n" */
 
-       if (prefixcmp(bufptr, "type "))
+       if (!starts_with(bufptr, "type "))
                return -1;
        bufptr += 5;
        nl = memchr(bufptr, '\n', tail - bufptr);
@@ -97,7 +99,9 @@ int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
                item->tagged = NULL;
        }
 
-       if (prefixcmp(bufptr, "tag "))
+       if (bufptr + 4 < tail && starts_with(bufptr, "tag "))
+               ;               /* good */
+       else
                return -1;
        bufptr += 4;
        nl = memchr(bufptr, '\n', tail - bufptr);
@@ -106,7 +110,7 @@ int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
        item->tag = xmemdupz(bufptr, nl - bufptr);
        bufptr = nl + 1;
 
-       if (!prefixcmp(bufptr, "tagger "))
+       if (bufptr + 7 < tail && starts_with(bufptr, "tagger "))
                item->date = parse_tag_date(bufptr, tail);
        else
                item->date = 0;
@@ -136,15 +140,3 @@ int parse_tag(struct tag *item)
        free(data);
        return ret;
 }
-
-size_t parse_signature(const char *buf, unsigned long size)
-{
-       char *eol;
-       size_t len = 0;
-       while (len < size && prefixcmp(buf + len, PGP_SIGNATURE) &&
-                       prefixcmp(buf + len, PGP_MESSAGE)) {
-               eol = memchr(buf + len, '\n', size - len);
-               len += eol ? eol - (buf + len) + 1 : size - len;
-       }
-       return len;
-}