Skip to content

Commit d32987b

Browse files
author
Linus Torvalds
committed
Set object type at object creation time, not object parse time.
Otherwise we can have objects without a type, which is not good.
1 parent 4728b86 commit d32987b

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ struct commit *lookup_commit(unsigned char *sha1)
1212
struct commit *ret = malloc(sizeof(struct commit));
1313
memset(ret, 0, sizeof(struct commit));
1414
created_object(sha1, &ret->object);
15+
ret->object.type = commit_type;
1516
return ret;
1617
}
1718
if (obj->parsed && obj->type != commit_type) {
@@ -56,7 +57,6 @@ int parse_commit(struct commit *item)
5657
if (strcmp(type, commit_type))
5758
return error("Object %s not a commit",
5859
sha1_to_hex(item->object.sha1));
59-
item->object.type = commit_type;
6060
get_sha1_hex(bufptr + 5, parent);
6161
item->tree = lookup_tree(parent);
6262
add_ref(&item->object, &item->tree->object);

tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct tree *lookup_tree(unsigned char *sha1)
7777
struct tree *ret = malloc(sizeof(struct tree));
7878
memset(ret, 0, sizeof(struct tree));
7979
created_object(sha1, &ret->object);
80+
ret->object.type = tree_type;
8081
return ret;
8182
}
8283
if (obj->parsed && obj->type != tree_type) {
@@ -96,7 +97,6 @@ int parse_tree(struct tree *item)
9697
if (item->object.parsed)
9798
return 0;
9899
item->object.parsed = 1;
99-
item->object.type = tree_type;
100100
buffer = bufptr = read_sha1_file(item->object.sha1, type, &size);
101101
if (!buffer)
102102
return error("Could not read %s",

0 commit comments

Comments
 (0)