ref:5b5b235ba9aad7a1c8956550d92b1278a2157da0

fix: sort_by_time uses walk order as tiebreaker for same-second commits

When multiple commits share the same timestamp (common in rebases, tests, and rapid-fire commits), the stable sort preserving BFS accumulation order caused oldest-first ordering. Now reverse the accumulator before sorting and use walk index as a secondary sort key, ensuring commits closer to HEAD appear first when timestamps are equal. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
SHA: 5b5b235ba9aad7a1c8956550d92b1278a2157da0
Author: Cole Christensen <cole.christensen@macmillan.com>
Date: 2026-02-26 20:35
Parents: bb1ed51
1 files changed +10 -4
Type
lib/ex_git_objectstore/walk.ex +10 −4
@@ -204,13 +204,19 @@
end
defp sort_by_time(commits) do
Enum.sort_by(
commits,
fn {_sha, commit} ->
parse_timestamp(commit.committer)
# The acc has commits in reverse walk order (oldest at front for linear history).
# Reverse to get walk order (newest first), then use index as tiebreaker
# so same-second commits preserve topological ordering.
commits
|> Enum.reverse()
|> Enum.with_index()
|> Enum.sort_by(
fn {{_sha, commit}, idx} ->
{parse_timestamp(commit.committer), -idx}
end,
:desc
)
|> Enum.map(fn {commit, _idx} -> commit end)
end
defp parse_timestamp(author_or_committer) when is_binary(author_or_committer) do