summaryrefslogtreecommitdiff
path: root/sha1-name.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2019-08-20 18:49:12 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-08-20 20:59:59 (GMT)
commit7cfcb16b0ebd8294b2158669e55b79445b48fb31 (patch)
tree2c7f5ffa98348dcda605eebf5fd10cb9d469ad35 /sha1-name.c
parent75b2f01a0f642b39b0f29b6218515df9b5eb798e (diff)
downloadgit-7cfcb16b0ebd8294b2158669e55b79445b48fb31.zip
git-7cfcb16b0ebd8294b2158669e55b79445b48fb31.tar.gz
git-7cfcb16b0ebd8294b2158669e55b79445b48fb31.tar.bz2
sha1-name: make sort_ambiguous_oid_array() thread-safe
Use QSORT_S instead of QSORT, which allows passing the repository pointer to the comparison function without using a static variable. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1-name.c')
-rw-r--r--sha1-name.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/sha1-name.c b/sha1-name.c
index 728e6f1..c99fbb2 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -403,9 +403,9 @@ static int repo_collect_ambiguous(struct repository *r,
return collect_ambiguous(oid, data);
}
-static struct repository *sort_ambiguous_repo;
-static int sort_ambiguous(const void *a, const void *b)
+static int sort_ambiguous(const void *a, const void *b, void *ctx)
{
+ struct repository *sort_ambiguous_repo = ctx;
int a_type = oid_object_info(sort_ambiguous_repo, a, NULL);
int b_type = oid_object_info(sort_ambiguous_repo, b, NULL);
int a_type_sort;
@@ -434,10 +434,7 @@ static int sort_ambiguous(const void *a, const void *b)
static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)
{
- /* mutex will be needed if this code is to be made thread safe */
- sort_ambiguous_repo = r;
- QSORT(a->oid, a->nr, sort_ambiguous);
- sort_ambiguous_repo = NULL;
+ QSORT_S(a->oid, a->nr, sort_ambiguous, r);
}
static enum get_oid_result get_short_oid(struct repository *r,