Set object type at object creation time, not object parse time.
Otherwise we can have objects without a type, which is not good.
This commit is contained in:
2
commit.c
2
commit.c
@ -12,6 +12,7 @@ struct commit *lookup_commit(unsigned char *sha1)
|
|||||||
struct commit *ret = malloc(sizeof(struct commit));
|
struct commit *ret = malloc(sizeof(struct commit));
|
||||||
memset(ret, 0, sizeof(struct commit));
|
memset(ret, 0, sizeof(struct commit));
|
||||||
created_object(sha1, &ret->object);
|
created_object(sha1, &ret->object);
|
||||||
|
ret->object.type = commit_type;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if (obj->parsed && obj->type != commit_type) {
|
if (obj->parsed && obj->type != commit_type) {
|
||||||
@ -56,7 +57,6 @@ int parse_commit(struct commit *item)
|
|||||||
if (strcmp(type, commit_type))
|
if (strcmp(type, commit_type))
|
||||||
return error("Object %s not a commit",
|
return error("Object %s not a commit",
|
||||||
sha1_to_hex(item->object.sha1));
|
sha1_to_hex(item->object.sha1));
|
||||||
item->object.type = commit_type;
|
|
||||||
get_sha1_hex(bufptr + 5, parent);
|
get_sha1_hex(bufptr + 5, parent);
|
||||||
item->tree = lookup_tree(parent);
|
item->tree = lookup_tree(parent);
|
||||||
add_ref(&item->object, &item->tree->object);
|
add_ref(&item->object, &item->tree->object);
|
||||||
|
2
tree.c
2
tree.c
@ -77,6 +77,7 @@ struct tree *lookup_tree(unsigned char *sha1)
|
|||||||
struct tree *ret = malloc(sizeof(struct tree));
|
struct tree *ret = malloc(sizeof(struct tree));
|
||||||
memset(ret, 0, sizeof(struct tree));
|
memset(ret, 0, sizeof(struct tree));
|
||||||
created_object(sha1, &ret->object);
|
created_object(sha1, &ret->object);
|
||||||
|
ret->object.type = tree_type;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if (obj->parsed && obj->type != tree_type) {
|
if (obj->parsed && obj->type != tree_type) {
|
||||||
@ -96,7 +97,6 @@ int parse_tree(struct tree *item)
|
|||||||
if (item->object.parsed)
|
if (item->object.parsed)
|
||||||
return 0;
|
return 0;
|
||||||
item->object.parsed = 1;
|
item->object.parsed = 1;
|
||||||
item->object.type = tree_type;
|
|
||||||
buffer = bufptr = read_sha1_file(item->object.sha1, type, &size);
|
buffer = bufptr = read_sha1_file(item->object.sha1, type, &size);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
return error("Could not read %s",
|
return error("Could not read %s",
|
||||||
|
Reference in New Issue
Block a user