4 const char *tag_type = "tag";
6 struct object *deref_tag(struct object *o, const char *warn, int warnlen)
8 while (o && o->type == tag_type)
9 o = parse_object(((struct tag *)o)->tagged->sha1);
12 warnlen = strlen(warn);
13 error("missing object referenced by '%.*s'", warnlen, warn);
18 struct tag *lookup_tag(const unsigned char *sha1)
20 struct object *obj = lookup_object(sha1);
22 struct tag *ret = xmalloc(sizeof(struct tag));
23 memset(ret, 0, sizeof(struct tag));
24 created_object(sha1, &ret->object);
25 ret->object.type = tag_type;
30 if (obj->type != tag_type) {
31 error("Object %s is a %s, not a tree",
32 sha1_to_hex(sha1), obj->type);
35 return (struct tag *) obj;
38 int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
41 unsigned char object[20];
42 const char *type_line, *tag_line, *sig_line;
45 if (item->object.parsed)
47 item->object.parsed = 1;
51 if (memcmp("object ", data, 7) || get_sha1_hex(data + 7, object))
54 type_line = data + 48;
55 if (memcmp("\ntype ", type_line-1, 6))
58 tag_line = strchr(type_line, '\n');
59 if (!tag_line || memcmp("tag ", ++tag_line, 4))
62 sig_line = strchr(tag_line, '\n');
67 typelen = tag_line - type_line - strlen("type \n");
70 memcpy(type, type_line + 5, typelen);
72 taglen = sig_line - tag_line - strlen("tag \n");
73 item->tag = xmalloc(taglen + 1);
74 memcpy(item->tag, tag_line + 4, taglen);
75 item->tag[taglen] = '\0';
77 item->tagged = lookup_object_type(object, type);
78 if (item->tagged && track_object_refs) {
79 struct object_refs *refs = alloc_object_refs(1);
80 refs->ref[0] = item->tagged;
81 set_object_refs(&item->object, refs);
87 int parse_tag(struct tag *item)
94 if (item->object.parsed)
96 data = read_sha1_file(item->object.sha1, type, &size);
98 return error("Could not read %s",
99 sha1_to_hex(item->object.sha1));
100 if (strcmp(type, tag_type)) {
102 return error("Object %s not a tag",
103 sha1_to_hex(item->object.sha1));
105 ret = parse_tag_buffer(item, data, size);