git/replace-object.h
Stefan Beller c3c36d7de2 replace-object: check_replace_refs is safe in multi repo environment
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>
2018-04-12 11:38:56 +09:00

35 lines
1,019 B
C

#ifndef REPLACE_OBJECT_H
#define REPLACE_OBJECT_H
#include "oidmap.h"
#include "repository.h"
#include "object-store.h"
struct replace_object {
struct oidmap_entry original;
struct object_id replacement;
};
/*
* This internal function is only declared here for the benefit of
* lookup_replace_object(). Please do not call it directly.
*/
extern const struct object_id *do_lookup_replace_object(const struct object_id *oid);
/*
* If object sha1 should be replaced, return the replacement object's
* name (replaced recursively, if necessary). The return value is
* either sha1 or a pointer to a permanently-allocated value. When
* object replacement is suppressed, always return sha1.
*/
static inline const struct object_id *lookup_replace_object(const struct object_id *oid)
{
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);
}
#endif /* REPLACE_OBJECT_H */