Skip to content

Commit 4fc01d2

Browse files
authored
Merge branch 'main' into improve-actions-gitcontext
2 parents 67fdece + f6dbf0e commit 4fc01d2

File tree

16 files changed

+47
-95
lines changed

16 files changed

+47
-95
lines changed

routers/web/repo/branch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ func CreateBranch(ctx *context.Context) {
193193

194194
if form.CreateTag {
195195
target := ctx.Repo.CommitID
196-
if ctx.Repo.IsViewBranch {
196+
if ctx.Repo.RefFullName.IsBranch() {
197197
target = ctx.Repo.BranchName
198198
}
199199
err = release_service.CreateNewTag(ctx, ctx.Doer, ctx.Repo.Repository, target, form.NewBranchName, "")
200-
} else if ctx.Repo.IsViewBranch {
200+
} else if ctx.Repo.RefFullName.IsBranch() {
201201
err = repo_service.CreateNewBranch(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, ctx.Repo.BranchName, form.NewBranchName)
202202
} else {
203203
err = repo_service.CreateNewBranchFromCommit(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, ctx.Repo.CommitID, form.NewBranchName)

routers/web/repo/commit.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,6 @@ func Diff(ctx *context.Context) {
390390
}
391391
}
392392

393-
ctx.Data["BranchName"], err = commit.GetBranchName()
394-
if err != nil {
395-
ctx.ServerError("commit.GetBranchName", err)
396-
return
397-
}
398-
399393
ctx.HTML(http.StatusOK, tplCommitPage)
400394
}
401395

routers/web/repo/release.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ func getReleaseInfos(ctx *context.Context, opts *repo_model.FindReleasesOptions)
148148
func Releases(ctx *context.Context) {
149149
ctx.Data["PageIsReleaseList"] = true
150150
ctx.Data["Title"] = ctx.Tr("repo.release.releases")
151-
ctx.Data["IsViewBranch"] = false
152-
ctx.Data["IsViewTag"] = true
153151

154152
listOptions := db.ListOptions{
155153
Page: ctx.FormInt("page"),
@@ -194,8 +192,6 @@ func Releases(ctx *context.Context) {
194192
func TagsList(ctx *context.Context) {
195193
ctx.Data["PageIsTagList"] = true
196194
ctx.Data["Title"] = ctx.Tr("repo.release.tags")
197-
ctx.Data["IsViewBranch"] = false
198-
ctx.Data["IsViewTag"] = true
199195
ctx.Data["CanCreateRelease"] = ctx.Repo.CanWrite(unit.TypeReleases) && !ctx.Repo.Repository.IsArchived
200196

201197
namePattern := ctx.FormTrim("q")
@@ -299,6 +295,7 @@ func SingleRelease(ctx *context.Context) {
299295
}
300296

301297
ctx.Data["PageIsSingleTag"] = release.IsTag
298+
ctx.Data["SingleReleaseTagName"] = release.TagName
302299
if release.IsTag {
303300
ctx.Data["Title"] = release.TagName
304301
} else {

routers/web/repo/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func Search(ctx *context.Context) {
7070
res, err := git.GrepSearch(ctx, ctx.Repo.GitRepo, prepareSearch.Keyword, git.GrepOptions{
7171
ContextLineNumber: 1,
7272
IsFuzzy: prepareSearch.IsFuzzy,
73-
RefName: git.RefNameFromBranch(ctx.Repo.BranchName).String(), // BranchName should be default branch or the first existing branch
73+
RefName: git.RefNameFromBranch(ctx.Repo.Repository.DefaultBranch).String(), // BranchName should be default branch or the first existing branch
7474
PathspecList: indexSettingToGitGrepPathspecList(),
7575
})
7676
if err != nil {

routers/web/repo/view_file.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
232232
ctx.Data["CanEditFile"] = true
233233
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file")
234234
}
235-
} else if !ctx.Repo.IsViewBranch {
235+
} else if !ctx.Repo.RefFullName.IsBranch() {
236236
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
237237
} else if !ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, ctx.Repo.BranchName) {
238238
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.fork_before_edit")
@@ -305,7 +305,7 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
305305
ctx.Data["CanDeleteFile"] = true
306306
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.delete_this_file")
307307
}
308-
} else if !ctx.Repo.IsViewBranch {
308+
} else if !ctx.Repo.RefFullName.IsBranch() {
309309
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
310310
} else if !ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, ctx.Repo.BranchName) {
311311
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_have_write_access")

routers/web/repo/view_home.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func prepareHomeSidebarLatestRelease(ctx *context.Context) {
178178
}
179179

180180
func prepareUpstreamDivergingInfo(ctx *context.Context) {
181-
if !ctx.Repo.Repository.IsFork || !ctx.Repo.IsViewBranch || ctx.Repo.TreePath != "" {
181+
if !ctx.Repo.Repository.IsFork || !ctx.Repo.RefFullName.IsBranch() || ctx.Repo.TreePath != "" {
182182
return
183183
}
184184
upstreamDivergingInfo, err := repo_service.GetUpstreamDivergingInfo(ctx, ctx.Repo.Repository, ctx.Repo.BranchName)

routers/web/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ func registerRoutes(m *web.Router) {
15921592
m.Get("/watchers", repo.Watchers)
15931593
m.Get("/search", reqUnitCodeReader, repo.Search)
15941594
m.Post("/action/{action}", reqSignIn, repo.Action)
1595-
}, optSignIn, context.RepoAssignment, context.RepoRef())
1595+
}, optSignIn, context.RepoAssignment)
15961596

15971597
common.AddOwnerRepoGitLFSRoutes(m, optSignInIgnoreCsrf, lfsServerEnabled) // "/{username}/{reponame}/{lfs-paths}": git-lfs support
15981598

services/context/repo.go

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
8175
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
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

templates/repo/blame.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<div class="file-header-right file-actions tw-flex tw-items-center tw-flex-wrap">
1919
<div class="ui buttons">
2020
<a class="ui tiny button" href="{{$.RawFileLink}}">{{ctx.Locale.Tr "repo.file_raw"}}</a>
21-
{{if not .IsViewCommit}}
21+
{{if or .RefFullName.IsBranch .RefFullName.IsTag}}
2222
<a class="ui tiny button" href="{{.RepoLink}}/src/commit/{{.CommitID | PathEscape}}/{{.TreePath | PathEscapeSegments}}">{{ctx.Locale.Tr "repo.file_permalink"}}</a>
2323
{{end}}
2424
<a class="ui tiny button" href="{{.RepoLink}}/src/{{.RefTypeNameSubURL}}/{{.TreePath | PathEscapeSegments}}">{{ctx.Locale.Tr "repo.normal_view"}}</a>

templates/repo/commit_page.tmpl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,11 @@
5454
<p id="cherry-pick-content" class="branch-dropdown"></p>
5555

5656
<form method="get">
57-
{{/*FIXME: CurrentRefShortName seems not making sense here (old code),
58-
because the "commit page" has no "$.BranchName" info, so only using DefaultBranch should be enough */}}
5957
{{template "repo/branch_dropdown" dict
6058
"Repository" .Repository
6159
"ShowTabBranches" true
6260
"CurrentRefType" "branch"
63-
"CurrentRefShortName" (or $.BranchName $.Repository.DefaultBranch)
61+
"CurrentRefShortName" $.Repository.DefaultBranch
6462
"RefFormActionTemplate" (print "{RepoLink}/_cherrypick/" .CommitID "/{RefShortName}")
6563
}}
6664
<input type="hidden" id="cherry-pick-type" name="cherry-pick-type"><br>

0 commit comments

Comments
 (0)