summaryrefslogtreecommitdiff
path: root/ref-filter.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-01-31 21:15:00 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-01-31 21:15:00 (GMT)
commit6ad8b8e98faa5a301a98a2997da162dea060672e (patch)
tree99ca685d15df287c1f686c033157756d439c119c /ref-filter.c
parent4e170adc8ad654bddb9421a4bf51bb4802656262 (diff)
parent83fc4d64fec779d73b18494461613ef911236daf (diff)
downloadgit-6ad8b8e98faa5a301a98a2997da162dea060672e.zip
git-6ad8b8e98faa5a301a98a2997da162dea060672e.tar.gz
git-6ad8b8e98faa5a301a98a2997da162dea060672e.tar.bz2
Merge branch 'rs/qsort-s'
A few codepaths had to rely on a global variable when sorting elements of an array because sort(3) API does not allow extra data to be passed to the comparison function. Use qsort_s() when natively available, and a fallback implementation of it when not, to eliminate the need, which is a prerequisite for making the codepath reentrant. * rs/qsort-s: ref-filter: use QSORT_S in ref_array_sort() string-list: use QSORT_S in string_list_sort() perf: add basic sort performance test add QSORT_S compat: add qsort_s()
Diffstat (limited to 'ref-filter.c')
-rw-r--r--ref-filter.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/ref-filter.c b/ref-filter.c
index 5f4b087..3820b21 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1594,8 +1594,7 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, stru
return (s->reverse) ? -cmp : cmp;
}
-static struct ref_sorting *ref_sorting;
-static int compare_refs(const void *a_, const void *b_)
+static int compare_refs(const void *a_, const void *b_, void *ref_sorting)
{
struct ref_array_item *a = *((struct ref_array_item **)a_);
struct ref_array_item *b = *((struct ref_array_item **)b_);
@@ -1611,8 +1610,7 @@ static int compare_refs(const void *a_, const void *b_)
void ref_array_sort(struct ref_sorting *sorting, struct ref_array *array)
{
- ref_sorting = sorting;
- QSORT(array->items, array->nr, compare_refs);
+ QSORT_S(array->items, array->nr, compare_refs, sorting);
}
static void append_literal(const char *cp, const char *ep, struct ref_formatting_state *state)