Skip to content

Commit c127449

Browse files
stefanbellergitster
authored andcommitted
replace-object: eliminate replace objects prepared flag
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>
1 parent 47f351e commit c127449

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

object-store.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ struct raw_object_store {
9999
* Objects that should be substituted by other objects
100100
* (see git-replace(1)).
101101
*/
102-
struct oidmap replace_map;
102+
struct oidmap *replace_map;
103103

104104
/*
105105
* private data

replace_object.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,24 @@ static int register_replace_ref(const char *refname,
2525
oidcpy(&repl_obj->replacement, oid);
2626

2727
/* Register new object */
28-
if (oidmap_put(&the_repository->objects->replace_map, repl_obj))
28+
if (oidmap_put(the_repository->objects->replace_map, repl_obj))
2929
die("duplicate replace ref: %s", refname);
3030

3131
return 0;
3232
}
3333

3434
static void prepare_replace_object(void)
3535
{
36-
static int replace_object_prepared;
37-
38-
if (replace_object_prepared)
36+
if (the_repository->objects->replace_map)
3937
return;
4038

39+
the_repository->objects->replace_map =
40+
xmalloc(sizeof(*the_repository->objects->replace_map));
41+
oidmap_init(the_repository->objects->replace_map, 0);
42+
4143
for_each_replace_ref(register_replace_ref, NULL);
42-
replace_object_prepared = 1;
43-
if (!the_repository->objects->replace_map.map.tablesize)
44+
45+
if (!the_repository->objects->replace_map->map.tablesize)
4446
check_replace_refs = 0;
4547
}
4648

@@ -64,7 +66,7 @@ const struct object_id *do_lookup_replace_object(const struct object_id *oid)
6466
/* Try to recursively replace the object */
6567
while (depth-- > 0) {
6668
struct replace_object *repl_obj =
67-
oidmap_get(&the_repository->objects->replace_map, cur);
69+
oidmap_get(the_repository->objects->replace_map, cur);
6870
if (!repl_obj)
6971
return cur;
7072
cur = &repl_obj->replacement;

0 commit comments

Comments
 (0)