77package repository
88
99import (
10+ "context"
11+ "fmt"
1012 "path"
1113 "path/filepath"
1214 "sync"
@@ -15,6 +17,7 @@ import (
1517 "code.gitea.io/gitea/modules/git"
1618 "code.gitea.io/gitea/modules/graceful"
1719 "code.gitea.io/gitea/modules/log"
20+ "code.gitea.io/gitea/modules/process"
1821 "code.gitea.io/gitea/modules/queue"
1922 "code.gitea.io/gitea/modules/setting"
2023)
@@ -33,6 +36,9 @@ type CommitCacheRequest struct {
3336
3437// Do runs the cache request uniquely ensuring that only one cache request is running for this request triple
3538func (req * CommitCacheRequest ) Do () error {
39+ ctx , cancel , _ := process .GetManager ().AddContext (graceful .GetManager ().HammerContext (), fmt .Sprintf ("Cache: %s:%s:%s:%t" , req .Repo , req .CommitID , req .TreePath , req .Recursive ))
40+ defer cancel ()
41+
3642 recursive := req .Recursive
3743 req .Recursive = false
3844
@@ -52,8 +58,14 @@ func (req *CommitCacheRequest) Do() error {
5258
5359 directories := []string {req .TreePath }
5460 for len (directories ) > 0 {
61+ select {
62+ case <- ctx .Done ():
63+ return ctx .Err ()
64+ default :
65+ }
66+
5567 req .TreePath = directories [len (directories )- 1 ]
56- next , err := req .doTree (repo , commit , recursive , lccache )
68+ next , err := req .doTree (ctx , repo , commit , recursive , lccache )
5769 if err != nil {
5870 return err
5971 }
@@ -62,8 +74,7 @@ func (req *CommitCacheRequest) Do() error {
6274 return nil
6375}
6476
65- func (req * CommitCacheRequest ) doTree (repo * git.Repository , commit * git.Commit , recursive bool , lccache * git.LastCommitCache ) ([]string , error ) {
66-
77+ func (req * CommitCacheRequest ) doTree (ctx context.Context , repo * git.Repository , commit * git.Commit , recursive bool , lccache * git.LastCommitCache ) ([]string , error ) {
6778 tree , err := commit .Tree .SubTree (req .TreePath )
6879 if err != nil {
6980 if git .IsErrNotExist (err ) {
@@ -125,7 +136,7 @@ func (req *CommitCacheRequest) doTree(repo *git.Repository, commit *git.Commit,
125136 return directories , nil
126137 }
127138
128- commits , err := git .GetLastCommitForPaths (graceful . GetManager (). HammerContext () , commitNode , req .TreePath , entryPaths )
139+ commits , err := git .GetLastCommitForPaths (ctx , commitNode , req .TreePath , entryPaths )
129140 if err != nil {
130141 return nil , err
131142 }
0 commit comments