From 532be8c2e773a7d153e324699325140f2e940046 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Fri, 28 Aug 2026 23:25:43 +0900 Subject: [PATCH] git: sort 'history' commits in reverse chronological order, the depth-first order from the api put merged branches after the root commit. --- git.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/git.go b/git.go index b52c0c7..1d96a88 100644 --- a/git.go +++ b/git.go @@ -800,6 +800,20 @@ aside from those, there is also: continue } + // they come back in a depth-first order that walks the first parent + // all the way down to the root before visiting merged branches, so + // put them in reverse chronological order like 'git log' does + slices.SortStableFunc(commits, func(a, b *gitnaturalapi.Commit) int { + switch { + case a.Committer.Timestamp > b.Committer.Timestamp: + return -1 + case a.Committer.Timestamp < b.Committer.Timestamp: + return 1 + default: + return 0 + } + }) + for _, c := range commits { date := time.Unix(c.Author.Timestamp, 0).Format(time.DateOnly) stdout(