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.
Unknwon 8 years ago
parent
commit
ebc0943713

+ 2 - 2
conf/locale/locale_en-US.ini

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

File diff suppressed because it is too large
+ 0 - 0
modules/bindata/bindata.go


+ 0 - 7
modules/context/repo.go

@@ -456,13 +456,6 @@ func RepoRef() macaron.Handler {
 			}
 		}
 		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
 	}
 }
 

+ 2 - 2
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",
-"creatorBuild": "19115",
+"creatorBuild": "19127",
 "files": {
 	"\/css\/github.min.css": {
 		"fileType": 16,
@@ -66,7 +66,7 @@
 		"fileType": 32768,
 		"ignore": 0,
 		"ignoreWasSetByUser": 0,
-		"initialSize": 4048,
+		"initialSize": 514087,
 		"inputAbbreviatedPath": "\/img\/avatar_default.png",
 		"outputAbbreviatedPath": "\/img\/avatar_default.png",
 		"outputPathIsOutsideProject": 0,

+ 19 - 4
public/css/gogs.css

@@ -125,6 +125,11 @@ code.wrap {
 .ui.form .ui.button {
   font-weight: normal;
 }
+.ui.menu,
+.ui.vertical.menu,
+.ui.segment {
+  box-shadow: none;
+}
 .ui .text.red {
   color: #d95c5c !important;
 }
@@ -1235,6 +1240,20 @@ footer .ui.language .menu {
   padding: 8px 10px;
   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 {
   padding-top: 8px;
   padding-bottom: 5px;
@@ -2427,10 +2446,6 @@ footer .ui.language .menu {
 .settings .content {
   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) {
   border-top: 1px solid #eaeaea;
 }

+ 6 - 0
public/less/_base.less

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

+ 14 - 4
public/less/_repository.less

@@ -167,6 +167,20 @@
 				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 {
 			thead {
@@ -1476,10 +1490,6 @@
 .settings {
 	.content {
 		margin-top: 2px;
-		>.header,
-		.segment {
-			box-shadow: 0 1px 2px 0 rgba(34,36,38,.15);
-		}
 	}
 	.key.list {
 		.item:not(:first-child) {

+ 1 - 1
routers/repo/pull.go

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

+ 0 - 6
routers/repo/release.go

@@ -23,12 +23,6 @@ const (
 
 // calReleaseNumCommitsBehind calculates given release has how many commits behind release target.
 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
 	if _, ok := countCache[release.Target]; !ok {
 		if repoCtx.GitRepo.IsBranchExist(release.Target) {

+ 13 - 0
routers/repo/view.go

@@ -238,9 +238,22 @@ func Home(ctx *context.Context) {
 	treeLink := branchLink
 	rawLink := ctx.Repo.RepoLink + "/raw/" + ctx.Repo.BranchName
 
+	isRootDir := false
 	if len(ctx.Repo.TreePath) > 0 {
 		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.
 	entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)

+ 0 - 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>
 				</a>
 			{{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}}
 				<a class="{{if .PageIsWiki}}active{{end}} item" href="{{.RepoLink}}/wiki">
 					<i class="octicon octicon-book"></i> {{.i18n.Tr "repo.wiki"}}

+ 16 - 4
templates/repo/home.tmpl

@@ -3,10 +3,22 @@
 	{{template "repo/header" .}}
 	<div class="ui container">
 		{{template "base/alert" .}}
-		<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}}
-			<a class="link" href="{{.Repository.Website}}">{{.Repository.Website}}</a>
-		</p>
+		{{if .PageIsRepoHome}}
+			<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}}
+				<a class="link" href="{{.Repository.Website}}">{{.Repository.Website}}</a>
+			</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">
 			{{if .PullRequestCtx.Allowed}}
 				<div class="fitted item">

Some files were not shown because too many files changed in this diff