]>
Commit | Line | Data |
---|---|---|
175785e5 | 1 | #include "cache.h" |
8f1d2e6f | 2 | #include "blob.h" |
175785e5 DB |
3 | |
4 | const char *blob_type = "blob"; | |
5 | ||
5d6ccf5c | 6 | struct blob *lookup_blob(const unsigned char *sha1) |
175785e5 DB |
7 | { |
8 | struct object *obj = lookup_object(sha1); | |
9 | if (!obj) { | |
855419f7 | 10 | struct blob *ret = alloc_blob_node(); |
175785e5 | 11 | created_object(sha1, &ret->object); |
1974632c | 12 | ret->object.type = OBJ_BLOB; |
175785e5 DB |
13 | return ret; |
14 | } | |
d1af002d | 15 | if (!obj->type) |
1974632c LT |
16 | obj->type = OBJ_BLOB; |
17 | if (obj->type != OBJ_BLOB) { | |
885a86ab LT |
18 | error("Object %s is a %s, not a blob", |
19 | sha1_to_hex(sha1), typename(obj->type)); | |
175785e5 DB |
20 | return NULL; |
21 | } | |
22 | return (struct blob *) obj; | |
23 | } | |
a510bfaa | 24 | |
bd2c39f5 NP |
25 | int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size) |
26 | { | |
27 | item->object.parsed = 1; | |
28 | return 0; | |
29 | } | |
30 | ||
a510bfaa DB |
31 | int parse_blob(struct blob *item) |
32 | { | |
33 | char type[20]; | |
34 | void *buffer; | |
35 | unsigned long size; | |
bd2c39f5 NP |
36 | int ret; |
37 | ||
a510bfaa DB |
38 | if (item->object.parsed) |
39 | return 0; | |
a510bfaa DB |
40 | buffer = read_sha1_file(item->object.sha1, type, &size); |
41 | if (!buffer) | |
42 | return error("Could not read %s", | |
43 | sha1_to_hex(item->object.sha1)); | |
44 | if (strcmp(type, blob_type)) | |
45 | return error("Object %s not a blob", | |
46 | sha1_to_hex(item->object.sha1)); | |
bd2c39f5 NP |
47 | ret = parse_blob_buffer(item, buffer, size); |
48 | free(buffer); | |
49 | return ret; | |
a510bfaa | 50 | } |