Skip to content

Commit ea42d3c

Browse files
authored
Fixed commit count. (#17698)
Added "Tag" label. Unified branch, tag and commit name.
1 parent 3c4724d commit ea42d3c

File tree

8 files changed

+35
-32
lines changed

8 files changed

+35
-32
lines changed

modules/context/repo.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type Repository struct {
5959
Commit *git.Commit
6060
Tag *git.Tag
6161
GitRepo *git.Repository
62+
RefName string
6263
BranchName string
6364
TagName string
6465
TreePath string
@@ -191,9 +192,9 @@ func (r *Repository) BranchNameSubURL() string {
191192
case r.IsViewBranch:
192193
return "branch/" + util.PathEscapeSegments(r.BranchName)
193194
case r.IsViewTag:
194-
return "tag/" + util.PathEscapeSegments(r.BranchName)
195+
return "tag/" + util.PathEscapeSegments(r.TagName)
195196
case r.IsViewCommit:
196-
return "commit/" + util.PathEscapeSegments(r.BranchName)
197+
return "commit/" + util.PathEscapeSegments(r.CommitID)
197198
}
198199
log.Error("Unknown view type for repo: %v", r)
199200
return ""
@@ -563,8 +564,6 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
563564
ctx.Data["Branches"] = brs
564565
ctx.Data["BranchesCount"] = len(brs)
565566

566-
ctx.Data["TagName"] = ctx.Repo.TagName
567-
568567
// If not branch selected, try default one.
569568
// If default branch doesn't exists, fall back to some other branch.
570569
if len(ctx.Repo.BranchName) == 0 {
@@ -573,9 +572,9 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
573572
} else if len(brs) > 0 {
574573
ctx.Repo.BranchName = brs[0]
575574
}
575+
ctx.Repo.RefName = ctx.Repo.BranchName
576576
}
577577
ctx.Data["BranchName"] = ctx.Repo.BranchName
578-
ctx.Data["CommitID"] = ctx.Repo.CommitID
579578

580579
// People who have push access or have forked repository can propose a new pull request.
581580
canPush := ctx.Repo.CanWrite(unit_model.TypeCode) || (ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID))
@@ -781,7 +780,6 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
781780
// Get default branch.
782781
if len(ctx.Params("*")) == 0 {
783782
refName = ctx.Repo.Repository.DefaultBranch
784-
ctx.Repo.BranchName = refName
785783
if !ctx.Repo.GitRepo.IsBranchExist(refName) {
786784
brs, _, err := ctx.Repo.GitRepo.GetBranches(0, 0)
787785
if err != nil {
@@ -795,6 +793,8 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
795793
}
796794
refName = brs[0]
797795
}
796+
ctx.Repo.RefName = refName
797+
ctx.Repo.BranchName = refName
798798
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName)
799799
if err != nil {
800800
ctx.ServerError("GetBranchCommit", err)
@@ -805,7 +805,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
805805

806806
} else {
807807
refName = getRefName(ctx, refType)
808-
ctx.Repo.BranchName = refName
808+
ctx.Repo.RefName = refName
809809
isRenamedBranch, has := ctx.Data["IsRenamedBranch"].(bool)
810810
if isRenamedBranch && has {
811811
renamedBranchName := ctx.Data["RenamedBranchName"].(string)
@@ -817,6 +817,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
817817

818818
if refType.RefTypeIncludesBranches() && ctx.Repo.GitRepo.IsBranchExist(refName) {
819819
ctx.Repo.IsViewBranch = true
820+
ctx.Repo.BranchName = refName
820821

821822
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName)
822823
if err != nil {
@@ -827,6 +828,8 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
827828

828829
} else if refType.RefTypeIncludesTags() && ctx.Repo.GitRepo.IsTagExist(refName) {
829830
ctx.Repo.IsViewTag = true
831+
ctx.Repo.TagName = refName
832+
830833
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(refName)
831834
if err != nil {
832835
ctx.ServerError("GetTagCommit", err)
@@ -870,6 +873,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
870873

871874
ctx.Data["BranchName"] = ctx.Repo.BranchName
872875
ctx.Data["BranchNameSubURL"] = ctx.Repo.BranchNameSubURL()
876+
ctx.Data["TagName"] = ctx.Repo.TagName
873877
ctx.Data["CommitID"] = ctx.Repo.CommitID
874878
ctx.Data["TreePath"] = ctx.Repo.TreePath
875879
ctx.Data["IsViewBranch"] = ctx.Repo.IsViewBranch

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,7 @@ release = Release
971971
releases = Releases
972972
tag = Tag
973973
released_this = released this
974+
file.title = %s at %s
974975
file_raw = Raw
975976
file_history = History
976977
file_view_source = View Source

routers/web/repo/branch.go

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

346346
if form.CreateTag {
347-
if ctx.Repo.IsViewTag {
348-
err = release_service.CreateNewTag(ctx.User, ctx.Repo.Repository, ctx.Repo.CommitID, form.NewBranchName, "")
349-
} else {
350-
err = release_service.CreateNewTag(ctx.User, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName, "")
347+
target := ctx.Repo.CommitID
348+
if ctx.Repo.IsViewBranch {
349+
target = ctx.Repo.BranchName
351350
}
351+
err = release_service.CreateNewTag(ctx.User, ctx.Repo.Repository, target, form.NewBranchName, "")
352352
} else if ctx.Repo.IsViewBranch {
353353
err = repo_service.CreateNewBranch(ctx.User, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName)
354-
} else if ctx.Repo.IsViewTag {
355-
err = repo_service.CreateNewBranchFromCommit(ctx.User, ctx.Repo.Repository, ctx.Repo.CommitID, form.NewBranchName)
356354
} else {
357-
err = repo_service.CreateNewBranchFromCommit(ctx.User, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName)
355+
err = repo_service.CreateNewBranchFromCommit(ctx.User, ctx.Repo.Repository, ctx.Repo.CommitID, form.NewBranchName)
358356
}
359357
if err != nil {
360358
if models.IsErrTagAlreadyExists(err) {

routers/web/repo/commit.go

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

8282
pager := context.NewPagination(int(commitsCount), setting.Git.CommitsRangeSize, page, 5)
8383
pager.SetDefaultParams(ctx)
@@ -153,7 +153,7 @@ func Graph(ctx *context.Context) {
153153
ctx.Data["Username"] = ctx.Repo.Owner.Name
154154
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
155155
ctx.Data["CommitCount"] = commitsCount
156-
ctx.Data["Branch"] = ctx.Repo.BranchName
156+
ctx.Data["RefName"] = ctx.Repo.RefName
157157
paginator := context.NewPagination(int(graphCommitsCount), setting.UI.GraphMaxCommitNum, page, 5)
158158
paginator.AddParam(ctx, "mode", "Mode")
159159
paginator.AddParam(ctx, "hide-pr-refs", "HidePRRefs")
@@ -199,7 +199,7 @@ func SearchCommits(ctx *context.Context) {
199199
}
200200
ctx.Data["Username"] = ctx.Repo.Owner.Name
201201
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
202-
ctx.Data["Branch"] = ctx.Repo.BranchName
202+
ctx.Data["RefName"] = ctx.Repo.RefName
203203
ctx.HTML(http.StatusOK, tplCommits)
204204
}
205205

@@ -213,8 +213,7 @@ func FileHistory(ctx *context.Context) {
213213
return
214214
}
215215

216-
branchName := ctx.Repo.BranchName
217-
commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName)
216+
commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(ctx.Repo.RefName, fileName)
218217
if err != nil {
219218
ctx.ServerError("FileCommitsCount", err)
220219
return
@@ -228,7 +227,7 @@ func FileHistory(ctx *context.Context) {
228227
page = 1
229228
}
230229

231-
commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page)
230+
commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(ctx.Repo.RefName, fileName, page)
232231
if err != nil {
233232
ctx.ServerError("CommitsByFileAndRange", err)
234233
return
@@ -239,7 +238,7 @@ func FileHistory(ctx *context.Context) {
239238
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
240239
ctx.Data["FileName"] = fileName
241240
ctx.Data["CommitCount"] = commitsCount
242-
ctx.Data["Branch"] = branchName
241+
ctx.Data["RefName"] = ctx.Repo.RefName
243242

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

routers/web/repo/view.go

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

374-
ctx.Data["Title"] = ctx.Data["Title"].(string) + " - " + ctx.Repo.TreePath + " at " + ctx.Repo.BranchName
374+
ctx.Data["Title"] = ctx.Data["Title"].(string) + " - " + ctx.Tr("repo.file.title", ctx.Repo.TreePath, ctx.Repo.RefName)
375375

376376
fileSize := blob.Size()
377377
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: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
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}}
5-
{{else if .IsNothingToCompare }}
6-
{{.i18n.Tr "repo.commits.nothing_to_compare" }} {{if .Branch}}({{.Branch}}){{end}}
7-
4+
{{.CommitCount}} {{.i18n.Tr "repo.commits.commits"}} {{if .RefName}}({{.RefName}}){{end}}
5+
{{else if .IsNothingToCompare}}
6+
{{.i18n.Tr "repo.commits.nothing_to_compare" }} {{if .RefName}}({{.RefName}}){{end}}
87
{{else}}
9-
{{.i18n.Tr "repo.commits.no_commits" $.BaseBranch $.HeadBranch }} {{if .Branch}}({{.Branch}}){{end}}
8+
{{.i18n.Tr "repo.commits.no_commits" $.BaseBranch $.HeadBranch}} {{if .RefName}}({{.RefName}}){{end}}
109
{{end}}
1110
</div>
1211
<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}}/{{PathEscapeSegments .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)