Skip to content

Commit a95cdf1

Browse files
committed
diffcore_rename(): use a stable sort
During Git's rename detection, the file names are sorted. At the moment, this job is performed by `qsort()`. As that function is not guaranteed to implement a stable sort algorithm, this can lead to inconsistent and/or surprising behavior: a rename might be detected differently depending on the platform where Git was run. The `qsort()` in MS Visual C's runtime does _not_ implement a stable sort algorithm, and it even leads to an inconsistency leading to a test failure in t3030.35 "merge-recursive remembers the names of all base trees": a different code path than on Linux is taken in the rename detection of an ambiguous rename between either `e` to `a` or `a~Temporary merge branch 2_0` to `a` during a recursive merge, unexpectedly resulting in a clean merge. Let's use the stable sort provided by `git_sort()` to avoid this inconsistency. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 1202809 commit a95cdf1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

diffcore-rename.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ void diffcore_rename(struct diff_options *options)
585585
stop_progress(&progress);
586586

587587
/* cost matrix sorted by most to least similar pair */
588-
QSORT(mx, dst_cnt * NUM_CANDIDATE_PER_DST, score_compare);
588+
QSORT_STABLE(mx, dst_cnt * NUM_CANDIDATE_PER_DST, score_compare);
589589

590590
rename_count += find_renames(mx, dst_cnt, minimum_score, 0);
591591
if (detect_rename == DIFF_DETECT_COPY)

0 commit comments

Comments
 (0)