Skip to content

Git's rename detection requires a stable sort #352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

dscho
Copy link
Member

@dscho dscho commented Sep 24, 2019

With the en/merge-recursive-cleanup patches already having advanced to next, the problem I discovered when rebasing Git for Windows' branch thicket becomes quite relevant now: t3030.35 fails consistently in the MSVC build & test (this part of the Azure Pipeline will be upstreamed later).

The solution: use a stable sort.

Note: this patch series is based on top of en/merge-recursive-cleanup.

Changes since v1:

  • The function was renamed to git_stable_qsort(), as per Junio's suggestion.

@dscho dscho force-pushed the rename-needs-stable-sort branch 3 times, most recently from 77e30d0 to a95cdf1 Compare September 24, 2019 21:30
@dscho dscho changed the title WIP Rename detection requires a stable sort Git's rename detection requires a stable sort Sep 25, 2019
@dscho
Copy link
Member Author

dscho commented Sep 25, 2019

/submit

@gitgitgadget
Copy link

gitgitgadget bot commented Sep 25, 2019

Submitted as [email protected]

dscho added a commit to git-for-windows/git that referenced this pull request Sep 28, 2019
@gitgitgadget
Copy link

gitgitgadget bot commented Sep 30, 2019

This branch is now known as js/diff-rename-force-stable-sort.

@gitgitgadget
Copy link

gitgitgadget bot commented Sep 30, 2019

This patch series was integrated into pu via git@01c240c.

@gitgitgadget gitgitgadget bot added the pu label Sep 30, 2019
The `qsort()` function is not guaranteed to be stable, i.e. it does not
promise to maintain the order of items it is told to consider equal. In
contrast, the `git_sort()` function we carry in `compat/qsort.c` _is_
stable, by virtue of implementing a merge sort algorithm.

In preparation for using a stable sort in Git's rename detection, move
the stable sort into `libgit.a` so that it is compiled in
unconditionally, and rename it to `git_stable_qsort()`.

Note: this also makes the hack obsolete that was introduced in
fe21c6b (mingw: reencode environment variables on the fly (UTF-16
<-> UTF-8), 2018-10-30), where we included `compat/qsort.c` directly in
`compat/mingw.c` to use the stable sort.

Signed-off-by: Johannes Schindelin <[email protected]>
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_stable_qsort()` to avoid this
inconsistency.

Signed-off-by: Johannes Schindelin <[email protected]>
@dscho dscho force-pushed the rename-needs-stable-sort branch from a95cdf1 to 4421404 Compare September 30, 2019 11:29
@dscho
Copy link
Member Author

dscho commented Sep 30, 2019

/submit

@gitgitgadget
Copy link

gitgitgadget bot commented Sep 30, 2019

Submitted as [email protected]

git-for-windows-ci pushed a commit to git-for-windows/git that referenced this pull request Sep 30, 2019
@gitgitgadget

This comment has been minimized.

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 2, 2019

This patch series was integrated into pu via git@aaf27a8.

git-for-windows-ci pushed a commit to git-for-windows/git that referenced this pull request Oct 3, 2019
@gitgitgadget
Copy link

gitgitgadget bot commented Oct 3, 2019

This patch series was integrated into pu via git@016da89.

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 4, 2019

This patch series was integrated into pu via git@9c79a23.

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 4, 2019

This patch series was integrated into pu via git@b699e49.

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 4, 2019

This patch series was integrated into next via git@e02d882.

@gitgitgadget gitgitgadget bot added the next label Oct 4, 2019
@gitgitgadget
Copy link

gitgitgadget bot commented Oct 6, 2019

This patch series was integrated into pu via git@b8203e1.

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 7, 2019

This patch series was integrated into pu via git@fa94da2.

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 8, 2019

This patch series was integrated into pu via git@d90b93d.

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 9, 2019

This patch series was integrated into pu via git@7be6d77.

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 9, 2019

This patch series was integrated into pu via git@772cad0.

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 9, 2019

This patch series was integrated into next via git@772cad0.

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 9, 2019

This patch series was integrated into master via git@772cad0.

@gitgitgadget gitgitgadget bot added the master label Oct 9, 2019
@gitgitgadget gitgitgadget bot closed this Oct 9, 2019
@gitgitgadget
Copy link

gitgitgadget bot commented Oct 9, 2019

Closed via 772cad0.

@dscho dscho deleted the rename-needs-stable-sort branch October 9, 2019 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant