@@ -10,6 +10,7 @@ import (
10
10
"html/template"
11
11
"net/http"
12
12
"path"
13
+ "sort"
13
14
"strings"
14
15
"time"
15
16
@@ -28,6 +29,7 @@ import (
28
29
"code.gitea.io/gitea/modules/markup"
29
30
"code.gitea.io/gitea/modules/setting"
30
31
"code.gitea.io/gitea/modules/templates"
32
+ "code.gitea.io/gitea/modules/timeutil"
31
33
"code.gitea.io/gitea/modules/util"
32
34
asymkey_service "code.gitea.io/gitea/services/asymkey"
33
35
"code.gitea.io/gitea/services/context"
@@ -465,13 +467,14 @@ func processGitCommits(ctx *context.Context, gitCommits []*git.Commit) ([]*git_m
465
467
466
468
// GroupedCommits defines the structure for grouped commits.
467
469
type GroupedCommits struct {
468
- Date time. Time
470
+ Date timeutil. TimeStamp
469
471
Commits []* git_model.SignCommitWithStatuses
470
472
}
471
473
472
474
// GroupCommitsByDate groups the commits by date (in days).
473
475
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 )
475
478
476
479
for _ , commit := range commits {
477
480
var sigTime time.Time
@@ -481,17 +484,32 @@ func GroupCommitsByDate(commits []*git_model.SignCommitWithStatuses) []GroupedCo
481
484
sigTime = commit .Author .When
482
485
}
483
486
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 )
487
493
}
488
494
495
+ // Create result slice with pre-allocated capacity
489
496
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 {
492
510
result = append (result , GroupedCommits {
493
- Date : date ,
494
- Commits : commitsGroup ,
511
+ Date : timeutil . TimeStamp ( dateUnix ) ,
512
+ Commits : grouped [ dateUnix ] ,
495
513
})
496
514
}
497
515
0 commit comments