diff options
Diffstat (limited to 'replace-object.c')
| -rw-r--r-- | replace-object.c | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/replace-object.c b/replace-object.c index 320be2522d..59252d565e 100644 --- a/replace-object.c +++ b/replace-object.c @@ -1,23 +1,26 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "gettext.h" +#include "hex.h" #include "oidmap.h" -#include "object-store.h" +#include "object-store-ll.h" #include "replace-object.h" #include "refs.h" #include "repository.h" #include "commit.h" -static int register_replace_ref(struct repository *r, - const char *refname, +static int register_replace_ref(const char *refname, const struct object_id *oid, int flag UNUSED, - void *cb_data UNUSED) + void *cb_data) { + struct repository *r = cb_data; + /* Get sha1 from refname */ const char *slash = strrchr(refname, '/'); const char *hash = slash ? slash + 1 : refname; struct replace_object *repl_obj = xmalloc(sizeof(*repl_obj)); - if (get_oid_hex(hash, &repl_obj->original.oid)) { + if (get_oid_hex_algop(hash, &repl_obj->original.oid, r->hash_algo)) { free(repl_obj); warning(_("bad replace ref name: %s"), refname); return 0; @@ -48,7 +51,8 @@ void prepare_replace_object(struct repository *r) xmalloc(sizeof(*r->objects->replace_map)); oidmap_init(r->objects->replace_map, 0); - for_each_replace_ref(r, register_replace_ref, NULL); + refs_for_each_replace_ref(get_main_ref_store(r), + register_replace_ref, r); r->objects->replace_map_initialized = 1; pthread_mutex_unlock(&r->objects->replace_mutex); @@ -62,7 +66,7 @@ void prepare_replace_object(struct repository *r) * replacement object's name (replaced recursively, if necessary). * The return value is either oid or a pointer to a * permanently-allocated value. This function always respects replace - * references, regardless of the value of read_replace_refs. + * references, regardless of the value of r->settings.read_replace_refs. */ const struct object_id *do_lookup_replace_object(struct repository *r, const struct object_id *oid) @@ -82,3 +86,29 @@ const struct object_id *do_lookup_replace_object(struct repository *r, } die(_("replace depth too high for object %s"), oid_to_hex(oid)); } + +/* + * This indicator determines whether replace references should be + * respected process-wide, regardless of which repository is being + * using at the time. + */ +static int read_replace_refs = 1; + +void disable_replace_refs(void) +{ + read_replace_refs = 0; +} + +int replace_refs_enabled(struct repository *r) +{ + if (!read_replace_refs) + return 0; + + if (r->gitdir) { + prepare_repo_settings(r); + return r->settings.read_replace_refs; + } + + /* repository has no objects or refs. */ + return 0; +} |
