GIT 1.5.1.1
[git/mingw/4msysgit/wingit-dll.git] / blob.c
blob0a9ea417b8af4b06871eae8c47168dc178e9bb29
1 #include "cache.h"
2 #include "blob.h"
4 const char *blob_type = "blob";
6 struct blob *lookup_blob(const unsigned char *sha1)
8 struct object *obj = lookup_object(sha1);
9 if (!obj) {
10 struct blob *ret = alloc_blob_node();
11 created_object(sha1, &ret->object);
12 ret->object.type = OBJ_BLOB;
13 return ret;
15 if (!obj->type)
16 obj->type = OBJ_BLOB;
17 if (obj->type != OBJ_BLOB) {
18 error("Object %s is a %s, not a blob",
19 sha1_to_hex(sha1), typename(obj->type));
20 return NULL;
22 return (struct blob *) obj;
25 int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size)
27 item->object.parsed = 1;
28 return 0;
31 int parse_blob(struct blob *item)
33 enum object_type type;
34 void *buffer;
35 unsigned long size;
36 int ret;
38 if (item->object.parsed)
39 return 0;
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 (type != OBJ_BLOB)
45 return error("Object %s not a blob",
46 sha1_to_hex(item->object.sha1));
47 ret = parse_blob_buffer(item, buffer, size);
48 free(buffer);
49 return ret;