Skip to content

Commit fa2ace8

Browse files
committed
commit: add CommitsByRangeSize and CommitsByFileAndRangeSize (gogs/gogs#3965)
1 parent 7c2ab58 commit fa2ace8

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

commit.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,12 @@ func (c *Commit) CommitsCount() (int64, error) {
170170
return CommitsCount(c.repo.Path, c.ID.String())
171171
}
172172

173+
func (c *Commit) CommitsByRangeSize(page, size int) (*list.List, error) {
174+
return c.repo.CommitsByRangeSize(c.ID.String(), page, size)
175+
}
176+
173177
func (c *Commit) CommitsByRange(page int) (*list.List, error) {
174-
return c.repo.commitsByRange(c.ID, page)
178+
return c.repo.CommitsByRange(c.ID.String(), page)
175179
}
176180

177181
func (c *Commit) CommitsBefore() (*list.List, error) {

git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"time"
1111
)
1212

13-
const _VERSION = "0.4.10"
13+
const _VERSION = "0.4.11"
1414

1515
func Version() string {
1616
return _VERSION

repo_commit.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,21 @@ func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) {
200200
return commits.Front().Value.(*Commit), nil
201201
}
202202

203-
var CommitsRangeSize = 50
204-
205-
func (repo *Repository) commitsByRange(id sha1, page int) (*list.List, error) {
206-
stdout, err := NewCommand("log", id.String(), "--skip="+strconv.Itoa((page-1)*CommitsRangeSize),
207-
"--max-count="+strconv.Itoa(CommitsRangeSize), _PRETTY_LOG_FORMAT).RunInDirBytes(repo.Path)
203+
func (repo *Repository) CommitsByRangeSize(revision string, page, size int) (*list.List, error) {
204+
stdout, err := NewCommand("log", revision, "--skip="+strconv.Itoa((page-1)*size),
205+
"--max-count="+strconv.Itoa(size), _PRETTY_LOG_FORMAT).RunInDirBytes(repo.Path)
208206
if err != nil {
209207
return nil, err
210208
}
211209
return repo.parsePrettyFormatLogToList(stdout)
212210
}
213211

212+
const DEFAULT_COMMITS_PAGE_SIZE = 50
213+
214+
func (repo *Repository) CommitsByRange(revision string, page int) (*list.List, error) {
215+
return repo.CommitsByRangeSize(revision, page, DEFAULT_COMMITS_PAGE_SIZE)
216+
}
217+
214218
func (repo *Repository) searchCommits(id sha1, keyword string) (*list.List, error) {
215219
stdout, err := NewCommand("log", id.String(), "-100", "-i", "--grep="+keyword, _PRETTY_LOG_FORMAT).RunInDirBytes(repo.Path)
216220
if err != nil {
@@ -231,15 +235,19 @@ func (repo *Repository) FileCommitsCount(revision, file string) (int64, error) {
231235
return commitsCount(repo.Path, revision, file)
232236
}
233237

234-
func (repo *Repository) CommitsByFileAndRange(revision, file string, page int) (*list.List, error) {
235-
stdout, err := NewCommand("log", revision, "--skip="+strconv.Itoa((page-1)*50),
236-
"--max-count="+strconv.Itoa(CommitsRangeSize), _PRETTY_LOG_FORMAT, "--", file).RunInDirBytes(repo.Path)
238+
func (repo *Repository) CommitsByFileAndRangeSize(revision, file string, page, size int) (*list.List, error) {
239+
stdout, err := NewCommand("log", revision, "--skip="+strconv.Itoa((page-1)*size),
240+
"--max-count="+strconv.Itoa(size), _PRETTY_LOG_FORMAT, "--", file).RunInDirBytes(repo.Path)
237241
if err != nil {
238242
return nil, err
239243
}
240244
return repo.parsePrettyFormatLogToList(stdout)
241245
}
242246

247+
func (repo *Repository) CommitsByFileAndRange(revision, file string, page int) (*list.List, error) {
248+
return repo.CommitsByFileAndRangeSize(revision, file, page, DEFAULT_COMMITS_PAGE_SIZE)
249+
}
250+
243251
func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (int, error) {
244252
stdout, err := NewCommand("diff", "--name-only", startCommitID+"..."+endCommitID).RunInDir(repo.Path)
245253
if err != nil {

0 commit comments

Comments
 (0)