@@ -11,6 +11,7 @@ import (
1111 "net/http"
1212 "path"
1313 "strings"
14+ "time"
1415
1516 asymkey_model "code.gitea.io/gitea/models/asymkey"
1617 "code.gitea.io/gitea/models/db"
@@ -82,11 +83,12 @@ func Commits(ctx *context.Context) {
8283 ctx .ServerError ("CommitsByRange" , err )
8384 return
8485 }
85- ctx . Data [ "Commits" ] , err = processGitCommits (ctx , commits )
86+ processedCommits , err : = processGitCommits (ctx , commits )
8687 if err != nil {
8788 ctx .ServerError ("processGitCommits" , err )
8889 return
8990 }
91+ ctx .Data ["GroupCommits" ] = GroupCommitsByDate (processedCommits )
9092 commitIDs := make ([]string , 0 , len (commits ))
9193 for _ , c := range commits {
9294 commitIDs = append (commitIDs , c .ID .String ())
@@ -198,11 +200,12 @@ func SearchCommits(ctx *context.Context) {
198200 return
199201 }
200202 ctx .Data ["CommitCount" ] = len (commits )
201- ctx . Data [ "Commits" ] , err = processGitCommits (ctx , commits )
203+ processedCommits , err : = processGitCommits (ctx , commits )
202204 if err != nil {
203205 ctx .ServerError ("processGitCommits" , err )
204206 return
205207 }
208+ ctx .Data ["GroupCommits" ] = GroupCommitsByDate (processedCommits )
206209
207210 ctx .Data ["Keyword" ] = query
208211 if all {
@@ -245,11 +248,12 @@ func FileHistory(ctx *context.Context) {
245248 ctx .ServerError ("CommitsByFileAndRange" , err )
246249 return
247250 }
248- ctx . Data [ "Commits" ] , err = processGitCommits (ctx , commits )
251+ processedCommits , err : = processGitCommits (ctx , commits )
249252 if err != nil {
250253 ctx .ServerError ("processGitCommits" , err )
251254 return
252255 }
256+ ctx .Data ["GroupCommits" ] = GroupCommitsByDate (processedCommits )
253257
254258 ctx .Data ["Username" ] = ctx .Repo .Owner .Name
255259 ctx .Data ["Reponame" ] = ctx .Repo .Repository .Name
@@ -459,3 +463,38 @@ func processGitCommits(ctx *context.Context, gitCommits []*git.Commit) ([]*git_m
459463 }
460464 return commits , nil
461465}
466+
467+ // GroupedCommits defines the structure for grouped commits.
468+ type GroupedCommits struct {
469+ Date time.Time
470+ Commits []* git_model.SignCommitWithStatuses
471+ }
472+
473+ // GroupCommitsByDate groups the commits by date (in days).
474+ func GroupCommitsByDate (commits []* git_model.SignCommitWithStatuses ) []GroupedCommits {
475+ grouped := make (map [string ][]* git_model.SignCommitWithStatuses )
476+
477+ for _ , commit := range commits {
478+ var sigTime time.Time
479+ if commit .Committer != nil {
480+ sigTime = commit .Committer .When
481+ } else if commit .Author != nil {
482+ sigTime = commit .Author .When
483+ }
484+
485+ // Extract the date part
486+ date := sigTime .Format ("2006-01-02" )
487+ grouped [date ] = append (grouped [date ], commit )
488+ }
489+
490+ result := make ([]GroupedCommits , 0 , len (grouped ))
491+ for dateStr , commitsGroup := range grouped {
492+ date , _ := time .Parse ("2006-01-02" , dateStr )
493+ result = append (result , GroupedCommits {
494+ Date : date ,
495+ Commits : commitsGroup ,
496+ })
497+ }
498+
499+ return result
500+ }
0 commit comments