🌐 AI搜索 & 代理 主页
blob: bd7d078e1ae5fe4ce0a16fda62a2c1743237941b [file] [log] [blame]
Daniel Barkalow175785e2005-04-18 18:39:481#include "cache.h"
Junio C Hamano8f1d2e62006-01-07 09:33:542#include "blob.h"
Daniel Barkalow175785e2005-04-18 18:39:483
4const char *blob_type = "blob";
5
Jason McMullan5d6ccf52005-06-03 15:05:396struct blob *lookup_blob(const unsigned char *sha1)
Daniel Barkalow175785e2005-04-18 18:39:487{
8 struct object *obj = lookup_object(sha1);
Linus Torvalds100c5f32007-04-17 05:11:439 if (!obj)
10 return create_object(sha1, OBJ_BLOB, alloc_blob_node());
Nicolas Pitred1af0022005-05-20 20:59:1711 if (!obj->type)
Linus Torvalds19746322006-07-12 03:45:3112 obj->type = OBJ_BLOB;
13 if (obj->type != OBJ_BLOB) {
Linus Torvalds885a86a2006-06-14 23:45:1314 error("Object %s is a %s, not a blob",
15 sha1_to_hex(sha1), typename(obj->type));
Daniel Barkalow175785e2005-04-18 18:39:4816 return NULL;
17 }
18 return (struct blob *) obj;
19}
Daniel Barkalowa510bfa2005-04-28 14:46:3320
Nicolas Pitrebd2c39f2005-05-06 17:48:3421int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size)
22{
23 item->object.parsed = 1;
24 return 0;
25}
26
Daniel Barkalowa510bfa2005-04-28 14:46:3327int parse_blob(struct blob *item)
28{
Nicolas Pitre21666f12007-02-26 19:55:5929 enum object_type type;
Daniel Barkalowa510bfa2005-04-28 14:46:3330 void *buffer;
31 unsigned long size;
Nicolas Pitrebd2c39f2005-05-06 17:48:3432 int ret;
33
Daniel Barkalowa510bfa2005-04-28 14:46:3334 if (item->object.parsed)
35 return 0;
Nicolas Pitre21666f12007-02-26 19:55:5936 buffer = read_sha1_file(item->object.sha1, &type, &size);
Daniel Barkalowa510bfa2005-04-28 14:46:3337 if (!buffer)
38 return error("Could not read %s",
39 sha1_to_hex(item->object.sha1));
Nicolas Pitre21666f12007-02-26 19:55:5940 if (type != OBJ_BLOB)
Daniel Barkalowa510bfa2005-04-28 14:46:3341 return error("Object %s not a blob",
42 sha1_to_hex(item->object.sha1));
Nicolas Pitrebd2c39f2005-05-06 17:48:3443 ret = parse_blob_buffer(item, buffer, size);
44 free(buffer);
45 return ret;
Daniel Barkalowa510bfa2005-04-28 14:46:3346}