Use $GITPERLLIB instead of $RUNNING_GIT_TESTS and centralize @INC munging
[git/vmiklos.git] / blob.c
blob496f270043a617242efa9d27285853feb2597484
1 #include "cache.h"
2 #include "blob.h"
3 #include <stdlib.h>
5 const char *blob_type = "blob";
7 struct blob *lookup_blob(const unsigned char *sha1)
9 struct object *obj = lookup_object(sha1);
10 if (!obj) {
11 struct blob *ret = alloc_blob_node();
12 created_object(sha1, &ret->object);
13 ret->object.type = TYPE_BLOB;
14 return ret;
16 if (!obj->type)
17 obj->type = TYPE_BLOB;
18 if (obj->type != TYPE_BLOB) {
19 error("Object %s is a %s, not a blob",
20 sha1_to_hex(sha1), typename(obj->type));
21 return NULL;
23 return (struct blob *) obj;
26 int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size)
28 item->object.parsed = 1;
29 return 0;
32 int parse_blob(struct blob *item)
34 char type[20];
35 void *buffer;
36 unsigned long size;
37 int ret;
39 if (item->object.parsed)
40 return 0;
41 buffer = read_sha1_file(item->object.sha1, type, &size);
42 if (!buffer)
43 return error("Could not read %s",
44 sha1_to_hex(item->object.sha1));
45 if (strcmp(type, blob_type))
46 return error("Object %s not a blob",
47 sha1_to_hex(item->object.sha1));
48 ret = parse_blob_buffer(item, buffer, size);
49 free(buffer);
50 return ret;