replace-object: move replace_map to object store

The relationship between an object X and another object Y that replaces the object X is defined only within the scope of a single repository. The exception in reachability rule around these replacement objects is also local to a repository (i.e. if traversal from refs reaches X, then both X and Y are reachable and need to be kept from gc). Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Apr 11, 2018 at 17:21 UTC d88f9fdf8b2ccf65993bb977094ab9b2249635ee
3 files changed +24 -10
object-store.h
+8
@@ -1,6 +1,8 @@
1 #ifndef OBJECT_STORE_H
2 #define OBJECT_STORE_H
3
4 +#include "oidmap.h"
5 +
6 struct alternate_object_database {
7 struct alternate_object_database *next;
8
@@ -93,6 +95,12 @@ struct raw_object_store {
95 struct alternate_object_database *alt_odb_list;
96 struct alternate_object_database **alt_odb_tail;
97
98 + /*
99 + * Objects that should be substituted by other objects
100 + * (see git-replace(1)).
101 + */
102 + struct oidmap replace_map;
103 +
104 /*
105 * private data
106 *
replace-object.h new
+9
@@ -0,0 +1,9 @@
1 +#ifndef REPLACE_OBJECT_H
2 +#define REPLACE_OBJECT_H
3 +
4 +struct replace_object {
5 + struct oidmap_entry original;
6 + struct object_id replacement;
7 +};
8 +
9 +#endif /* REPLACE_OBJECT_H */
replace_object.c
+7 -10
@@ -1,15 +1,11 @@
1 #include "cache.h"
2 #include "oidmap.h"
3 +#include "object-store.h"
4 +#include "replace-object.h"
5 #include "refs.h"
6 +#include "repository.h"
7 #include "commit.h"
8
6 -struct replace_object {
7 - struct oidmap_entry original;
8 - struct object_id replacement;
9 -};
10 -
11 -static struct oidmap replace_map = OIDMAP_INIT;
12 -
9 static int register_replace_ref(const char *refname,
10 const struct object_id *oid,
11 int flag, void *cb_data)
@@ -29,7 +25,7 @@ static int register_replace_ref(const char *refname,
25 oidcpy(&repl_obj->replacement, oid);
26
27 /* Register new object */
32 - if (oidmap_put(&replace_map, repl_obj))
28 + if (oidmap_put(&the_repository->objects->replace_map, repl_obj))
29 die("duplicate replace ref: %s", refname);
30
31 return 0;
@@ -44,7 +40,7 @@ static void prepare_replace_object(void)
40
41 for_each_replace_ref(register_replace_ref, NULL);
42 replace_object_prepared = 1;
47 - if (!replace_map.map.tablesize)
43 + if (!the_repository->objects->replace_map.map.tablesize)
44 check_replace_refs = 0;
45 }
46
@@ -67,7 +63,8 @@ const struct object_id *do_lookup_replace_object(const struct object_id *oid)
63
64 /* Try to recursively replace the object */
65 while (depth-- > 0) {
70 - struct replace_object *repl_obj = oidmap_get(&replace_map, cur);
66 + struct replace_object *repl_obj =
67 + oidmap_get(&the_repository->objects->replace_map, cur);
68 if (!repl_obj)
69 return cur;
70 cur = &repl_obj->replacement;