replace-object: check_replace_refs is safe in multi repo environment
authorStefan Beller <sbeller@google.com>
Thu, 12 Apr 2018 00:21:08 +0000 (17:21 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 12 Apr 2018 02:38:56 +0000 (11:38 +0900)
In e1111cef23 (inline lookup_replace_object() calls, 2011-05-15) a shortcut
for checking the object replacement was added by setting check_replace_refs
to 0 once the replacements were evaluated to not exist. This works fine in
with the assumption of only one repository in existence.

The assumption won't hold true any more when we work on multiple instances
of a repository structs (e.g. one struct per submodule), as the first
repository to be inspected may have no replacements and would set the
global variable. Other repositories would then completely omit their
evaluation of replacements.

This reverts back the meaning of the flag `check_replace_refs` of
"Do we need to check with the lookup table?" to "Do we need to read
the replacement definition?", adding the bypassing logic to
lookup_replace_object after the replacement definition was read.
As with the original patch, delay the renaming of the global variable

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
environment.c
replace-object.h
replace_object.c
index 39b3d906c89048cd094f352fa2ea81d873deb31a..b991fc0a87ce17b51a248a980cef34251fc032f6 100644 (file)
@@ -50,7 +50,7 @@ const char *editor_program;
 const char *askpass_program;
 const char *excludes_file;
 enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
-int check_replace_refs = 1;
+int check_replace_refs = 1; /* NEEDSWORK: rename to read_replace_refs */
 char *git_replace_ref_base;
 enum eol core_eol = EOL_UNSET;
 int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
index 15315311fb892e24129162cef0f61eddfc6fff78..dbc51265ecff251f222161fb085ab66e256352d8 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "oidmap.h"
 #include "repository.h"
+#include "object-store.h"
 
 struct replace_object {
        struct oidmap_entry original;
@@ -23,7 +24,9 @@ extern const struct object_id *do_lookup_replace_object(const struct object_id *
  */
 static inline const struct object_id *lookup_replace_object(const struct object_id *oid)
 {
-       if (!check_replace_refs)
+       if (!check_replace_refs ||
+           (the_repository->objects->replace_map &&
+            the_repository->objects->replace_map->map.tablesize == 0))
                return oid;
        return do_lookup_replace_object(oid);
 }
index 953fa9cc40c1831dc52547a9d30a369560b6a1d7..b2405f602745b55673ea2e114c3489310fa0d823 100644 (file)
@@ -41,9 +41,6 @@ static void prepare_replace_object(void)
        oidmap_init(the_repository->objects->replace_map, 0);
 
        for_each_replace_ref(register_replace_ref, NULL);
-
-       if (!the_repository->objects->replace_map->map.tablesize)
-               check_replace_refs = 0;
 }
 
 /* We allow "recursive" replacement. Only within reason, though */