4 const char *tag_type
= "tag";
6 struct object
*deref_tag(struct object
*o
, const char *warn
, int warnlen
)
8 while (o
&& o
->type
== TYPE_TAG
)
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
= xcalloc(1, sizeof(struct tag
));
23 created_object(sha1
, &ret
->object
);
24 ret
->object
.type
= TYPE_TAG
;
29 if (obj
->type
!= TYPE_TAG
) {
30 error("Object %s is a %s, not a tree",
31 sha1_to_hex(sha1
), typename(obj
->type
));
34 return (struct tag
*) obj
;
37 int parse_tag_buffer(struct tag
*item
, void *data
, unsigned long size
)
40 unsigned char object
[20];
41 const char *type_line
, *tag_line
, *sig_line
;
44 if (item
->object
.parsed
)
46 item
->object
.parsed
= 1;
50 if (memcmp("object ", data
, 7) || get_sha1_hex(data
+ 7, object
))
53 type_line
= data
+ 48;
54 if (memcmp("\ntype ", type_line
-1, 6))
57 tag_line
= strchr(type_line
, '\n');
58 if (!tag_line
|| memcmp("tag ", ++tag_line
, 4))
61 sig_line
= strchr(tag_line
, '\n');
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
= xmalloc(taglen
+ 1);
73 memcpy(item
->tag
, tag_line
+ 4, taglen
);
74 item
->tag
[taglen
] = '\0';
76 item
->tagged
= lookup_object_type(object
, type
);
77 if (item
->tagged
&& track_object_refs
) {
78 struct object_refs
*refs
= alloc_object_refs(1);
79 refs
->ref
[0] = item
->tagged
;
80 set_object_refs(&item
->object
, refs
);
86 int parse_tag(struct tag
*item
)
93 if (item
->object
.parsed
)
95 data
= read_sha1_file(item
->object
.sha1
, type
, &size
);
97 return error("Could not read %s",
98 sha1_to_hex(item
->object
.sha1
));
99 if (strcmp(type
, tag_type
)) {
101 return error("Object %s not a tag",
102 sha1_to_hex(item
->object
.sha1
));
104 ret
= parse_tag_buffer(item
, data
, size
);