]> git.ipfire.org Git - thirdparty/git.git/commitdiff
replace-object: eliminate replace objects prepared flag
authorStefan Beller <sbeller@google.com>
Thu, 12 Apr 2018 00:21:07 +0000 (17:21 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 12 Apr 2018 02:38:56 +0000 (11:38 +0900)
Make the oidmap a pointer.

That way we eliminate the need for the global boolean
variable 'replace_object_prepared' as we can put this information
into the pointer being NULL or not.

Another advantage of this is that we would more quickly catch
code that tries to access replace-map without initializing it.

This also allows the '#include "oidmap.h"' introduced in a previous
patch to be replaced by the forward declaration of 'struct oidmap;'.
Keeping the type opaque discourages circumventing accessor functions;
not dragging in other headers avoids some compile time overhead.

One disadvantage of this is change is performance as we need to
pay the overhead for a malloc. The alternative of moving the
global variable into the object store is less modular code.

Helped-by: René Scharfe <l.s.r@web.de>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
object-store.h
replace_object.c

index c04b4c95ebd58adb651221798a7ae5eaa3f49eff..1ff862c7f93fbe793af21acc963ea0f7ea8f1623 100644 (file)
@@ -99,7 +99,7 @@ struct raw_object_store {
         * Objects that should be substituted by other objects
         * (see git-replace(1)).
         */
-       struct oidmap replace_map;
+       struct oidmap *replace_map;
 
        /*
         * private data
index afbdf2df25f608e956ed9b4f5340dc95c1788291..953fa9cc40c1831dc52547a9d30a369560b6a1d7 100644 (file)
@@ -25,7 +25,7 @@ static int register_replace_ref(const char *refname,
        oidcpy(&repl_obj->replacement, oid);
 
        /* Register new object */
-       if (oidmap_put(&the_repository->objects->replace_map, repl_obj))
+       if (oidmap_put(the_repository->objects->replace_map, repl_obj))
                die("duplicate replace ref: %s", refname);
 
        return 0;
@@ -33,14 +33,16 @@ static int register_replace_ref(const char *refname,
 
 static void prepare_replace_object(void)
 {
-       static int replace_object_prepared;
-
-       if (replace_object_prepared)
+       if (the_repository->objects->replace_map)
                return;
 
+       the_repository->objects->replace_map =
+               xmalloc(sizeof(*the_repository->objects->replace_map));
+       oidmap_init(the_repository->objects->replace_map, 0);
+
        for_each_replace_ref(register_replace_ref, NULL);
-       replace_object_prepared = 1;
-       if (!the_repository->objects->replace_map.map.tablesize)
+
+       if (!the_repository->objects->replace_map->map.tablesize)
                check_replace_refs = 0;
 }
 
@@ -64,7 +66,7 @@ const struct object_id *do_lookup_replace_object(const struct object_id *oid)
        /* Try to recursively replace the object */
        while (depth-- > 0) {
                struct replace_object *repl_obj =
-                       oidmap_get(&the_repository->objects->replace_map, cur);
+                       oidmap_get(the_repository->objects->replace_map, cur);
                if (!repl_obj)
                        return cur;
                cur = &repl_obj->replacement;