}
}
+struct object *lookup_object_type(const unsigned char *sha1, const char *type)
+{
+ if (!strcmp(type, blob_type)) {
+ return &lookup_blob(sha1)->object;
+ } else if (!strcmp(type, tree_type)) {
+ return &lookup_tree(sha1)->object;
+ } else if (!strcmp(type, commit_type)) {
+ return &lookup_commit(sha1)->object;
+ } else if (!strcmp(type, tag_type)) {
+ return &lookup_tag(sha1)->object;
+ } else {
+ error("Unknown type %s", type);
+ return NULL;
+ }
+}
+
struct object *parse_object(const unsigned char *sha1)
{
unsigned long mapsize;
extern int nr_objs;
extern struct object **objs;
+/** Internal only **/
struct object *lookup_object(const unsigned char *sha1);
+/** Returns the object, having looked it up as being the given type. **/
+struct object *lookup_object_type(const unsigned char *sha1, const char *type);
+
void created_object(const unsigned char *sha1, struct object *obj);
/** Returns the object, having parsed it to find out what it is. **/
int typelen, taglen;
unsigned char object[20];
const char *type_line, *tag_line, *sig_line;
+ char type[20];
if (item->object.parsed)
return 0;
if (memcmp("object ", data, 7) || get_sha1_hex(data + 7, object))
return -1;
- item->tagged = parse_object(object);
- if (item->tagged)
- add_ref(&item->object, item->tagged);
-
type_line = data + 48;
if (memcmp("\ntype ", type_line-1, 6))
return -1;
typelen = tag_line - type_line - strlen("type \n");
if (typelen >= 20)
return -1;
+ memcpy(type, type_line + 5, typelen);
+ type[typelen] = '\0';
taglen = sig_line - tag_line - strlen("tag \n");
item->tag = xmalloc(taglen + 1);
memcpy(item->tag, tag_line + 4, taglen);
item->tag[taglen] = '\0';
+ item->tagged = lookup_object_type(object, type);
+ if (item->tagged)
+ add_ref(&item->object, item->tagged);
+
return 0;
}