Don't add references to objects we couldn't find.
[alt-git.git] / blob.c
blobf79f5abd00ba2eb0b25cf244e0b21b559b86e1d7
1 #include "blob.h"
2 #include "cache.h"
3 #include <stdlib.h>
5 const char *blob_type = "blob";
7 struct blob *lookup_blob(unsigned char *sha1)
9 struct object *obj = lookup_object(sha1);
10 if (!obj) {
11 struct blob *ret = malloc(sizeof(struct blob));
12 memset(ret, 0, sizeof(struct blob));
13 created_object(sha1, &ret->object);
14 ret->object.type = blob_type;
15 return ret;
17 if (obj->parsed && obj->type != blob_type) {
18 error("Object %s is a %s, not a blob",
19 sha1_to_hex(sha1), obj->type);
20 return NULL;
22 return (struct blob *) obj;