Skip to content

Commit 948ff41

Browse files
committed
fix
1 parent 1228d48 commit 948ff41

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

routers/web/repo/commit.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"html/template"
1111
"net/http"
1212
"path"
13+
"sort"
1314
"strings"
1415
"time"
1516

@@ -28,6 +29,7 @@ import (
2829
"code.gitea.io/gitea/modules/markup"
2930
"code.gitea.io/gitea/modules/setting"
3031
"code.gitea.io/gitea/modules/templates"
32+
"code.gitea.io/gitea/modules/timeutil"
3133
"code.gitea.io/gitea/modules/util"
3234
asymkey_service "code.gitea.io/gitea/services/asymkey"
3335
"code.gitea.io/gitea/services/context"
@@ -465,13 +467,14 @@ func processGitCommits(ctx *context.Context, gitCommits []*git.Commit) ([]*git_m
465467

466468
// GroupedCommits defines the structure for grouped commits.
467469
type GroupedCommits struct {
468-
Date time.Time
470+
Date timeutil.TimeStamp
469471
Commits []*git_model.SignCommitWithStatuses
470472
}
471473

472474
// GroupCommitsByDate groups the commits by date (in days).
473475
func GroupCommitsByDate(commits []*git_model.SignCommitWithStatuses) []GroupedCommits {
474-
grouped := make(map[string][]*git_model.SignCommitWithStatuses)
476+
// Use Unix timestamp of date as key (truncated to day)
477+
grouped := make(map[int64][]*git_model.SignCommitWithStatuses)
475478

476479
for _, commit := range commits {
477480
var sigTime time.Time
@@ -481,17 +484,32 @@ func GroupCommitsByDate(commits []*git_model.SignCommitWithStatuses) []GroupedCo
481484
sigTime = commit.Author.When
482485
}
483486

484-
// Extract the date part
485-
date := sigTime.Format("2006-01-02")
486-
grouped[date] = append(grouped[date], commit)
487+
// Truncate time to date part (remove hours, minutes, seconds)
488+
year, month, day := sigTime.Date()
489+
dateOnly := time.Date(year, month, day, 0, 0, 0, 0, sigTime.Location())
490+
dateUnix := dateOnly.Unix()
491+
492+
grouped[dateUnix] = append(grouped[dateUnix], commit)
487493
}
488494

495+
// Create result slice with pre-allocated capacity
489496
result := make([]GroupedCommits, 0, len(grouped))
490-
for dateStr, commitsGroup := range grouped {
491-
date, _ := time.Parse("2006-01-02", dateStr)
497+
498+
// Collect all dates and sort them
499+
dates := make([]int64, 0, len(grouped))
500+
for dateUnix := range grouped {
501+
dates = append(dates, dateUnix)
502+
}
503+
// Sort dates in descending order (most recent first)
504+
sort.Slice(dates, func(i, j int) bool {
505+
return dates[i] > dates[j]
506+
})
507+
508+
// Build result in sorted order
509+
for _, dateUnix := range dates {
492510
result = append(result, GroupedCommits{
493-
Date: date,
494-
Commits: commitsGroup,
511+
Date: timeutil.TimeStamp(dateUnix),
512+
Commits: grouped[dateUnix],
495513
})
496514
}
497515

0 commit comments

Comments
 (0)