@@ -6,32 +6,12 @@ package repository
66import (
77 "context"
88
9- git_model "code.gitea.io/gitea/models/git"
109 repo_model "code.gitea.io/gitea/models/repo"
1110 "code.gitea.io/gitea/modules/cache"
1211 "code.gitea.io/gitea/modules/git"
12+ context_service "code.gitea.io/gitea/services/context"
1313)
1414
15- func GetRefCommitsCount (ctx context.Context , repoID int64 , refFullName git.RefName ) (int64 , error ) {
16- // Get the commit count of the branch or the tag
17- switch {
18- case refFullName .IsBranch ():
19- branch , err := git_model .GetBranch (ctx , repoID , refFullName .BranchName ())
20- if err != nil {
21- return 0 , err
22- }
23- return branch .CommitCount , nil
24- case refFullName .IsTag ():
25- tag , err := repo_model .GetRelease (ctx , repoID , refFullName .TagName ())
26- if err != nil {
27- return 0 , err
28- }
29- return tag .NumCommits , nil
30- default :
31- return 0 , nil
32- }
33- }
34-
3515// CacheRef cachhe last commit information of the branch or the tag
3616func CacheRef (ctx context.Context , repo * repo_model.Repository , gitRepo * git.Repository , fullRefName git.RefName ) error {
3717 commit , err := gitRepo .GetCommit (fullRefName .String ())
@@ -40,7 +20,7 @@ func CacheRef(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Rep
4020 }
4121
4222 if gitRepo .LastCommitCache == nil {
43- commitsCount , err := GetRefCommitsCount (ctx , repo .ID , fullRefName )
23+ commitsCount , err := context_service . GetRefCommitsCount (ctx , repo .ID , fullRefName )
4424 if err != nil {
4525 return err
4626 }
0 commit comments