Skip to content

Commit 83fc4d6

Browse files
rscharfegitster
authored andcommitted
ref-filter: use QSORT_S in ref_array_sort()
Pass the array of sort keys to compare_refs() via the context parameter of qsort_s() instead of using a global variable; that's cleaner and simpler. If ref_array_sort() is to be called from multiple parallel threads then care still needs to be taken that the global variable used_atom is not modified concurrently. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5ebd947 commit 83fc4d6

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

ref-filter.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,8 +1555,7 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, stru
15551555
return (s->reverse) ? -cmp : cmp;
15561556
}
15571557

1558-
static struct ref_sorting *ref_sorting;
1559-
static int compare_refs(const void *a_, const void *b_)
1558+
static int compare_refs(const void *a_, const void *b_, void *ref_sorting)
15601559
{
15611560
struct ref_array_item *a = *((struct ref_array_item **)a_);
15621561
struct ref_array_item *b = *((struct ref_array_item **)b_);
@@ -1572,8 +1571,7 @@ static int compare_refs(const void *a_, const void *b_)
15721571

15731572
void ref_array_sort(struct ref_sorting *sorting, struct ref_array *array)
15741573
{
1575-
ref_sorting = sorting;
1576-
QSORT(array->items, array->nr, compare_refs);
1574+
QSORT_S(array->items, array->nr, compare_refs, sorting);
15771575
}
15781576

15791577
static void append_literal(const char *cp, const char *ep, struct ref_formatting_state *state)

0 commit comments

Comments
 (0)