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>
René Scharfe committed
Aug 20, 2019 at 20:49 UTC
7cfcb16b0ebd8294b2158669e55b79445b48fb31
1 file changed
+3
-6
sha1-name.c
+3
-6
@@ -403,9 +403,9 @@ static int repo_collect_ambiguous(struct repository *r,
403
return collect_ambiguous(oid, data);
404
}
405
406
-static struct repository *sort_ambiguous_repo;
407
-static int sort_ambiguous(const void *a, const void *b)
406
+static int sort_ambiguous(const void *a, const void *b, void *ctx)
407
{
408
+ struct repository *sort_ambiguous_repo = ctx;
409
int a_type = oid_object_info(sort_ambiguous_repo, a, NULL);
410
int b_type = oid_object_info(sort_ambiguous_repo, b, NULL);
411
int a_type_sort;
@@ -434,10 +434,7 @@ static int sort_ambiguous(const void *a, const void *b)
434
435
static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)
436
{
437
- /* mutex will be needed if this code is to be made thread safe */
438
- sort_ambiguous_repo = r;
439
- QSORT(a->oid, a->nr, sort_ambiguous);
440
- sort_ambiguous_repo = NULL;
437
+ QSORT_S(a->oid, a->nr, sort_ambiguous, r);
438
}
439
440
static enum get_oid_result get_short_oid(struct repository *r,