path: root/git-compat-util.h
diff options
authorJunio C Hamano <>2019-10-09 05:00:59 (GMT)
committerJunio C Hamano <>2019-10-09 05:00:59 (GMT)
commit772cad0afb834b9af8ee56511dc3df4d6e2f011d (patch)
treebf4f9f9be0c01cfb4b4adb41dfda0ccb3fc1ba99 /git-compat-util.h
parent424663d9c822454cc605c5bab22afdc8475de031 (diff)
parent2049b8dc65e7371c56452cfda5234182d58b704e (diff)
Merge branch 'js/diff-rename-force-stable-sort'
The rename detection logic sorts a list of rename source candidates by similarity to pick the best candidate, which means that a tie between sources with the same similarity is broken by the original location in the original candidate list (which is sorted by path). Force the sorting by similarity done with a stable sort, which is not promised by system supplied qsort(3), to ensure consistent results across platforms. * js/diff-rename-force-stable-sort: diffcore_rename(): use a stable sort Move git_sort(), a stable sort, into into libgit.a
Diffstat (limited to 'git-compat-util.h')
1 files changed, 6 insertions, 3 deletions
diff --git a/git-compat-util.h b/git-compat-util.h
index d2e884e..a8b5854 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -1092,10 +1092,10 @@ static inline int strtol_i(char const *s, int base, int *result)
return 0;
+void git_stable_qsort(void *base, size_t nmemb, size_t size,
+ int(*compar)(const void *, const void *));
-void git_qsort(void *base, size_t nmemb, size_t size,
- int(*compar)(const void *, const void *));
-#define qsort git_qsort
+#define qsort git_stable_qsort
#define QSORT(base, n, compar) sane_qsort((base), (n), sizeof(*(base)), compar)
@@ -1106,6 +1106,9 @@ static inline void sane_qsort(void *base, size_t nmemb, size_t size,
qsort(base, nmemb, size, compar);
+#define STABLE_QSORT(base, n, compar) \
+ git_stable_qsort((base), (n), sizeof(*(base)), compar)
int git_qsort_s(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *, void *), void *ctx);