Skip to content

Commit cfc6e21

Browse files
authored
Fix incorrect ref usages (#33301)
Fix #33297 By the way, improve some locales
1 parent ab347fd commit cfc6e21

File tree

6 files changed

+24
-22
lines changed

6 files changed

+24
-22
lines changed

options/locale/locale_en-US.ini

+3-3
Original file line numberDiff line numberDiff line change
@@ -1685,16 +1685,16 @@ issues.timetracker_timer_manually_add = Add Time
16851685
16861686
issues.time_estimate_set = Set estimated time
16871687
issues.time_estimate_display = Estimate: %s
1688-
issues.change_time_estimate_at = changed time estimate to <b>%s</b> %s
1688+
issues.change_time_estimate_at = changed time estimate to <b>%[1]s</b> %[2]s
16891689
issues.remove_time_estimate_at = removed time estimate %s
16901690
issues.time_estimate_invalid = Time estimate format is invalid
16911691
issues.start_tracking_history = started working %s
16921692
issues.tracker_auto_close = Timer will be stopped automatically when this issue gets closed
16931693
issues.tracking_already_started = `You have already started time tracking on <a href="%s">another issue</a>!`
1694-
issues.stop_tracking_history = worked for <b>%s</b> %s
1694+
issues.stop_tracking_history = worked for <b>%[1]s</b> %[2]s
16951695
issues.cancel_tracking_history = `canceled time tracking %s`
16961696
issues.del_time = Delete this time log
1697-
issues.add_time_history = added spent time <b>%s</b> %s
1697+
issues.add_time_history = added spent time <b>%[1]s</b> %[2]s
16981698
issues.del_time_history= `deleted spent time %s`
16991699
issues.add_time_manually = Manually Add Time
17001700
issues.add_time_hours = Hours

routers/web/repo/branch.go

-1
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

+1-12
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

+7-5
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() /* for the "commits" tab */, 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() /* for the "commits" tab */, 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

+12
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,18 @@ 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["RefFullName"] = ctx.Repo.RefFullName
787+
ctx.Data["BranchName"] = ctx.Repo.BranchName
788+
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
789+
}
790+
}
791+
780792
// RepoRefByType handles repository reference name for a specific type
781793
// of repository reference
782794
func RepoRefByType(detectRefType git.RefType) func(*Context) {

templates/repo/sub_menu.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="ui segments repository-summary tw-mt-1 tw-mb-0">
33
<div class="ui segment sub-menu repository-menu">
44
{{if and (.Permission.CanRead ctx.Consts.RepoUnitTypeCode) (not .IsEmptyRepo)}}
5-
<a class="item muted {{if .PageIsCommits}}active{{end}}" href="{{.RepoLink}}/commits/{{.RefTypeNameSubURL}}">
5+
<a class="item muted {{if .PageIsCommits}}active{{end}}" href="{{.RepoLink}}/commits/{{.RefFullName.RefWebLinkPath}}">
66
{{svg "octicon-history"}} <b>{{ctx.Locale.PrettyNumber .CommitsCount}}</b> {{ctx.Locale.TrN .CommitsCount "repo.commit" "repo.commits"}}
77
</a>
88
<a class="item muted {{if .PageIsBranches}}active{{end}}" href="{{.RepoLink}}/branches">

0 commit comments

Comments
 (0)