]> asedeno.scripts.mit.edu Git - git.git/blobdiff - object.c
Use proper object allocators for unknown object nodes too
[git.git] / object.c
index 5b468893421794c50741ce9085c12bc41fb1985f..153ebac66d86fb49df449edc4d92c9db4428f44a 100644 (file)
--- a/object.c
+++ b/object.c
@@ -120,22 +120,13 @@ void created_object(const unsigned char *sha1, struct object *obj)
        nr_objs++;
 }
 
-union any_object {
-       struct object object;
-       struct commit commit;
-       struct tree tree;
-       struct blob blob;
-       struct tag tag;
-};
-
 struct object *lookup_unknown_object(const unsigned char *sha1)
 {
        struct object *obj = lookup_object(sha1);
        if (!obj) {
-               union any_object *ret = xcalloc(1, sizeof(*ret));
-               created_object(sha1, &ret->object);
-               ret->object.type = OBJ_NONE;
-               return &ret->object;
+               obj = alloc_object_node();
+               created_object(sha1, obj);
+               obj->type = OBJ_NONE;
        }
        return obj;
 }
@@ -184,8 +175,10 @@ struct object *parse_object(const unsigned char *sha1)
 
        if (buffer) {
                struct object *obj;
-               if (check_sha1_signature(sha1, buffer, size, typename(type)) < 0)
-                       printf("sha1 mismatch %s\n", sha1_to_hex(sha1));
+               if (check_sha1_signature(sha1, buffer, size, typename(type)) < 0) {
+                       error("sha1 mismatch %s\n", sha1_to_hex(sha1));
+                       return NULL;
+               }
 
                obj = parse_object_buffer(sha1, type, size, buffer, &eaten);
                if (!eaten)