diff --git a/modules/cache/cache_test.go b/modules/cache/cache_test.go index e0b82f86f2..d0352947a8 100644 --- a/modules/cache/cache_test.go +++ b/modules/cache/cache_test.go @@ -43,7 +43,7 @@ func TestTest(t *testing.T) { elapsed, err := Test() assert.NoError(t, err) // mem cache should take from 300ns up to 1ms on modern hardware ... - assert.Less(t, elapsed, SlowCacheThreshold) + assert.Less(t, elapsed, time.Millisecond) } func TestGetCache(t *testing.T) { diff --git a/templates/repo/branch_dropdown.tmpl b/templates/repo/branch_dropdown.tmpl index c4f73875f2..43568732fb 100644 --- a/templates/repo/branch_dropdown.tmpl +++ b/templates/repo/branch_dropdown.tmpl @@ -1,87 +1,57 @@ {{/* Attributes: -* root * ContainerClasses -* (TODO: search "branch_dropdown" in the template directory) +* Repository +* CurrentRefType: eg. "branch", "tag" +* CurrentRefShortName: eg. "master", "v1.0" +* CurrentTreePath +* RefLinkTemplate: redirect to the link when a branch/tag is selected +* RefFormActionTemplate: change the parent form's action when a branch/tag is selected +* DropdownFixedText: the text to show in the dropdown (mainly used by "release page"), if empty, the text will be the branch/tag name +* ShowTabBranches +* ShowTabTagsTab +* AllowCreateNewRef + +Search "repo/branch_dropdown" in the template directory to find all occurrences. */}} -{{$defaultSelectedRefName := $.root.BranchName}} -{{if and .root.IsViewTag (not .noTag)}} - {{$defaultSelectedRefName = .root.TagName}} -{{end}} -{{if eq $defaultSelectedRefName ""}} - {{$defaultSelectedRefName = $.root.Repository.DefaultBranch}} -{{end}} +
- const data = { - 'textReleaseCompare': {{ctx.Locale.Tr "repo.release.compare"}}, - 'textCreateTag': {{ctx.Locale.Tr "repo.tag.create_tag"}}, - 'textCreateBranch': {{ctx.Locale.Tr "repo.branch.create_branch"}}, - 'textCreateBranchFrom': {{ctx.Locale.Tr "repo.branch.create_from"}}, - 'textBranches': {{ctx.Locale.Tr "repo.branches"}}, - 'textTags': {{ctx.Locale.Tr "repo.tags"}}, - 'textDefaultBranchLabel': {{ctx.Locale.Tr "repo.default_branch_label"}}, - - 'mode': '{{if or .root.IsViewTag .isTag}}tags{{else}}branches{{end}}', - 'showBranchesInDropdown': {{$showBranchesInDropdown}}, - 'searchFieldPlaceholder': '{{if $.noTag}}{{ctx.Locale.Tr "repo.pulls.filter_branch"}}{{else if $showBranchesInDropdown}}{{ctx.Locale.Tr "repo.filter_branch_and_tag"}}{{else}}{{ctx.Locale.Tr "repo.find_tag"}}{{end}}...', - 'branchForm': {{$.branchForm}}, - 'disableCreateBranch': {{if .disableCreateBranch}}{{.disableCreateBranch}}{{else}}{{not .root.CanCreateBranch}}{{end}}, - 'setAction': {{.setAction}}, - 'submitForm': {{.submitForm}}, - 'viewType': {{$type}}, - 'refName': {{if and .root.IsViewTag (not .noTag)}}{{.root.TagName}}{{else if .root.IsViewBranch}}{{.root.BranchName}}{{else}}{{ShortSha .root.CommitID}}{{end}}, - 'commitIdShort': {{ShortSha .root.CommitID}}, - 'tagName': {{.root.TagName}}, - 'branchName': {{.root.BranchName}}, - 'noTag': {{.noTag}}, - 'defaultSelectedRefName': {{$defaultSelectedRefName}}, - 'repoDefaultBranch': {{.root.Repository.DefaultBranch}}, - 'enableFeed': {{.root.EnableFeed}}, - 'rssURLPrefix': '{{$.root.RepoLink}}/rss/branch/', - 'branchURLPrefix': '{{if .branchURLPrefix}}{{.branchURLPrefix}}{{else}}{{$.root.RepoLink}}/{{if $.root.PageIsCommits}}commits{{else}}src{{end}}/branch/{{end}}', - 'branchURLSuffix': '{{if .branchURLSuffix}}{{.branchURLSuffix}}{{else}}{{if $.root.TreePath}}/{{PathEscapeSegments $.root.TreePath}}{{end}}{{end}}', - 'tagURLPrefix': '{{if .tagURLPrefix}}{{.tagURLPrefix}}{{else if .release}}{{$.root.RepoLink}}/compare/{{else}}{{$.root.RepoLink}}/{{if $.root.PageIsCommits}}commits{{else}}src{{end}}/tag/{{end}}', - 'tagURLSuffix': '{{if .tagURLSuffix}}{{.tagURLSuffix}}{{else if .release}}...{{if .release.IsDraft}}{{PathEscapeSegments .release.Target}}{{else}}{{if .release.TagName}}{{PathEscapeSegments .release.TagName}}{{else}}{{PathEscapeSegments .release.Sha1}}{{end}}{{end}}{{else}}{{if $.root.TreePath}}/{{PathEscapeSegments $.root.TreePath}}{{end}}{{end}}', - 'repoLink': {{.root.RepoLink}}, - 'treePath': {{.root.TreePath}}, - 'branchNameSubURL': {{.root.BranchNameSubURL}}, - 'noResults': {{ctx.Locale.Tr "no_results_found"}}, - }; - {{if .release}} - data.release = { - 'tagName': {{.release.TagName}}, - }; - {{end}} - window.config.pageData.branchDropdownDataList = window.config.pageData.branchDropdownDataList || []; - window.config.pageData.branchDropdownDataList.push(data); - - -
+ data-enable-feed="{{ctx.RootData.EnableFeed}}" +> {{/* show dummy elements before Vue componment is mounted, this code must match the code in BranchTagSelector.vue */}}

- {{template "repo/branch_dropdown" dict "root" . - "noTag" true "disableCreateBranch" true - "branchForm" "branch-dropdown-form" - "branchURLPrefix" (printf "%s/_cherrypick/%s/" $.RepoLink .CommitID) "branchURLSuffix" "" - "setAction" true "submitForm" true}} -
- - + + + {{template "repo/branch_dropdown" dict + "Repository" .Repository + "ShowTabBranches" true + "CurrentRefType" "branch" + "CurrentRefShortName" (Iif $.BranchName $.Repository.DefaultBranch) + "RefFormActionTemplate" (print "{RepoLink}/_cherrypick/" .CommitID "/{RefShortName}") + }}
diff --git a/templates/repo/commits.tmpl b/templates/repo/commits.tmpl index 6bce585774..e79f3d7751 100644 --- a/templates/repo/commits.tmpl +++ b/templates/repo/commits.tmpl @@ -5,7 +5,24 @@ {{template "repo/sub_menu" .}}
- {{template "repo/branch_dropdown" dict "root" .}} + + {{$branchDropdownCurrentRefType := "branch"}} + {{$branchDropdownCurrentRefShortName := .BranchName}} + {{if .IsViewTag}} + {{$branchDropdownCurrentRefType := "tag"}} + {{$branchDropdownCurrentRefShortName := .TagName}} + {{end}} + {{template "repo/branch_dropdown" dict + "Repository" .Repository + "ShowTabBranches" true + "ShowTabTags" true + "CurrentRefType" $branchDropdownCurrentRefType + "CurrentRefShortName" $branchDropdownCurrentRefShortName + "CurrentTreePath" .TreePath + "RefLinkTemplate" "{RepoLink}/commits/{RefType}/{RefShortName}/{TreePath}" + "AllowCreateNewRef" .CanCreateBranch + }} + {{svg "octicon-git-branch"}} {{ctx.Locale.Tr "repo.commit_graph"}} diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 12c4a17234..c2f1be782a 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -47,7 +47,22 @@ {{$isHomepage := (eq $n 0)}}
- {{template "repo/branch_dropdown" dict "root" .}} + {{$branchDropdownCurrentRefType := "branch"}} + {{$branchDropdownCurrentRefShortName := .BranchName}} + {{if .IsViewTag}} + {{$branchDropdownCurrentRefType := "tag"}} + {{$branchDropdownCurrentRefShortName := .TagName}} + {{end}} + {{template "repo/branch_dropdown" dict + "Repository" .Repository + "ShowTabBranches" true + "ShowTabTags" true + "CurrentRefType" $branchDropdownCurrentRefType + "CurrentRefShortName" $branchDropdownCurrentRefShortName + "CurrentTreePath" .TreePath + "RefLinkTemplate" "{RepoLink}/src/{RefType}/{RefShortName}/{TreePath}" + "AllowCreateNewRef" .CanCreateBranch + }} {{if and .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}} {{$cmpBranch := ""}} {{if ne .Repository.ID .BaseRepo.ID}} diff --git a/templates/repo/release/list.tmpl b/templates/repo/release/list.tmpl index 7e13dac0dc..efaac4432a 100644 --- a/templates/repo/release/list.tmpl +++ b/templates/repo/release/list.tmpl @@ -12,7 +12,20 @@ {{svg "octicon-tag" 16 "tw-mr-1"}}{{$release.TagName}} {{if and $release.Sha1 ($.Permission.CanRead ctx.Consts.RepoUnitTypeCode)}} {{svg "octicon-git-commit" 16 "tw-mr-1"}}{{ShortSha $release.Sha1}} - {{template "repo/branch_dropdown" dict "root" $ "release" $release}} + {{$compareTarget := ""}} + {{if $release.IsDraft}} + {{$compareTarget = $release.Target}} + {{else if $release.TagName}} + {{$compareTarget = $release.TagName}} + {{else}} + {{$compareTarget = $release.Sha1}} + {{end}} + {{template "repo/branch_dropdown" dict + "Repository" $.Repository + "ShowTabTags" true + "DropdownFixedText" (ctx.Locale.Tr "repo.release.compare") + "RefLinkTemplate" (print "{RepoLink}/compare/{RefShortName}..." (PathEscapeSegments $compareTarget)) + }} {{end}}
diff --git a/web_src/js/components/RepoBranchTagSelector.vue b/web_src/js/components/RepoBranchTagSelector.vue index 7aecb1e351..05f7b59a66 100644 --- a/web_src/js/components/RepoBranchTagSelector.vue +++ b/web_src/js/components/RepoBranchTagSelector.vue @@ -1,244 +1,217 @@