Skip to content

Commit c3c36d7

Browse files
stefanbellergitster
authored andcommitted
replace-object: check_replace_refs is safe in multi repo environment
In e1111ce (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>
1 parent c127449 commit c3c36d7

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

environment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const char *editor_program;
5050
const char *askpass_program;
5151
const char *excludes_file;
5252
enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
53-
int check_replace_refs = 1;
53+
int check_replace_refs = 1; /* NEEDSWORK: rename to read_replace_refs */
5454
char *git_replace_ref_base;
5555
enum eol core_eol = EOL_UNSET;
5656
int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;

replace-object.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "oidmap.h"
55
#include "repository.h"
6+
#include "object-store.h"
67

78
struct replace_object {
89
struct oidmap_entry original;
@@ -23,7 +24,9 @@ extern const struct object_id *do_lookup_replace_object(const struct object_id *
2324
*/
2425
static inline const struct object_id *lookup_replace_object(const struct object_id *oid)
2526
{
26-
if (!check_replace_refs)
27+
if (!check_replace_refs ||
28+
(the_repository->objects->replace_map &&
29+
the_repository->objects->replace_map->map.tablesize == 0))
2730
return oid;
2831
return do_lookup_replace_object(oid);
2932
}

replace_object.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ static void prepare_replace_object(void)
4141
oidmap_init(the_repository->objects->replace_map, 0);
4242

4343
for_each_replace_ref(register_replace_ref, NULL);
44-
45-
if (!the_repository->objects->replace_map->map.tablesize)
46-
check_replace_refs = 0;
4744
}
4845

4946
/* We allow "recursive" replacement. Only within reason, though */

0 commit comments

Comments
 (0)