@@ -53,20 +53,14 @@ type Repository struct {
5353 RepoLink string
5454 GitRepo * git.Repository
5555
56- // these fields indicate the current ref type, for example: ".../src/branch/master" means IsViewBranch=true
57- IsViewBranch bool
58- IsViewTag bool
59- IsViewCommit bool
60-
56+ // RefFullName is the full ref name that the user is viewing
6157 RefFullName git.RefName
62- BranchName string
63- TagName string
58+ BranchName string // it is the RefFullName's short name if its type is "branch"
6459 TreePath string
6560
66- // Commit it is always set to the commit for the branch or tag
67- Commit * git.Commit
68- CommitID string
69-
61+ // Commit it is always set to the commit for the branch or tag, or just the commit that the user is viewing
62+ Commit * git.Commit
63+ CommitID string
7064 CommitsCount int64
7165
7266 PullRequest * PullRequest
@@ -79,7 +73,7 @@ func (r *Repository) CanWriteToBranch(ctx context.Context, user *user_model.User
7973
8074// CanEnableEditor returns true if repository is editable and user has proper access level.
8175func (r * Repository ) CanEnableEditor (ctx context.Context , user * user_model.User ) bool {
82- return r .IsViewBranch && r .CanWriteToBranch (ctx , user , r .BranchName ) && r .Repository .CanEnableEditor () && ! r .Repository .IsArchived
76+ return r .RefFullName . IsBranch () && r .CanWriteToBranch (ctx , user , r .BranchName ) && r .Repository .CanEnableEditor () && ! r .Repository .IsArchived
8377}
8478
8579// CanCreateBranch returns true if repository is editable and user has proper access level.
@@ -174,15 +168,9 @@ func (r *Repository) GetCommitsCount() (int64, error) {
174168 if r .Commit == nil {
175169 return 0 , nil
176170 }
177- var contextName string
178- if r .IsViewBranch {
179- contextName = r .BranchName
180- } else if r .IsViewTag {
181- contextName = r .TagName
182- } else {
183- contextName = r .CommitID
184- }
185- return cache .GetInt64 (r .Repository .GetCommitsCountCacheKey (contextName , r .IsViewBranch || r .IsViewTag ), func () (int64 , error ) {
171+ contextName := r .RefFullName .ShortName ()
172+ isRef := r .RefFullName .IsBranch () || r .RefFullName .IsTag ()
173+ return cache .GetInt64 (r .Repository .GetCommitsCountCacheKey (contextName , isRef ), func () (int64 , error ) {
186174 return r .Commit .CommitsCount ()
187175 })
188176}
@@ -798,7 +786,6 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
798786 // Empty repository does not have reference information.
799787 if ctx .Repo .Repository .IsEmpty {
800788 // assume the user is viewing the (non-existent) default branch
801- ctx .Repo .IsViewBranch = true
802789 ctx .Repo .BranchName = ctx .Repo .Repository .DefaultBranch
803790 ctx .Repo .RefFullName = git .RefNameFromBranch (ctx .Repo .BranchName )
804791 // these variables are used by the template to "add/upload" new files
@@ -834,7 +821,6 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
834821 ctx .ServerError ("GetBranchCommit" , err )
835822 return
836823 }
837- ctx .Repo .IsViewBranch = true
838824 } else { // there is a path in request
839825 guessLegacyPath := refType == ""
840826 if guessLegacyPath {
@@ -853,7 +839,6 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
853839 }
854840
855841 if refType == git .RefTypeBranch && ctx .Repo .GitRepo .IsBranchExist (refShortName ) {
856- ctx .Repo .IsViewBranch = true
857842 ctx .Repo .BranchName = refShortName
858843 ctx .Repo .RefFullName = git .RefNameFromBranch (refShortName )
859844
@@ -864,9 +849,7 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
864849 }
865850 ctx .Repo .CommitID = ctx .Repo .Commit .ID .String ()
866851 } else if refType == git .RefTypeTag && ctx .Repo .GitRepo .IsTagExist (refShortName ) {
867- ctx .Repo .IsViewTag = true
868852 ctx .Repo .RefFullName = git .RefNameFromTag (refShortName )
869- ctx .Repo .TagName = refShortName
870853
871854 ctx .Repo .Commit , err = ctx .Repo .GitRepo .GetTagCommit (refShortName )
872855 if err != nil {
@@ -879,7 +862,6 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
879862 }
880863 ctx .Repo .CommitID = ctx .Repo .Commit .ID .String ()
881864 } else if git .IsStringLikelyCommitID (ctx .Repo .GetObjectFormat (), refShortName , 7 ) {
882- ctx .Repo .IsViewCommit = true
883865 ctx .Repo .RefFullName = git .RefNameFromCommit (refShortName )
884866 ctx .Repo .CommitID = refShortName
885867
@@ -915,13 +897,8 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
915897 ctx .Data ["RefTypeNameSubURL" ] = ctx .Repo .RefTypeNameSubURL ()
916898 ctx .Data ["TreePath" ] = ctx .Repo .TreePath
917899
918- ctx .Data ["IsViewBranch" ] = ctx .Repo .IsViewBranch
919900 ctx .Data ["BranchName" ] = ctx .Repo .BranchName
920901
921- ctx .Data ["IsViewTag" ] = ctx .Repo .IsViewTag
922- ctx .Data ["TagName" ] = ctx .Repo .TagName
923-
924- ctx .Data ["IsViewCommit" ] = ctx .Repo .IsViewCommit
925902 ctx .Data ["CommitID" ] = ctx .Repo .CommitID
926903
927904 ctx .Data ["CanCreateBranch" ] = ctx .Repo .CanCreateBranch () // only used by the branch selector dropdown: AllowCreateNewRef
0 commit comments