7 const char *tag_type = "tag";
9 struct object *deref_tag(struct object *o, const char *warn, int warnlen)
11 while (o && o->type == OBJ_TAG)
12 o = parse_object(((struct tag *)o)->tagged->sha1);
15 warnlen = strlen(warn);
16 error("missing object referenced by '%.*s'", warnlen, warn);
21 struct tag *lookup_tag(const unsigned char *sha1)
23 struct object *obj = lookup_object(sha1);
25 return create_object(sha1, OBJ_TAG, alloc_tag_node());
28 if (obj->type != OBJ_TAG) {
29 error("Object %s is a %s, not a tag",
30 sha1_to_hex(sha1), typename(obj->type));
33 return (struct tag *) obj;
36 int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
39 unsigned char sha1[20];
40 const char *type_line, *tag_line, *sig_line;
42 const char *start = data;
44 if (item->object.parsed)
46 item->object.parsed = 1;
50 if (memcmp("object ", data, 7) || get_sha1_hex((char *) data + 7, sha1))
53 type_line = (char *) data + 48;
54 if (memcmp("\ntype ", type_line-1, 6))
57 tag_line = memchr(type_line, '\n', size - (type_line - start));
58 if (!tag_line || memcmp("tag ", ++tag_line, 4))
61 sig_line = memchr(tag_line, '\n', size - (tag_line - start));
66 typelen = tag_line - type_line - strlen("type \n");
69 memcpy(type, type_line + 5, typelen);
71 taglen = sig_line - tag_line - strlen("tag \n");
72 item->tag = xmemdupz(tag_line + 4, taglen);
74 if (!strcmp(type, blob_type)) {
75 item->tagged = &lookup_blob(sha1)->object;
76 } else if (!strcmp(type, tree_type)) {
77 item->tagged = &lookup_tree(sha1)->object;
78 } else if (!strcmp(type, commit_type)) {
79 item->tagged = &lookup_commit(sha1)->object;
80 } else if (!strcmp(type, tag_type)) {
81 item->tagged = &lookup_tag(sha1)->object;
83 error("Unknown type %s", type);
87 if (item->tagged && track_object_refs) {
88 struct object_refs *refs = alloc_object_refs(1);
89 refs->ref[0] = item->tagged;
90 set_object_refs(&item->object, refs);
96 int parse_tag(struct tag *item)
98 enum object_type type;
103 if (item->object.parsed)
105 data = read_sha1_file(item->object.sha1, &type, &size);
107 return error("Could not read %s",
108 sha1_to_hex(item->object.sha1));
109 if (type != OBJ_TAG) {
111 return error("Object %s not a tag",
112 sha1_to_hex(item->object.sha1));
114 ret = parse_tag_buffer(item, data, size);