sha1-file.c: mark more strings for translation
[gitweb.git] / object.c
index 91edc30770c60c9e64d9910460afc694027db717..477e686da7dc783a5341888bb987a42226d75795 100644 (file)
--- a/object.c
+++ b/object.c
@@ -5,6 +5,7 @@
 #include "tree.h"
 #include "commit.h"
 #include "tag.h"
+#include "alloc.h"
 #include "object-store.h"
 #include "packfile.h"
 
@@ -48,7 +49,7 @@ int type_from_string_gently(const char *str, ssize_t len, int gentle)
        if (gentle)
                return -1;
 
-       die("invalid object type \"%s\"", str);
+       die(_("invalid object type \"%s\""), str);
 }
 
 /*
@@ -116,30 +117,30 @@ struct object *lookup_object(const unsigned char *sha1)
  * power of 2 (but at least 32).  Copy the existing values to the new
  * hash map.
  */
-#define grow_object_hash(r) grow_object_hash_##r()
-static void grow_object_hash_the_repository(void)
+static void grow_object_hash(struct repository *r)
 {
        int i;
        /*
         * Note that this size must always be power-of-2 to match hash_obj
         * above.
         */
-       int new_hash_size = the_repository->parsed_objects->obj_hash_size < 32 ? 32 : 2 * the_repository->parsed_objects->obj_hash_size;
+       int new_hash_size = r->parsed_objects->obj_hash_size < 32 ? 32 : 2 * r->parsed_objects->obj_hash_size;
        struct object **new_hash;
 
        new_hash = xcalloc(new_hash_size, sizeof(struct object *));
-       for (i = 0; i < the_repository->parsed_objects->obj_hash_size; i++) {
-               struct object *obj = the_repository->parsed_objects->obj_hash[i];
+       for (i = 0; i < r->parsed_objects->obj_hash_size; i++) {
+               struct object *obj = r->parsed_objects->obj_hash[i];
+
                if (!obj)
                        continue;
                insert_obj_hash(obj, new_hash, new_hash_size);
        }
-       free(the_repository->parsed_objects->obj_hash);
-       the_repository->parsed_objects->obj_hash = new_hash;
-       the_repository->parsed_objects->obj_hash_size = new_hash_size;
+       free(r->parsed_objects->obj_hash);
+       r->parsed_objects->obj_hash = new_hash;
+       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 +148,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;
 }
 
@@ -162,13 +163,13 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet)
                return obj;
        else if (obj->type == OBJ_NONE) {
                if (type == OBJ_COMMIT)
-                       ((struct commit *)obj)->index = alloc_commit_index();
+                       ((struct commit *)obj)->index = alloc_commit_index(the_repository);
                obj->type = type;
                return obj;
        }
        else {
                if (!quiet)
-                       error("object %s is a %s, not a %s",
+                       error(_("object %s is a %s, not a %s"),
                              oid_to_hex(&obj->oid),
                              type_name(obj->type), type_name(type));
                return NULL;
@@ -180,7 +181,7 @@ struct object *lookup_unknown_object(const unsigned char *sha1)
        struct object *obj = lookup_object(sha1);
        if (!obj)
                obj = create_object(the_repository, sha1,
-                                   alloc_object_node());
+                                   alloc_object_node(the_repository));
        return obj;
 }
 
@@ -212,7 +213,7 @@ struct object *parse_object_buffer(const struct object_id *oid, enum object_type
        } else if (type == OBJ_COMMIT) {
                struct commit *commit = lookup_commit(oid);
                if (commit) {
-                       if (parse_commit_buffer(commit, buffer, size))
+                       if (parse_commit_buffer(commit, buffer, size, 1))
                                return NULL;
                        if (!get_cached_commit_buffer(commit, NULL)) {
                                set_commit_buffer(commit, buffer, size);
@@ -228,7 +229,7 @@ struct object *parse_object_buffer(const struct object_id *oid, enum object_type
                        obj = &tag->object;
                }
        } else {
-               warning("object %s has unknown type id %d", oid_to_hex(oid), type);
+               warning(_("object %s has unknown type id %d"), oid_to_hex(oid), type);
                obj = NULL;
        }
        return obj;
@@ -261,7 +262,7 @@ struct object *parse_object(const struct object_id *oid)
            (!obj && has_object_file(oid) &&
             oid_object_info(the_repository, oid, NULL) == OBJ_BLOB)) {
                if (check_object_signature(repl, NULL, 0, NULL) < 0) {
-                       error("sha1 mismatch %s", oid_to_hex(oid));
+                       error(_("sha1 mismatch %s"), oid_to_hex(oid));
                        return NULL;
                }
                parse_blob_buffer(lookup_blob(oid), NULL, 0);
@@ -272,7 +273,7 @@ struct object *parse_object(const struct object_id *oid)
        if (buffer) {
                if (check_object_signature(repl, buffer, size, type_name(type)) < 0) {
                        free(buffer);
-                       error("sha1 mismatch %s", oid_to_hex(repl));
+                       error(_("sha1 mismatch %s"), oid_to_hex(repl));
                        return NULL;
                }
 
@@ -455,6 +456,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;
 }
 
@@ -490,6 +498,9 @@ void raw_object_store_clear(struct raw_object_store *o)
        FREE_AND_NULL(o->objectdir);
        FREE_AND_NULL(o->alternate_db);
 
+       oidmap_free(o->replace_map, 1);
+       FREE_AND_NULL(o->replace_map);
+
        free_alt_odbs(o);
        o->alt_odb_tail = NULL;
 
@@ -501,9 +512,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);
 }