]> git.ipfire.org Git - thirdparty/git.git/blame - blob.c
Remove case-sensitive file in t3030-merge-recursive.
[thirdparty/git.git] / blob.c
CommitLineData
175785e5 1#include "cache.h"
8f1d2e6f 2#include "blob.h"
175785e5
DB
3
4const char *blob_type = "blob";
5
5d6ccf5c 6struct 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
25int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size)
26{
27 item->object.parsed = 1;
28 return 0;
29}
30
a510bfaa
DB
31int parse_blob(struct blob *item)
32{
21666f1a 33 enum object_type type;
a510bfaa
DB
34 void *buffer;
35 unsigned long size;
bd2c39f5
NP
36 int ret;
37
a510bfaa
DB
38 if (item->object.parsed)
39 return 0;
21666f1a 40 buffer = read_sha1_file(item->object.sha1, &type, &size);
a510bfaa
DB
41 if (!buffer)
42 return error("Could not read %s",
43 sha1_to_hex(item->object.sha1));
21666f1a 44 if (type != OBJ_BLOB)
a510bfaa
DB
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}