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'.
This commit is contained in:
Unknwon
2017-02-18 18:37:47 -05:00
parent 685737b816
commit c69900325d
11 changed files with 106 additions and 110 deletions

12
vendor/github.com/Unknwon/i18n/Makefile generated vendored Normal file
View File

@@ -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

View File

@@ -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...)

View File

@@ -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) {

View File

@@ -10,7 +10,7 @@ import (
"time"
)
const _VERSION = "0.4.10"
const _VERSION = "0.4.11"
func Version() string {
return _VERSION

View File

@@ -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 {