Verify that the object type matches for tree/commit objects even before parsing.
[git.git] / tree.c
diff --git a/tree.c b/tree.c
index 79b9625..3537c11 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -77,9 +77,10 @@ struct tree *lookup_tree(unsigned char *sha1)
                struct tree *ret = malloc(sizeof(struct tree));
                memset(ret, 0, sizeof(struct tree));
                created_object(sha1, &ret->object);
+               ret->object.type = tree_type;
                return ret;
        }
-       if (obj->parsed && obj->type != tree_type) {
+       if (obj->type != tree_type) {
                error("Object %s is a %s, not a tree", 
                      sha1_to_hex(sha1), obj->type);
                return NULL;
@@ -96,7 +97,6 @@ int parse_tree(struct tree *item)
        if (item->object.parsed)
                return 0;
        item->object.parsed = 1;
-       item->object.type = tree_type;
        buffer = bufptr = read_sha1_file(item->object.sha1, type, &size);
        if (!buffer)
                return error("Could not read %s",