@@ -53,20 +53,15 @@ 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"
59+ TagName string // it is the RefFullName's short name if its type is "tag"
6460 TreePath string
6561
66- // Commit it is always set to the commit for the branch or tag
67- Commit * git.Commit
68- CommitID string
69-
62+ // Commit it is always set to the commit for the branch or tag, or just the commit that the user is viewing
63+ Commit * git.Commit
64+ CommitID string
7065 CommitsCount int64
7166
7267 PullRequest * PullRequest
@@ -79,7 +74,7 @@ func (r *Repository) CanWriteToBranch(ctx context.Context, user *user_model.User
7974
8075// CanEnableEditor returns true if repository is editable and user has proper access level.
8176func (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
77+ return r .RefFullName . IsBranch () && r .CanWriteToBranch (ctx , user , r .BranchName ) && r .Repository .CanEnableEditor () && ! r .Repository .IsArchived
8378}
8479
8580// CanCreateBranch returns true if repository is editable and user has proper access level.
@@ -174,15 +169,9 @@ func (r *Repository) GetCommitsCount() (int64, error) {
174169 if r .Commit == nil {
175170 return 0 , nil
176171 }
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 ) {
172+ contextName := r .RefFullName .ShortName ()
173+ isRef := r .RefFullName .IsBranch () || r .RefFullName .IsTag ()
174+ return cache .GetInt64 (r .Repository .GetCommitsCountCacheKey (contextName , isRef ), func () (int64 , error ) {
186175 return r .Commit .CommitsCount ()
187176 })
188177}
@@ -798,7 +787,6 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
798787 // Empty repository does not have reference information.
799788 if ctx .Repo .Repository .IsEmpty {
800789 // assume the user is viewing the (non-existent) default branch
801- ctx .Repo .IsViewBranch = true
802790 ctx .Repo .BranchName = ctx .Repo .Repository .DefaultBranch
803791 ctx .Repo .RefFullName = git .RefNameFromBranch (ctx .Repo .BranchName )
804792 // these variables are used by the template to "add/upload" new files
@@ -834,7 +822,6 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
834822 ctx .ServerError ("GetBranchCommit" , err )
835823 return
836824 }
837- ctx .Repo .IsViewBranch = true
838825 } else { // there is a path in request
839826 guessLegacyPath := refType == ""
840827 if guessLegacyPath {
@@ -853,7 +840,6 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
853840 }
854841
855842 if refType == git .RefTypeBranch && ctx .Repo .GitRepo .IsBranchExist (refShortName ) {
856- ctx .Repo .IsViewBranch = true
857843 ctx .Repo .BranchName = refShortName
858844 ctx .Repo .RefFullName = git .RefNameFromBranch (refShortName )
859845
@@ -864,7 +850,6 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
864850 }
865851 ctx .Repo .CommitID = ctx .Repo .Commit .ID .String ()
866852 } else if refType == git .RefTypeTag && ctx .Repo .GitRepo .IsTagExist (refShortName ) {
867- ctx .Repo .IsViewTag = true
868853 ctx .Repo .RefFullName = git .RefNameFromTag (refShortName )
869854 ctx .Repo .TagName = refShortName
870855
@@ -879,7 +864,6 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
879864 }
880865 ctx .Repo .CommitID = ctx .Repo .Commit .ID .String ()
881866 } else if git .IsStringLikelyCommitID (ctx .Repo .GetObjectFormat (), refShortName , 7 ) {
882- ctx .Repo .IsViewCommit = true
883867 ctx .Repo .RefFullName = git .RefNameFromCommit (refShortName )
884868 ctx .Repo .CommitID = refShortName
885869
@@ -915,13 +899,10 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
915899 ctx .Data ["RefTypeNameSubURL" ] = ctx .Repo .RefTypeNameSubURL ()
916900 ctx .Data ["TreePath" ] = ctx .Repo .TreePath
917901
918- ctx .Data ["IsViewBranch" ] = ctx .Repo .IsViewBranch
919902 ctx .Data ["BranchName" ] = ctx .Repo .BranchName
920903
921- ctx .Data ["IsViewTag" ] = ctx .Repo .IsViewTag
922904 ctx .Data ["TagName" ] = ctx .Repo .TagName
923905
924- ctx .Data ["IsViewCommit" ] = ctx .Repo .IsViewCommit
925906 ctx .Data ["CommitID" ] = ctx .Repo .CommitID
926907
927908 ctx .Data ["CanCreateBranch" ] = ctx .Repo .CanCreateBranch () // only used by the branch selector dropdown: AllowCreateNewRef
0 commit comments