Skip to content

Commit 3a222ee

Browse files
authored
Fixed commit count (#17698) (#17790)
* Fixed commit count (#17698) Added "Tag" label. Unified branch, tag and commit name. * Keep 1.15 behaviour. * Removed locale change.
1 parent add85f5 commit 3a222ee

File tree

7 files changed

+32
-29
lines changed

7 files changed

+32
-29
lines changed

modules/context/repo.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type Repository struct {
5858
Commit *git.Commit
5959
Tag *git.Tag
6060
GitRepo *git.Repository
61+
RefName string
6162
BranchName string
6263
TagName string
6364
TreePath string
@@ -190,9 +191,9 @@ func (r *Repository) BranchNameSubURL() string {
190191
case r.IsViewBranch:
191192
return "branch/" + r.BranchName
192193
case r.IsViewTag:
193-
return "tag/" + r.BranchName
194+
return "tag/" + r.TagName
194195
case r.IsViewCommit:
195-
return "commit/" + r.BranchName
196+
return "commit/" + r.CommitID
196197
}
197198
log.Error("Unknown view type for repo: %v", r)
198199
return ""
@@ -562,8 +563,6 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
562563
ctx.Data["Branches"] = brs
563564
ctx.Data["BranchesCount"] = len(brs)
564565

565-
ctx.Data["TagName"] = ctx.Repo.TagName
566-
567566
// If not branch selected, try default one.
568567
// If default branch doesn't exists, fall back to some other branch.
569568
if len(ctx.Repo.BranchName) == 0 {
@@ -572,9 +571,9 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
572571
} else if len(brs) > 0 {
573572
ctx.Repo.BranchName = brs[0]
574573
}
574+
ctx.Repo.RefName = ctx.Repo.BranchName
575575
}
576576
ctx.Data["BranchName"] = ctx.Repo.BranchName
577-
ctx.Data["CommitID"] = ctx.Repo.CommitID
578577

579578
// People who have push access or have forked repository can propose a new pull request.
580579
canPush := ctx.Repo.CanWrite(models.UnitTypeCode) || (ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID))
@@ -759,7 +758,6 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
759758
// Get default branch.
760759
if len(ctx.Params("*")) == 0 {
761760
refName = ctx.Repo.Repository.DefaultBranch
762-
ctx.Repo.BranchName = refName
763761
if !ctx.Repo.GitRepo.IsBranchExist(refName) {
764762
brs, _, err := ctx.Repo.GitRepo.GetBranches(0, 0)
765763
if err != nil {
@@ -773,6 +771,8 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
773771
}
774772
refName = brs[0]
775773
}
774+
ctx.Repo.RefName = refName
775+
ctx.Repo.BranchName = refName
776776
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName)
777777
if err != nil {
778778
ctx.ServerError("GetBranchCommit", err)
@@ -783,9 +783,10 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
783783

784784
} else {
785785
refName = getRefName(ctx, refType)
786-
ctx.Repo.BranchName = refName
786+
ctx.Repo.RefName = refName
787787
if refType.RefTypeIncludesBranches() && ctx.Repo.GitRepo.IsBranchExist(refName) {
788788
ctx.Repo.IsViewBranch = true
789+
ctx.Repo.BranchName = refName
789790

790791
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName)
791792
if err != nil {
@@ -796,6 +797,8 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
796797

797798
} else if refType.RefTypeIncludesTags() && ctx.Repo.GitRepo.IsTagExist(refName) {
798799
ctx.Repo.IsViewTag = true
800+
ctx.Repo.TagName = refName
801+
799802
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(refName)
800803
if err != nil {
801804
ctx.ServerError("GetTagCommit", err)
@@ -837,6 +840,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
837840

838841
ctx.Data["BranchName"] = ctx.Repo.BranchName
839842
ctx.Data["BranchNameSubURL"] = ctx.Repo.BranchNameSubURL()
843+
ctx.Data["TagName"] = ctx.Repo.TagName
840844
ctx.Data["CommitID"] = ctx.Repo.CommitID
841845
ctx.Data["TreePath"] = ctx.Repo.TreePath
842846
ctx.Data["IsViewBranch"] = ctx.Repo.IsViewBranch

routers/web/repo/branch.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,17 +343,15 @@ func CreateBranch(ctx *context.Context) {
343343
var err error
344344

345345
if form.CreateTag {
346-
if ctx.Repo.IsViewTag {
347-
err = release_service.CreateNewTag(ctx.User, ctx.Repo.Repository, ctx.Repo.CommitID, form.NewBranchName, "")
348-
} else {
349-
err = release_service.CreateNewTag(ctx.User, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName, "")
346+
target := ctx.Repo.CommitID
347+
if ctx.Repo.IsViewBranch {
348+
target = ctx.Repo.BranchName
350349
}
350+
err = release_service.CreateNewTag(ctx.User, ctx.Repo.Repository, target, form.NewBranchName, "")
351351
} else if ctx.Repo.IsViewBranch {
352352
err = repo_module.CreateNewBranch(ctx.User, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName)
353-
} else if ctx.Repo.IsViewTag {
354-
err = repo_module.CreateNewBranchFromCommit(ctx.User, ctx.Repo.Repository, ctx.Repo.CommitID, form.NewBranchName)
355353
} else {
356-
err = repo_module.CreateNewBranchFromCommit(ctx.User, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName)
354+
err = repo_module.CreateNewBranchFromCommit(ctx.User, ctx.Repo.Repository, ctx.Repo.CommitID, form.NewBranchName)
357355
}
358356
if err != nil {
359357
if models.IsErrTagAlreadyExists(err) {

routers/web/repo/commit.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func Commits(ctx *context.Context) {
8080
ctx.Data["Username"] = ctx.Repo.Owner.Name
8181
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
8282
ctx.Data["CommitCount"] = commitsCount
83-
ctx.Data["Branch"] = ctx.Repo.BranchName
83+
ctx.Data["RefName"] = ctx.Repo.RefName
8484

8585
pager := context.NewPagination(int(commitsCount), setting.Git.CommitsRangeSize, page, 5)
8686
pager.SetDefaultParams(ctx)
@@ -156,7 +156,7 @@ func Graph(ctx *context.Context) {
156156
ctx.Data["Username"] = ctx.Repo.Owner.Name
157157
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
158158
ctx.Data["CommitCount"] = commitsCount
159-
ctx.Data["Branch"] = ctx.Repo.BranchName
159+
ctx.Data["RefName"] = ctx.Repo.RefName
160160
paginator := context.NewPagination(int(graphCommitsCount), setting.UI.GraphMaxCommitNum, page, 5)
161161
paginator.AddParam(ctx, "mode", "Mode")
162162
paginator.AddParam(ctx, "hide-pr-refs", "HidePRRefs")
@@ -205,7 +205,7 @@ func SearchCommits(ctx *context.Context) {
205205
ctx.Data["Username"] = ctx.Repo.Owner.Name
206206
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
207207
ctx.Data["CommitCount"] = commits.Len()
208-
ctx.Data["Branch"] = ctx.Repo.BranchName
208+
ctx.Data["RefName"] = ctx.Repo.RefName
209209
ctx.HTML(http.StatusOK, tplCommits)
210210
}
211211

@@ -219,8 +219,7 @@ func FileHistory(ctx *context.Context) {
219219
return
220220
}
221221

222-
branchName := ctx.Repo.BranchName
223-
commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName)
222+
commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(ctx.Repo.RefName, fileName)
224223
if err != nil {
225224
ctx.ServerError("FileCommitsCount", err)
226225
return
@@ -234,7 +233,7 @@ func FileHistory(ctx *context.Context) {
234233
page = 1
235234
}
236235

237-
commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page)
236+
commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(ctx.Repo.RefName, fileName, page)
238237
if err != nil {
239238
ctx.ServerError("CommitsByFileAndRange", err)
240239
return
@@ -248,7 +247,7 @@ func FileHistory(ctx *context.Context) {
248247
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
249248
ctx.Data["FileName"] = fileName
250249
ctx.Data["CommitCount"] = commitsCount
251-
ctx.Data["Branch"] = branchName
250+
ctx.Data["RefName"] = ctx.Repo.RefName
252251

253252
pager := context.NewPagination(int(commitsCount), setting.Git.CommitsRangeSize, page, 5)
254253
pager.SetDefaultParams(ctx)

routers/web/repo/view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
406406
}
407407
defer dataRc.Close()
408408

409-
ctx.Data["Title"] = ctx.Data["Title"].(string) + " - " + ctx.Repo.TreePath + " at " + ctx.Repo.BranchName
409+
ctx.Data["Title"] = ctx.Data["Title"].(string) + " - " + ctx.Repo.TreePath + " at " + ctx.Repo.RefName
410410

411411
fileSize := blob.Size()
412412
ctx.Data["FileIsSymlink"] = entry.IsLink()

templates/repo/branch_dropdown.tmpl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
{{if $release}}
88
{{.root.i18n.Tr "repo.release.compare"}}
99
{{else}}
10-
{{svg "octicon-git-branch"}}
11-
{{if .root.IsViewBranch}}{{.root.i18n.Tr "repo.branch"}}{{else}}{{.root.i18n.Tr "repo.tree"}}{{end}}:
12-
<strong>{{if .root.IsViewBranch}}{{.root.BranchName}}{{else}}{{ShortSha .root.BranchName}}{{end}}</strong>
10+
{{if .root.IsViewTag}}{{svg "octicon-tag"}}{{else}}{{svg "octicon-git-branch"}}{{end}}
11+
{{if .root.IsViewBranch}}{{.root.i18n.Tr "repo.branch"}}{{else if .root.IsViewTag}}{{.root.i18n.Tr "repo.tag"}}{{else}}{{.root.i18n.Tr "repo.tree"}}{{end}}:
12+
<strong>{{if .root.IsViewBranch}}{{.root.BranchName}}{{else if .root.IsViewTag}}{{.root.TagName}}{{else}}{{ShortSha .root.CommitID}}{{end}}</strong>
1313
{{end}}
1414
</span>
1515
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
@@ -66,8 +66,10 @@
6666
<div class="text small">
6767
{{if or .root.IsViewBranch $release}}
6868
{{.root.i18n.Tr "repo.branch.create_from" .root.BranchName}}
69+
{{else if .root.IsViewTag}}
70+
{{.root.i18n.Tr "repo.branch.create_from" .root.TagName}}
6971
{{else}}
70-
{{.root.i18n.Tr "repo.branch.create_from" (ShortSha .root.BranchName)}}
72+
{{.root.i18n.Tr "repo.branch.create_from" (ShortSha .root.CommitID)}}
7173
{{end}}
7274
</div>
7375
</a>

templates/repo/commits_table.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<h4 class="ui top attached header commits-table df ac sb">
22
<div class="commits-table-left df ac">
33
{{if or .PageIsCommits (gt .CommitCount 0)}}
4-
{{.CommitCount}} {{.i18n.Tr "repo.commits.commits"}} {{if .Branch}}({{.Branch}}){{end}}
4+
{{.CommitCount}} {{.i18n.Tr "repo.commits.commits"}} {{if .RefName}}({{.RefName}}){{end}}
55
{{else}}
6-
{{.i18n.Tr "repo.commits.no_commits" $.BaseBranch $.HeadBranch }} {{if .Branch}}({{.Branch}}){{end}}
6+
{{.i18n.Tr "repo.commits.no_commits" $.BaseBranch $.HeadBranch}} {{if .RefName}}({{.RefName}}){{end}}
77
{{end}}
88
</div>
99
<div class="commits-table-right df ac">

templates/repo/sub_menu.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div class="ui two horizontal center link list">
44
{{if and (.Permission.CanRead $.UnitTypeCode) (not .IsEmptyRepo)}}
55
<div class="item{{if .PageIsCommits}} active{{end}}">
6-
<a class="ui" href="{{.RepoLink}}/commits{{if .IsViewBranch}}/branch{{else if .IsViewTag}}/tag{{else if .IsViewCommit}}/commit{{end}}/{{EscapePound .BranchName}}">{{svg "octicon-history"}} <b>{{.CommitsCount}}</b> {{.i18n.Tr (TrN .i18n.Lang .CommitsCount "repo.commit" "repo.commits") }}</a>
6+
<a class="ui" href="{{.RepoLink}}/commits/{{.BranchNameSubURL}}">{{svg "octicon-history"}} <b>{{.CommitsCount}}</b> {{.i18n.Tr (TrN .i18n.Lang .CommitsCount "repo.commit" "repo.commits") }}</a>
77
</div>
88
<div class="item{{if .PageIsBranches}} active{{end}}">
99
<a class="ui" href="{{.RepoLink}}/branches">{{svg "octicon-git-branch"}} <b>{{.BranchesCount}}</b> {{.i18n.Tr (TrN .i18n.Lang .BranchesCount "repo.branch" "repo.branches") }}</a>

0 commit comments

Comments
 (0)