Skip to content

ls: break a tie in the time sort with the name - #14049

Open
luantaraschi wants to merge 1 commit into
uutils:mainfrom
luantaraschi:fix/ls-time-sort-tiebreak
Open

ls: break a tie in the time sort with the name#14049
luantaraschi wants to merge 1 commit into
uutils:mainfrom
luantaraschi:fix/ls-time-sort-tiebreak

Conversation

@luantaraschi

Copy link
Copy Markdown
Contributor

Every sort in sort_entries falls back on the name when its key ties, apart
from the sort by time. Sort::Size, Sort::Version, Sort::Extension and
Sort::Width all end in a .then(...) on the name; Sort::Time was a bare
sort_unstable_by_key on the timestamp.

Entries sharing a timestamp therefore came out in the order the directory was
read in, and since the sort is unstable that order was not guaranteed either.
Four files created at the same mtime, against GNU coreutils 9.7:

GNU before after
ls -t in LC_ALL=C Mike alpha bravo zulu alpha bravo zulu Mike Mike alpha bravo zulu
ls -t in en_US.UTF-8 alpha bravo Mike zulu alpha bravo zulu Mike alpha bravo Mike zulu

alpha bravo zulu Mike is what ls -U prints, so the old output was the raw
directory order.

GNU breaks the tie with the collation rather than with the bytes, which is why
the two locales disagree on where Mike goes. The comparison Sort::Name
already builds is hoisted out of the match so the fallback uses that same one.

Checked against GNU for -t, -tr, -t -u and -t -c in both locales, and
with distinct timestamps to confirm the primary ordering is unchanged.

Copilot AI lite review requested due to automatic review settings August 20, 2026 19:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codspeed-hq

codspeed-hq Bot commented Aug 20, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 4.09%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 2 regressed benchmarks
✅ 355 untouched benchmarks
⏩ 50 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation du_summarize_balanced_tree[(5, 4, 10)] 16.2 ms 16.9 ms -4.21%
Simulation ls_recursive_long_all_balanced_tree[(6, 4, 15)] 289.2 ms 301.2 ms -3.97%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing luantaraschi:fix/ls-time-sort-tiebreak (c7fbfea) with main (df30282)

Open in CodSpeed

Footnotes

  1. 50 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Every other sort in sort_entries falls back on the name when its key
ties. Sorting by time did not, so entries sharing a timestamp came out
in the order the directory was read in, and since the sort is unstable
that order was not guaranteed either.

GNU ls breaks the tie with the collation rather than with the bytes, so
the comparison Sort::Name already builds is hoisted out of the match and
the fallback uses that same one.
@cakebaker
cakebaker force-pushed the fix/ls-time-sort-tiebreak branch from 4c71932 to c7fbfea Compare August 21, 2026 13:56
Copilot AI review requested due to automatic review settings August 21, 2026 13:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/date/resolution (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/cut/cut-huge-range is now passing!
Skip an intermittent issue tests/pr/bounded-memory (was skipped on 'main', now failing)
Skip an intermittent issue tests/tail/tail-n0f (was skipped on 'main', now failing)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants