shallow: add repository argument to register_shallow
[gitweb.git] / object.c
index 0fcd6f6df42d73934c2fdeaabafd06c18bbbbcf9..0116ed6529a9453c62f97a16f63434e51de24297 100644 (file)
--- a/object.c
+++ b/object.c
@@ -1,10 +1,12 @@
 #include "cache.h"
 #include "object.h"
 #include "replace-object.h"
+#include "object-store.h"
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
 #include "tag.h"
+#include "alloc.h"
 #include "object-store.h"
 #include "packfile.h"
 
@@ -139,7 +141,7 @@ static void grow_object_hash(struct repository *r)
        r->parsed_objects->obj_hash_size = new_hash_size;
 }
 
-void *create_object_the_repository(const unsigned char *sha1, void *o)
+void *create_object(struct repository *r, const unsigned char *sha1, void *o)
 {
        struct object *obj = o;
 
@@ -147,12 +149,12 @@ void *create_object_the_repository(const unsigned char *sha1, void *o)
        obj->flags = 0;
        hashcpy(obj->oid.hash, sha1);
 
-       if (the_repository->parsed_objects->obj_hash_size - 1 <= the_repository->parsed_objects->nr_objs * 2)
-               grow_object_hash(the_repository);
+       if (r->parsed_objects->obj_hash_size - 1 <= r->parsed_objects->nr_objs * 2)
+               grow_object_hash(r);
 
-       insert_obj_hash(obj, the_repository->parsed_objects->obj_hash,
-                       the_repository->parsed_objects->obj_hash_size);
-       the_repository->parsed_objects->nr_objs++;
+       insert_obj_hash(obj, r->parsed_objects->obj_hash,
+                       r->parsed_objects->obj_hash_size);
+       r->parsed_objects->nr_objs++;
        return obj;
 }
 
@@ -455,6 +457,13 @@ struct parsed_object_pool *parsed_object_pool_new(void)
 {
        struct parsed_object_pool *o = xmalloc(sizeof(*o));
        memset(o, 0, sizeof(*o));
+
+       o->blob_state = allocate_alloc_state();
+       o->tree_state = allocate_alloc_state();
+       o->commit_state = allocate_alloc_state();
+       o->tag_state = allocate_alloc_state();
+       o->object_state = allocate_alloc_state();
+
        return o;
 }
 
@@ -501,9 +510,39 @@ void raw_object_store_clear(struct raw_object_store *o)
 void parsed_object_pool_clear(struct parsed_object_pool *o)
 {
        /*
-        * TOOD free objects in o->obj_hash.
-        *
         * As objects are allocated in slabs (see alloc.c), we do
         * not need to free each object, but each slab instead.
+        *
+        * Before doing so, we need to free any additional memory
+        * the objects may hold.
         */
+       unsigned i;
+
+       for (i = 0; i < o->obj_hash_size; i++) {
+               struct object *obj = o->obj_hash[i];
+
+               if (!obj)
+                       continue;
+
+               if (obj->type == OBJ_TREE)
+                       free_tree_buffer((struct tree*)obj);
+               else if (obj->type == OBJ_COMMIT)
+                       release_commit_memory((struct commit*)obj);
+               else if (obj->type == OBJ_TAG)
+                       release_tag_memory((struct tag*)obj);
+       }
+
+       FREE_AND_NULL(o->obj_hash);
+       o->obj_hash_size = 0;
+
+       clear_alloc_state(o->blob_state);
+       clear_alloc_state(o->tree_state);
+       clear_alloc_state(o->commit_state);
+       clear_alloc_state(o->tag_state);
+       clear_alloc_state(o->object_state);
+       FREE_AND_NULL(o->blob_state);
+       FREE_AND_NULL(o->tree_state);
+       FREE_AND_NULL(o->commit_state);
+       FREE_AND_NULL(o->tag_state);
+       FREE_AND_NULL(o->object_state);
 }