Browse Source

templates/repo: only show Git stats in repository home page (#3518)

Move 'Commits' and 'Releases' tabs down to body.

This patch also reduces page load time for pages that do not need
to use commits count anywhere. Get commits count can hurt
performance badly for huge repositories that has tens of thousands
commits like Linux Kernel.
pull/4280/head
Unknwon 8 years ago
parent
commit
ebc0943713
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 4
      conf/locale/locale_en-US.ini
  2. 4
      modules/bindata/bindata.go
  3. 7
      modules/context/repo.go
  4. 4
      public/config.codekit
  5. 23
      public/css/gogs.css
  6. 6
      public/less/_base.less
  7. 18
      public/less/_repository.less
  8. 2
      routers/repo/pull.go
  9. 6
      routers/repo/release.go
  10. 13
      routers/repo/view.go
  11. 6
      templates/repo/header.tmpl
  12. 12
      templates/repo/home.tmpl

4
conf/locale/locale_en-US.ini

@ -426,8 +426,8 @@ issues = Issues
pulls = Pull Requests pulls = Pull Requests
labels = Labels labels = Labels
milestones = Milestones milestones = Milestones
commits = Commits commits = commits
releases = Releases releases = releases
file_raw = Raw file_raw = Raw
file_history = History file_history = History
file_view_raw = View Raw file_view_raw = View Raw

4
modules/bindata/bindata.go

File diff suppressed because one or more lines are too long

7
modules/context/repo.go

@ -456,13 +456,6 @@ func RepoRef() macaron.Handler {
} }
} }
ctx.Data["PullRequestCtx"] = ctx.Repo.PullRequest ctx.Data["PullRequestCtx"] = ctx.Repo.PullRequest
ctx.Repo.CommitsCount, err = ctx.Repo.Commit.CommitsCount()
if err != nil {
ctx.Handle(500, "CommitsCount", err)
return
}
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
} }
} }

4
public/config.codekit

@ -1,6 +1,6 @@
{ {
"CodeKitInfo": "This is a CodeKit 2.x project configuration file. It is designed to sync project settings across multiple machines. MODIFYING THE CONTENTS OF THIS FILE IS A POOR LIFE DECISION. If you do so, you will likely cause CodeKit to crash. This file is not useful unless accompanied by the project that created it in CodeKit 2. This file is not backwards-compatible with CodeKit 1.x. For more information, see: http:\/\/incident57.com\/codekit", "CodeKitInfo": "This is a CodeKit 2.x project configuration file. It is designed to sync project settings across multiple machines. MODIFYING THE CONTENTS OF THIS FILE IS A POOR LIFE DECISION. If you do so, you will likely cause CodeKit to crash. This file is not useful unless accompanied by the project that created it in CodeKit 2. This file is not backwards-compatible with CodeKit 1.x. For more information, see: http:\/\/incident57.com\/codekit",
"creatorBuild": "19115", "creatorBuild": "19127",
"files": { "files": {
"\/css\/github.min.css": { "\/css\/github.min.css": {
"fileType": 16, "fileType": 16,
@ -66,7 +66,7 @@
"fileType": 32768, "fileType": 32768,
"ignore": 0, "ignore": 0,
"ignoreWasSetByUser": 0, "ignoreWasSetByUser": 0,
"initialSize": 4048, "initialSize": 514087,
"inputAbbreviatedPath": "\/img\/avatar_default.png", "inputAbbreviatedPath": "\/img\/avatar_default.png",
"outputAbbreviatedPath": "\/img\/avatar_default.png", "outputAbbreviatedPath": "\/img\/avatar_default.png",
"outputPathIsOutsideProject": 0, "outputPathIsOutsideProject": 0,

23
public/css/gogs.css

@ -125,6 +125,11 @@ code.wrap {
.ui.form .ui.button { .ui.form .ui.button {
font-weight: normal; font-weight: normal;
} }
.ui.menu,
.ui.vertical.menu,
.ui.segment {
box-shadow: none;
}
.ui .text.red { .ui .text.red {
color: #d95c5c !important; color: #d95c5c !important;
} }
@ -1235,6 +1240,20 @@ footer .ui.language .menu {
padding: 8px 10px; padding: 8px 10px;
font-weight: normal; font-weight: normal;
} }
.repository.file.list #git-stats {
padding: 5px 10px;
line-height: 0;
}
.repository.file.list #git-stats .list {
width: 100%;
}
.repository.file.list #git-stats .list .item {
margin-left: 0;
width: 50%;
}
.repository.file.list #git-stats .list .item .text b {
font-size: 15px;
}
.repository.file.list #repo-files-table thead th { .repository.file.list #repo-files-table thead th {
padding-top: 8px; padding-top: 8px;
padding-bottom: 5px; padding-bottom: 5px;
@ -2427,10 +2446,6 @@ footer .ui.language .menu {
.settings .content { .settings .content {
margin-top: 2px; margin-top: 2px;
} }
.settings .content > .header,
.settings .content .segment {
box-shadow: 0 1px 2px 0 rgba(34, 36, 38, 0.15);
}
.settings .key.list .item:not(:first-child) { .settings .key.list .item:not(:first-child) {
border-top: 1px solid #eaeaea; border-top: 1px solid #eaeaea;
} }

6
public/less/_base.less

@ -135,6 +135,12 @@ pre, code {
} }
} }
&.menu,
&.vertical.menu,
&.segment {
box-shadow: none;
}
.text { .text {
&.red { &.red {
color: #d95c5c !important; color: #d95c5c !important;

18
public/less/_repository.less

@ -167,6 +167,20 @@
font-weight: normal; font-weight: normal;
} }
} }
#git-stats {
padding: 5px 10px;
line-height: 0;
.list {
width: 100%;
.item {
margin-left: 0;
width: 50%;
.text b {
font-size: 15px;
}
}
}
}
#repo-files-table { #repo-files-table {
thead { thead {
@ -1476,10 +1490,6 @@
.settings { .settings {
.content { .content {
margin-top: 2px; margin-top: 2px;
>.header,
.segment {
box-shadow: 0 1px 2px 0 rgba(34,36,38,.15);
}
} }
.key.list { .key.list {
.item:not(:first-child) { .item:not(:first-child) {

2
routers/repo/pull.go

@ -280,7 +280,7 @@ func ViewPullCommits(ctx *context.Context) {
commits = models.ValidateCommitsWithEmails(commits) commits = models.ValidateCommitsWithEmails(commits)
ctx.Data["Commits"] = commits ctx.Data["Commits"] = commits
ctx.Data["CommitCount"] = commits.Len() ctx.Data["CommitsCount"] = commits.Len()
ctx.HTML(200, PULL_COMMITS) ctx.HTML(200, PULL_COMMITS)
} }

6
routers/repo/release.go

@ -23,12 +23,6 @@ const (
// calReleaseNumCommitsBehind calculates given release has how many commits behind release target. // calReleaseNumCommitsBehind calculates given release has how many commits behind release target.
func calReleaseNumCommitsBehind(repoCtx *context.Repository, release *models.Release, countCache map[string]int64) error { func calReleaseNumCommitsBehind(repoCtx *context.Repository, release *models.Release, countCache map[string]int64) error {
// Fast return if release target is same as default branch.
if repoCtx.BranchName == release.Target {
release.NumCommitsBehind = repoCtx.CommitsCount - release.NumCommits
return nil
}
// Get count if not exists // Get count if not exists
if _, ok := countCache[release.Target]; !ok { if _, ok := countCache[release.Target]; !ok {
if repoCtx.GitRepo.IsBranchExist(release.Target) { if repoCtx.GitRepo.IsBranchExist(release.Target) {

13
routers/repo/view.go

@ -238,9 +238,22 @@ func Home(ctx *context.Context) {
treeLink := branchLink treeLink := branchLink
rawLink := ctx.Repo.RepoLink + "/raw/" + ctx.Repo.BranchName rawLink := ctx.Repo.RepoLink + "/raw/" + ctx.Repo.BranchName
isRootDir := false
if len(ctx.Repo.TreePath) > 0 { if len(ctx.Repo.TreePath) > 0 {
treeLink += "/" + ctx.Repo.TreePath treeLink += "/" + ctx.Repo.TreePath
} else {
isRootDir = true
// Only show Git stats panel when view root directory
var err error
ctx.Repo.CommitsCount, err = ctx.Repo.Commit.CommitsCount()
if err != nil {
ctx.Handle(500, "CommitsCount", err)
return
}
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
} }
ctx.Data["PageIsRepoHome"] = isRootDir
// Get current entry user currently looking at. // Get current entry user currently looking at.
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath) entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)

6
templates/repo/header.tmpl

@ -62,12 +62,6 @@
<i class="octicon octicon-git-pull-request"></i> {{.i18n.Tr "repo.pulls"}} <span class="ui {{if not .Repository.NumOpenPulls}}gray{{else}}blue{{end}} small label">{{.Repository.NumOpenPulls}}</span> <i class="octicon octicon-git-pull-request"></i> {{.i18n.Tr "repo.pulls"}} <span class="ui {{if not .Repository.NumOpenPulls}}gray{{else}}blue{{end}} small label">{{.Repository.NumOpenPulls}}</span>
</a> </a>
{{end}} {{end}}
<a class="{{if (or (.PageIsCommits) (.PageIsDiff))}}active{{end}} item" href="{{.RepoLink}}/commits/{{EscapePound .BranchName}}">
<i class="octicon octicon-history"></i> {{.i18n.Tr "repo.commits"}} <span class="ui {{if not .CommitsCount}}gray{{else}}blue{{end}} small label">{{.CommitsCount}}</span>
</a>
<a class="{{if .PageIsReleaseList}}active{{end}} item" href="{{.RepoLink}}/releases">
<i class="octicon octicon-tag"></i> {{.i18n.Tr "repo.releases"}} <span class="ui {{if not .Repository.NumTags}}gray{{else}}blue{{end}} small label">{{.Repository.NumTags}}</span>
</a>
{{if .Repository.EnableWiki}} {{if .Repository.EnableWiki}}
<a class="{{if .PageIsWiki}}active{{end}} item" href="{{.RepoLink}}/wiki"> <a class="{{if .PageIsWiki}}active{{end}} item" href="{{.RepoLink}}/wiki">
<i class="octicon octicon-book"></i> {{.i18n.Tr "repo.wiki"}} <i class="octicon octicon-book"></i> {{.i18n.Tr "repo.wiki"}}

12
templates/repo/home.tmpl

@ -3,10 +3,22 @@
{{template "repo/header" .}} {{template "repo/header" .}}
<div class="ui container"> <div class="ui container">
{{template "base/alert" .}} {{template "base/alert" .}}
{{if .PageIsRepoHome}}
<p id="repo-desc"> <p id="repo-desc">
{{if .Repository.DescriptionHtml}}<span class="description has-emoji">{{.Repository.DescriptionHtml}}</span>{{else}}<span class="no-description text-italic">{{.i18n.Tr "repo.no_desc"}}</span>{{end}} {{if .Repository.DescriptionHtml}}<span class="description has-emoji">{{.Repository.DescriptionHtml}}</span>{{else}}<span class="no-description text-italic">{{.i18n.Tr "repo.no_desc"}}</span>{{end}}
<a class="link" href="{{.Repository.Website}}">{{.Repository.Website}}</a> <a class="link" href="{{.Repository.Website}}">{{.Repository.Website}}</a>
</p> </p>
<div class="ui segment" id="git-stats">
<div class="ui two horizontal center link list">
<div class="item">
<a href="{{.RepoLink}}/commits/{{EscapePound .BranchName}}"><span class="ui text black"><i class="octicon octicon-history"></i> <b>{{.CommitsCount}}</b> {{.i18n.Tr "repo.commits"}}</span> </a>
</div>
<div class="item">
<a href="{{.RepoLink}}/releases"><span class="ui text black"><i class="octicon octicon-tag"></i> <b>{{.Repository.NumTags}}</b> {{.i18n.Tr "repo.releases"}}</span> </a>
</div>
</div>
</div>
{{end}}
<div class="ui secondary menu"> <div class="ui secondary menu">
{{if .PullRequestCtx.Allowed}} {{if .PullRequestCtx.Allowed}}
<div class="fitted item"> <div class="fitted item">

Loading…
Cancel
Save