aboutsummaryrefslogtreecommitdiff
path: root/replace-object.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-02-14 12:54:20 -0800
committerJunio C Hamano <gitster@pobox.com>2020-02-14 12:54:20 -0800
commit56ceb64eb0377acb2884226d4fb7d7c3f4032354 (patch)
tree3ab8775533954b285d1abf67d2ea0f53c7149154 /replace-object.c
parent0da63da7942ce810126cd54d9f72a46f3d616895 (diff)
parentf1928f04b2510c522c25d482e6ab4a17077add9a (diff)
downloadgit-56ceb64eb0377acb2884226d4fb7d7c3f4032354.tar.xz
Merge branch 'mt/threaded-grep-in-object-store'
Traditionally, we avoided threaded grep while searching in objects (as opposed to files in the working tree) as accesses to the object layer is not thread-safe. This limitation is getting lifted. * mt/threaded-grep-in-object-store: grep: use no. of cores as the default no. of threads grep: move driver pre-load out of critical section grep: re-enable threads in non-worktree case grep: protect packed_git [re-]initialization grep: allow submodule functions to run in parallel submodule-config: add skip_if_read option to repo_read_gitmodules() grep: replace grep_read_mutex by internal obj read lock object-store: allow threaded access to object reading replace-object: make replace operations thread-safe grep: fix racy calls in grep_objects() grep: fix race conditions at grep_submodule() grep: fix race conditions on userdiff calls
Diffstat (limited to 'replace-object.c')
-rw-r--r--replace-object.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/replace-object.c b/replace-object.c
index e295e87943..7bd9aba6ee 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -34,14 +34,23 @@ static int register_replace_ref(struct repository *r,
void prepare_replace_object(struct repository *r)
{
- if (r->objects->replace_map)
+ if (r->objects->replace_map_initialized)
return;
+ pthread_mutex_lock(&r->objects->replace_mutex);
+ if (r->objects->replace_map_initialized) {
+ pthread_mutex_unlock(&r->objects->replace_mutex);
+ return;
+ }
+
r->objects->replace_map =
xmalloc(sizeof(*r->objects->replace_map));
oidmap_init(r->objects->replace_map, 0);
for_each_replace_ref(r, register_replace_ref, NULL);
+ r->objects->replace_map_initialized = 1;
+
+ pthread_mutex_unlock(&r->objects->replace_mutex);
}
/* We allow "recursive" replacement. Only within reason, though */