@@ -53,20 +53,15 @@ type Repository struct {
53
53
RepoLink string
54
54
GitRepo * git.Repository
55
55
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
61
57
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"
64
60
TreePath string
65
61
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
70
65
CommitsCount int64
71
66
72
67
PullRequest * PullRequest
@@ -79,7 +74,7 @@ func (r *Repository) CanWriteToBranch(ctx context.Context, user *user_model.User
79
74
80
75
// CanEnableEditor returns true if repository is editable and user has proper access level.
81
76
func (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
83
78
}
84
79
85
80
// CanCreateBranch returns true if repository is editable and user has proper access level.
@@ -174,15 +169,9 @@ func (r *Repository) GetCommitsCount() (int64, error) {
174
169
if r .Commit == nil {
175
170
return 0 , nil
176
171
}
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 ) {
186
175
return r .Commit .CommitsCount ()
187
176
})
188
177
}
@@ -798,7 +787,6 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
798
787
// Empty repository does not have reference information.
799
788
if ctx .Repo .Repository .IsEmpty {
800
789
// assume the user is viewing the (non-existent) default branch
801
- ctx .Repo .IsViewBranch = true
802
790
ctx .Repo .BranchName = ctx .Repo .Repository .DefaultBranch
803
791
ctx .Repo .RefFullName = git .RefNameFromBranch (ctx .Repo .BranchName )
804
792
// these variables are used by the template to "add/upload" new files
@@ -834,7 +822,6 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
834
822
ctx .ServerError ("GetBranchCommit" , err )
835
823
return
836
824
}
837
- ctx .Repo .IsViewBranch = true
838
825
} else { // there is a path in request
839
826
guessLegacyPath := refType == ""
840
827
if guessLegacyPath {
@@ -853,7 +840,6 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
853
840
}
854
841
855
842
if refType == git .RefTypeBranch && ctx .Repo .GitRepo .IsBranchExist (refShortName ) {
856
- ctx .Repo .IsViewBranch = true
857
843
ctx .Repo .BranchName = refShortName
858
844
ctx .Repo .RefFullName = git .RefNameFromBranch (refShortName )
859
845
@@ -864,7 +850,6 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
864
850
}
865
851
ctx .Repo .CommitID = ctx .Repo .Commit .ID .String ()
866
852
} else if refType == git .RefTypeTag && ctx .Repo .GitRepo .IsTagExist (refShortName ) {
867
- ctx .Repo .IsViewTag = true
868
853
ctx .Repo .RefFullName = git .RefNameFromTag (refShortName )
869
854
ctx .Repo .TagName = refShortName
870
855
@@ -879,7 +864,6 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
879
864
}
880
865
ctx .Repo .CommitID = ctx .Repo .Commit .ID .String ()
881
866
} else if git .IsStringLikelyCommitID (ctx .Repo .GetObjectFormat (), refShortName , 7 ) {
882
- ctx .Repo .IsViewCommit = true
883
867
ctx .Repo .RefFullName = git .RefNameFromCommit (refShortName )
884
868
ctx .Repo .CommitID = refShortName
885
869
@@ -915,13 +899,10 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
915
899
ctx .Data ["RefTypeNameSubURL" ] = ctx .Repo .RefTypeNameSubURL ()
916
900
ctx .Data ["TreePath" ] = ctx .Repo .TreePath
917
901
918
- ctx .Data ["IsViewBranch" ] = ctx .Repo .IsViewBranch
919
902
ctx .Data ["BranchName" ] = ctx .Repo .BranchName
920
903
921
- ctx .Data ["IsViewTag" ] = ctx .Repo .IsViewTag
922
904
ctx .Data ["TagName" ] = ctx .Repo .TagName
923
905
924
- ctx .Data ["IsViewCommit" ] = ctx .Repo .IsViewCommit
925
906
ctx .Data ["CommitID" ] = ctx .Repo .CommitID
926
907
927
908
ctx .Data ["CanCreateBranch" ] = ctx .Repo .CanCreateBranch () // only used by the branch selector dropdown: AllowCreateNewRef
0 commit comments