4 const char *tag_type = "tag";
6 struct object *deref_tag(struct object *o)
8 while (o && o->type == tag_type)
9 o = parse_object(((struct tag *)o)->tagged->sha1);
13 struct tag *lookup_tag(const unsigned char *sha1)
15 struct object *obj = lookup_object(sha1);
17 struct tag *ret = xmalloc(sizeof(struct tag));
18 memset(ret, 0, sizeof(struct tag));
19 created_object(sha1, &ret->object);
20 ret->object.type = tag_type;
25 if (obj->type != tag_type) {
26 error("Object %s is a %s, not a tree",
27 sha1_to_hex(sha1), obj->type);
30 return (struct tag *) obj;
33 int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
36 unsigned char object[20];
37 const char *type_line, *tag_line, *sig_line;
40 if (item->object.parsed)
42 item->object.parsed = 1;
46 if (memcmp("object ", data, 7) || get_sha1_hex(data + 7, object))
49 type_line = data + 48;
50 if (memcmp("\ntype ", type_line-1, 6))
53 tag_line = strchr(type_line, '\n');
54 if (!tag_line || memcmp("tag ", ++tag_line, 4))
57 sig_line = strchr(tag_line, '\n');
62 typelen = tag_line - type_line - strlen("type \n");
65 memcpy(type, type_line + 5, typelen);
67 taglen = sig_line - tag_line - strlen("tag \n");
68 item->tag = xmalloc(taglen + 1);
69 memcpy(item->tag, tag_line + 4, taglen);
70 item->tag[taglen] = '\0';
72 item->tagged = lookup_object_type(object, type);
74 add_ref(&item->object, item->tagged);
79 int parse_tag(struct tag *item)
86 if (item->object.parsed)
88 data = read_sha1_file(item->object.sha1, type, &size);
90 return error("Could not read %s",
91 sha1_to_hex(item->object.sha1));
92 if (strcmp(type, tag_type)) {
94 return error("Object %s not a tag",
95 sha1_to_hex(item->object.sha1));
97 ret = parse_tag_buffer(item, data, size);