5 const char *blob_type = "blob";
7 struct blob *lookup_blob(const unsigned char *sha1)
9 struct object *obj = lookup_object(sha1);
11 struct blob *ret = xmalloc(sizeof(struct blob));
12 memset(ret, 0, sizeof(struct blob));
13 created_object(sha1, &ret->object);
14 ret->object.type = blob_type;
18 obj->type = blob_type;
19 if (obj->type != blob_type) {
20 error("Object %s is a %s, not a blob",
21 sha1_to_hex(sha1), obj->type);
24 return (struct blob *) obj;
27 int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size)
29 item->object.parsed = 1;
33 int parse_blob(struct blob *item)
40 if (item->object.parsed)
42 buffer = read_sha1_file(item->object.sha1, type, &size);
44 return error("Could not read %s",
45 sha1_to_hex(item->object.sha1));
46 if (strcmp(type, blob_type))
47 return error("Object %s not a blob",
48 sha1_to_hex(item->object.sha1));
49 ret = parse_blob_buffer(item, buffer, size);