Skip to content

Commit aaea689

Browse files
committed
fix
1 parent 2483a93 commit aaea689

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

routers/web/repo/branch.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const (
3737
// Branches render repository branch page
3838
func Branches(ctx *context.Context) {
3939
ctx.Data["Title"] = "Branches"
40-
ctx.Data["IsRepoToolbarBranches"] = true
4140
ctx.Data["AllowsPulls"] = ctx.Repo.Repository.AllowsPulls(ctx)
4241
ctx.Data["IsWriter"] = ctx.Repo.CanWrite(unit.TypeCode)
4342
ctx.Data["IsMirror"] = ctx.Repo.Repository.IsMirror

routers/web/repo/commit.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ func Commits(ctx *context.Context) {
6262
}
6363
ctx.Data["PageIsViewCode"] = true
6464

65-
commitsCount, err := ctx.Repo.GetCommitsCount()
66-
if err != nil {
67-
ctx.ServerError("GetCommitsCount", err)
68-
return
69-
}
65+
commitsCount := ctx.Repo.CommitsCount
7066

7167
page := ctx.FormInt("page")
7268
if page <= 1 {
@@ -129,12 +125,6 @@ func Graph(ctx *context.Context) {
129125
ctx.Data["SelectedBranches"] = realBranches
130126
files := ctx.FormStrings("file")
131127

132-
commitsCount, err := ctx.Repo.GetCommitsCount()
133-
if err != nil {
134-
ctx.ServerError("GetCommitsCount", err)
135-
return
136-
}
137-
138128
graphCommitsCount, err := ctx.Repo.GetCommitGraphsCount(ctx, hidePRRefs, realBranches, files)
139129
if err != nil {
140130
log.Warn("GetCommitGraphsCount error for generate graph exclude prs: %t branches: %s in %-v, Will Ignore branches and try again. Underlying Error: %v", hidePRRefs, branches, ctx.Repo.Repository, err)
@@ -171,7 +161,6 @@ func Graph(ctx *context.Context) {
171161

172162
ctx.Data["Username"] = ctx.Repo.Owner.Name
173163
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
174-
ctx.Data["CommitCount"] = commitsCount
175164

176165
paginator := context.NewPagination(int(graphCommitsCount), setting.UI.GraphMaxCommitNum, page, 5)
177166
paginator.AddParamFromRequest(ctx.Req)

routers/web/web.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ func registerRoutes(m *web.Router) {
13321332

13331333
m.Group("/{username}/{reponame}", func() { // repo tags
13341334
m.Group("/tags", func() {
1335-
m.Get("", repo.TagsList)
1335+
m.Get("", context.RepoRefByDefaultBranch(), repo.TagsList)
13361336
m.Get(".rss", feedEnabled, repo.TagsListFeedRSS)
13371337
m.Get(".atom", feedEnabled, repo.TagsListFeedAtom)
13381338
m.Get("/list", repo.GetTagList)
@@ -1522,8 +1522,8 @@ func registerRoutes(m *web.Router) {
15221522

15231523
m.Group("/branches", func() {
15241524
m.Get("/list", repo.GetBranchesList)
1525-
m.Get("", repo.Branches)
1526-
}, repo.MustBeNotEmpty, context.RepoRef())
1525+
m.Get("", context.RepoRefByDefaultBranch(), repo.Branches)
1526+
}, repo.MustBeNotEmpty)
15271527

15281528
m.Group("/media", func() {
15291529
m.Get("/blob/{sha}", repo.DownloadByIDOrLFS)
@@ -1567,8 +1567,10 @@ func registerRoutes(m *web.Router) {
15671567
m.Get("/graph", repo.Graph)
15681568
m.Get("/commit/{sha:([a-f0-9]{7,64})$}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.Diff)
15691569
m.Get("/commit/{sha:([a-f0-9]{7,64})$}/load-branches-and-tags", repo.LoadBranchesAndTags)
1570-
m.Get("/cherry-pick/{sha:([a-f0-9]{7,64})$}", repo.SetEditorconfigIfExists, repo.CherryPick)
1571-
}, repo.MustBeNotEmpty, context.RepoRef())
1570+
1571+
// FIXME: this route `/cherry-pick/{sha}` doesn't seem useful or right, the new code always uses `/_cherrypick/` which could handle branch name correctly
1572+
m.Get("/cherry-pick/{sha:([a-f0-9]{7,64})$}", repo.SetEditorconfigIfExists, context.RepoRefByDefaultBranch(), repo.CherryPick)
1573+
}, repo.MustBeNotEmpty)
15721574

15731575
m.Get("/rss/branch/*", context.RepoRefByType(git.RefTypeBranch), feedEnabled, feed.RenderBranchFeed)
15741576
m.Get("/atom/branch/*", context.RepoRefByType(git.RefTypeBranch), feedEnabled, feed.RenderBranchFeed)

services/context/repo.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,19 @@ func repoRefFullName(typ git.RefType, shortName string) git.RefName {
777777
}
778778
}
779779

780+
func RepoRefByDefaultBranch() func(*Context) {
781+
return func(ctx *Context) {
782+
ctx.Repo.RefFullName = git.RefNameFromBranch(ctx.Repo.Repository.DefaultBranch)
783+
ctx.Repo.BranchName = ctx.Repo.Repository.DefaultBranch
784+
ctx.Repo.Commit, _ = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.BranchName)
785+
ctx.Repo.CommitsCount, _ = ctx.Repo.GetCommitsCount()
786+
ctx.Data["BranchName"] = ctx.Repo.BranchName
787+
ctx.Data["TreePath"] = ""
788+
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
789+
ctx.Data["RefTypeNameSubURL"] = ctx.Repo.RefTypeNameSubURL()
790+
}
791+
}
792+
780793
// RepoRefByType handles repository reference name for a specific type
781794
// of repository reference
782795
func RepoRefByType(detectRefType git.RefType) func(*Context) {

0 commit comments

Comments
 (0)