mirror of https://github.com/gogs/gogs.git
commits: able to specify pageSize dynamically (#3965)
Usage: <url>?page={page}&pageSize={pageSize} Also avoid/removed getting total commits count for pagination, users are only allowed navigation by 'newer' and 'older'.pull/4150/merge
parent
685737b816
commit
c69900325d
|
@ -95,7 +95,7 @@ func checkVersion() {
|
|||
{"github.com/go-macaron/toolbox", toolbox.Version, "0.1.0"},
|
||||
{"gopkg.in/ini.v1", ini.Version, "1.8.4"},
|
||||
{"gopkg.in/macaron.v1", macaron.Version, "1.1.7"},
|
||||
{"github.com/gogits/git-module", git.Version, "0.4.10"},
|
||||
{"github.com/gogits/git-module", git.Version, "0.4.11"},
|
||||
{"github.com/gogits/go-gogs-client", gogs.Version, "0.12.1"},
|
||||
}
|
||||
for _, c := range checkers {
|
||||
|
|
|
@ -474,6 +474,7 @@ editor.add_subdir = Add subdirectory...
|
|||
editor.unable_to_upload_files = Failed to upload files to '%s' with error: %v
|
||||
editor.upload_files_to_dir = Upload files to '%s'
|
||||
|
||||
commits.commit_history = Commit History
|
||||
commits.commits = Commits
|
||||
commits.search = Search commits
|
||||
commits.find = Find
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -8,8 +8,6 @@ import (
|
|||
"container/list"
|
||||
"path"
|
||||
|
||||
"github.com/Unknwon/paginater"
|
||||
|
||||
"github.com/gogits/git-module"
|
||||
|
||||
"github.com/gogits/gogs/models"
|
||||
|
@ -43,38 +41,54 @@ func RenderIssueLinks(oldCommits *list.List, repoLink string) *list.List {
|
|||
return newCommits
|
||||
}
|
||||
|
||||
func Commits(ctx *context.Context) {
|
||||
func renderCommits(ctx *context.Context, filename string) {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.commits.commit_history") + " · " + ctx.Repo.Repository.FullName()
|
||||
ctx.Data["PageIsCommits"] = true
|
||||
|
||||
commitsCount, err := ctx.Repo.Commit.CommitsCount()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetCommitsCount", err)
|
||||
return
|
||||
}
|
||||
|
||||
page := ctx.QueryInt("page")
|
||||
if page <= 1 {
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
ctx.Data["Page"] = paginater.New(int(commitsCount), git.CommitsRangeSize, page, 5)
|
||||
pageSize := ctx.QueryInt("pageSize")
|
||||
if pageSize < 1 {
|
||||
pageSize = git.DEFAULT_COMMITS_PAGE_SIZE
|
||||
}
|
||||
|
||||
// Both `git log branchName` and `git log commitId` work.
|
||||
commits, err := ctx.Repo.Commit.CommitsByRange(page)
|
||||
// Both 'git log branchName' and 'git log commitID' work.
|
||||
var err error
|
||||
var commits *list.List
|
||||
if len(filename) == 0 {
|
||||
commits, err = ctx.Repo.Commit.CommitsByRangeSize(page, pageSize)
|
||||
} else {
|
||||
commits, err = ctx.Repo.GitRepo.CommitsByFileAndRangeSize(ctx.Repo.BranchName, filename, page, pageSize)
|
||||
}
|
||||
if err != nil {
|
||||
ctx.Handle(500, "CommitsByRange", err)
|
||||
ctx.Handle(500, "CommitsByRangeSize/CommitsByFileAndRangeSize", err)
|
||||
return
|
||||
}
|
||||
commits = RenderIssueLinks(commits, ctx.Repo.RepoLink)
|
||||
commits = models.ValidateCommitsWithEmails(commits)
|
||||
ctx.Data["Commits"] = commits
|
||||
|
||||
if page > 1 {
|
||||
ctx.Data["HasPrevious"] = true
|
||||
ctx.Data["PreviousPage"] = page - 1
|
||||
}
|
||||
if commits.Len() == pageSize {
|
||||
ctx.Data["HasNext"] = true
|
||||
ctx.Data["NextPage"] = page + 1
|
||||
}
|
||||
ctx.Data["PageSize"] = pageSize
|
||||
|
||||
ctx.Data["Username"] = ctx.Repo.Owner.Name
|
||||
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
|
||||
ctx.Data["CommitCount"] = commitsCount
|
||||
ctx.Data["Branch"] = ctx.Repo.BranchName
|
||||
ctx.HTML(200, COMMITS)
|
||||
}
|
||||
|
||||
func Commits(ctx *context.Context) {
|
||||
renderCommits(ctx, "")
|
||||
}
|
||||
|
||||
func SearchCommits(ctx *context.Context) {
|
||||
ctx.Data["PageIsCommits"] = true
|
||||
|
||||
|
@ -96,51 +110,12 @@ func SearchCommits(ctx *context.Context) {
|
|||
ctx.Data["Keyword"] = keyword
|
||||
ctx.Data["Username"] = ctx.Repo.Owner.Name
|
||||
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
|
||||
ctx.Data["CommitCount"] = commits.Len()
|
||||
ctx.Data["Branch"] = ctx.Repo.BranchName
|
||||
ctx.HTML(200, COMMITS)
|
||||
}
|
||||
|
||||
func FileHistory(ctx *context.Context) {
|
||||
ctx.Data["IsRepoToolbarCommits"] = true
|
||||
|
||||
fileName := ctx.Repo.TreePath
|
||||
if len(fileName) == 0 {
|
||||
Commits(ctx)
|
||||
return
|
||||
}
|
||||
|
||||
branchName := ctx.Repo.BranchName
|
||||
commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "FileCommitsCount", err)
|
||||
return
|
||||
} else if commitsCount == 0 {
|
||||
ctx.Handle(404, "FileCommitsCount", nil)
|
||||
return
|
||||
}
|
||||
|
||||
page := ctx.QueryInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
ctx.Data["Page"] = paginater.New(int(commitsCount), git.CommitsRangeSize, page, 5)
|
||||
|
||||
commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "CommitsByFileAndRange", err)
|
||||
return
|
||||
}
|
||||
commits = RenderIssueLinks(commits, ctx.Repo.RepoLink)
|
||||
commits = models.ValidateCommitsWithEmails(commits)
|
||||
ctx.Data["Commits"] = commits
|
||||
|
||||
ctx.Data["Username"] = ctx.Repo.Owner.Name
|
||||
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
|
||||
ctx.Data["FileName"] = fileName
|
||||
ctx.Data["CommitCount"] = commitsCount
|
||||
ctx.Data["Branch"] = branchName
|
||||
ctx.HTML(200, COMMITS)
|
||||
renderCommits(ctx, ctx.Repo.TreePath)
|
||||
}
|
||||
|
||||
func Diff(ctx *context.Context) {
|
||||
|
@ -216,7 +191,6 @@ func RawDiff(ctx *context.Context) {
|
|||
}
|
||||
|
||||
func CompareDiff(ctx *context.Context) {
|
||||
ctx.Data["IsRepoToolbarCommits"] = true
|
||||
ctx.Data["IsDiffCompare"] = true
|
||||
userName := ctx.Repo.Owner.Name
|
||||
repoName := ctx.Repo.Repository.Name
|
||||
|
@ -247,7 +221,7 @@ func CompareDiff(ctx *context.Context) {
|
|||
ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
|
||||
ctx.Data["CommitRepoLink"] = ctx.Repo.RepoLink
|
||||
ctx.Data["Commits"] = commits
|
||||
ctx.Data["CommitCount"] = commits.Len()
|
||||
ctx.Data["CommitsCount"] = commits.Len()
|
||||
ctx.Data["BeforeCommitID"] = beforeCommitID
|
||||
ctx.Data["AfterCommitID"] = afterCommitID
|
||||
ctx.Data["Username"] = userName
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
<h4 class="ui top attached header">
|
||||
{{.CommitCount}} {{.i18n.Tr "repo.commits.commits"}} {{if .Branch}}({{.Branch}}){{end}}
|
||||
{{if .PageIsCommits}}
|
||||
{{.i18n.Tr "repo.commits.commit_history"}}
|
||||
{{else}}
|
||||
{{.CommitsCount}} {{.i18n.Tr "repo.commits.commits"}}
|
||||
{{end}}
|
||||
{{if .PageIsCommits}}
|
||||
<div class="ui right">
|
||||
<form action="{{.RepoLink}}/commits/{{.BranchName}}/search">
|
||||
|
@ -48,24 +52,14 @@
|
|||
</div>
|
||||
{{end}}
|
||||
|
||||
{{with .Page}}
|
||||
{{if gt .TotalPages 1}}
|
||||
<div class="center page buttons">
|
||||
<div class="ui borderless pagination menu">
|
||||
<a class="{{if not .HasPrevious}}disabled{{end}} item" {{if .HasPrevious}}href="{{$.RepoLink}}/commits/{{$.BranchName}}{{if $.FileName}}/{{$.FileName}}{{end}}?page={{.Previous}}"{{end}}>
|
||||
<i class="left arrow icon"></i> {{$.i18n.Tr "repo.issues.previous"}}
|
||||
</a>
|
||||
{{range .Pages}}
|
||||
{{if eq .Num -1}}
|
||||
<a class="disabled item">...</a>
|
||||
{{else}}
|
||||
<a class="{{if .IsCurrent}}active{{end}} item" {{if not .IsCurrent}}href="{{$.RepoLink}}/commits/{{$.BranchName}}{{if $.FileName}}/{{$.FileName}}{{end}}?page={{.Num}}"{{end}}>{{.Num}}</a>
|
||||
{{end}}
|
||||
{{end}}
|
||||
<a class="{{if not .HasNext}}disabled{{end}} item" {{if .HasNext}}href="{{$.RepoLink}}/commits/{{$.BranchName}}{{if $.FileName}}/{{$.FileName}}{{end}}?page={{.Next}}"{{end}}>
|
||||
{{$.i18n.Tr "repo.issues.next"}} <i class="icon right arrow"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
{{if or .HasPrevious .HasNext}}
|
||||
<br>
|
||||
<div class="center">
|
||||
<a class="ui small button {{if not .HasPrevious}}disabled{{end}}" {{if .HasPrevious}}href="{{$.RepoLink}}/commits/{{$.BranchName}}{{if $.FileName}}/{{$.FileName}}{{end}}?page={{.PreviousPage}}&pageSize={{.PageSize}}"{{end}}>
|
||||
{{$.i18n.Tr "repo.commits.newer"}}
|
||||
</a>
|
||||
<a class="ui small button {{if not .HasNext}}disabled{{end}}" {{if .HasNext}}href="{{$.RepoLink}}/commits/{{$.BranchName}}{{if $.FileName}}/{{$.FileName}}{{end}}?page={{.NextPage}}&pageSize={{.PageSize}}"{{end}}>
|
||||
{{$.i18n.Tr "repo.commits.older"}}
|
||||
</a>
|
||||
</div>
|
||||
{{end}}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
.PHONY: build test bench vet
|
||||
|
||||
build: vet bench
|
||||
|
||||
test:
|
||||
go test -v -cover
|
||||
|
||||
bench:
|
||||
go test -v -cover -test.bench=. -test.benchmem
|
||||
|
||||
vet:
|
||||
go vet
|
|
@ -194,10 +194,11 @@ func (l Locale) Index() int {
|
|||
// Tr translates content to target language.
|
||||
func Tr(lang, format string, args ...interface{}) string {
|
||||
var section string
|
||||
parts := strings.SplitN(format, ".", 2)
|
||||
if len(parts) == 2 {
|
||||
section = parts[0]
|
||||
format = parts[1]
|
||||
|
||||
idx := strings.IndexByte(format, '.')
|
||||
if idx > 0 {
|
||||
section = format[:idx]
|
||||
format = format[idx+1:]
|
||||
}
|
||||
|
||||
value, ok := locales.Get(lang, section, format)
|
||||
|
@ -208,15 +209,17 @@ func Tr(lang, format string, args ...interface{}) string {
|
|||
if len(args) > 0 {
|
||||
params := make([]interface{}, 0, len(args))
|
||||
for _, arg := range args {
|
||||
if arg != nil {
|
||||
val := reflect.ValueOf(arg)
|
||||
if val.Kind() == reflect.Slice {
|
||||
for i := 0; i < val.Len(); i++ {
|
||||
params = append(params, val.Index(i).Interface())
|
||||
}
|
||||
} else {
|
||||
params = append(params, arg)
|
||||
if arg == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
val := reflect.ValueOf(arg)
|
||||
if val.Kind() == reflect.Slice {
|
||||
for i := 0; i < val.Len(); i++ {
|
||||
params = append(params, val.Index(i).Interface())
|
||||
}
|
||||
} else {
|
||||
params = append(params, arg)
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf(format, params...)
|
||||
|
|
|
@ -170,8 +170,12 @@ func (c *Commit) CommitsCount() (int64, error) {
|
|||
return CommitsCount(c.repo.Path, c.ID.String())
|
||||
}
|
||||
|
||||
func (c *Commit) CommitsByRangeSize(page, size int) (*list.List, error) {
|
||||
return c.repo.CommitsByRangeSize(c.ID.String(), page, size)
|
||||
}
|
||||
|
||||
func (c *Commit) CommitsByRange(page int) (*list.List, error) {
|
||||
return c.repo.commitsByRange(c.ID, page)
|
||||
return c.repo.CommitsByRange(c.ID.String(), page)
|
||||
}
|
||||
|
||||
func (c *Commit) CommitsBefore() (*list.List, error) {
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
const _VERSION = "0.4.10"
|
||||
const _VERSION = "0.4.11"
|
||||
|
||||
func Version() string {
|
||||
return _VERSION
|
||||
|
|
|
@ -200,17 +200,21 @@ func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) {
|
|||
return commits.Front().Value.(*Commit), nil
|
||||
}
|
||||
|
||||
var CommitsRangeSize = 50
|
||||
|
||||
func (repo *Repository) commitsByRange(id sha1, page int) (*list.List, error) {
|
||||
stdout, err := NewCommand("log", id.String(), "--skip="+strconv.Itoa((page-1)*CommitsRangeSize),
|
||||
"--max-count="+strconv.Itoa(CommitsRangeSize), _PRETTY_LOG_FORMAT).RunInDirBytes(repo.Path)
|
||||
func (repo *Repository) CommitsByRangeSize(revision string, page, size int) (*list.List, error) {
|
||||
stdout, err := NewCommand("log", revision, "--skip="+strconv.Itoa((page-1)*size),
|
||||
"--max-count="+strconv.Itoa(size), _PRETTY_LOG_FORMAT).RunInDirBytes(repo.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return repo.parsePrettyFormatLogToList(stdout)
|
||||
}
|
||||
|
||||
const DEFAULT_COMMITS_PAGE_SIZE = 50
|
||||
|
||||
func (repo *Repository) CommitsByRange(revision string, page int) (*list.List, error) {
|
||||
return repo.CommitsByRangeSize(revision, page, DEFAULT_COMMITS_PAGE_SIZE)
|
||||
}
|
||||
|
||||
func (repo *Repository) searchCommits(id sha1, keyword string) (*list.List, error) {
|
||||
stdout, err := NewCommand("log", id.String(), "-100", "-i", "--grep="+keyword, _PRETTY_LOG_FORMAT).RunInDirBytes(repo.Path)
|
||||
if err != nil {
|
||||
|
@ -231,15 +235,19 @@ func (repo *Repository) FileCommitsCount(revision, file string) (int64, error) {
|
|||
return commitsCount(repo.Path, revision, file)
|
||||
}
|
||||
|
||||
func (repo *Repository) CommitsByFileAndRange(revision, file string, page int) (*list.List, error) {
|
||||
stdout, err := NewCommand("log", revision, "--skip="+strconv.Itoa((page-1)*50),
|
||||
"--max-count="+strconv.Itoa(CommitsRangeSize), _PRETTY_LOG_FORMAT, "--", file).RunInDirBytes(repo.Path)
|
||||
func (repo *Repository) CommitsByFileAndRangeSize(revision, file string, page, size int) (*list.List, error) {
|
||||
stdout, err := NewCommand("log", revision, "--skip="+strconv.Itoa((page-1)*size),
|
||||
"--max-count="+strconv.Itoa(size), _PRETTY_LOG_FORMAT, "--", file).RunInDirBytes(repo.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return repo.parsePrettyFormatLogToList(stdout)
|
||||
}
|
||||
|
||||
func (repo *Repository) CommitsByFileAndRange(revision, file string, page int) (*list.List, error) {
|
||||
return repo.CommitsByFileAndRangeSize(revision, file, page, DEFAULT_COMMITS_PAGE_SIZE)
|
||||
}
|
||||
|
||||
func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (int, error) {
|
||||
stdout, err := NewCommand("diff", "--name-only", startCommitID+"..."+endCommitID).RunInDir(repo.Path)
|
||||
if err != nil {
|
||||
|
|
|
@ -21,10 +21,10 @@
|
|||
"revisionTime": "2017-02-13T07:20:14Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "gSAaJ38R4iqG2CEsZe/ftOs3V9w=",
|
||||
"checksumSHA1": "qbYhQkK6nb2oZ9OOyyuQpWD9fXY=",
|
||||
"path": "github.com/Unknwon/i18n",
|
||||
"revision": "39d6f2727e0698b1021ceb6a77c1801aa92e7d5d",
|
||||
"revisionTime": "2016-06-03T08:28:25Z"
|
||||
"revision": "e0eb0cef13c5eadc03d6993f3069c72e566004b7",
|
||||
"revisionTime": "2017-02-18T21:29:01Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "VI3Bz1L335gsrP1ZF0v3f+WWy3M=",
|
||||
|
@ -159,10 +159,10 @@
|
|||
"revisionTime": "2016-08-10T03:50:02Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "5SLknh130FbmnSNWkf6LtVFqdMI=",
|
||||
"checksumSHA1": "mR45j8svu6CZu81VqN+lfgpCVjA=",
|
||||
"path": "github.com/gogits/git-module",
|
||||
"revision": "7c2ab580a5b25e8b045139a44635258ceef64ace",
|
||||
"revisionTime": "2017-02-17T22:39:06Z"
|
||||
"revision": "fa2ace85ecb113f89f6862d8a6e3075a7aa425b9",
|
||||
"revisionTime": "2017-02-18T23:35:37Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "xvG+RgJODQqlmdAkHUQK2TyLR88=",
|
||||
|
|
Loading…
Reference in New Issue