diff --git a/modules/git/commit.go b/modules/git/commit.go index d63b71a87..4e3675b20 100644 --- a/modules/git/commit.go +++ b/modules/git/commit.go @@ -193,7 +193,7 @@ func (c *Commit) CommitsByRange(page, pageSize int) (*list.List, error) { // CommitsByFileAndRange returns the specific page page commits before current revision and file, every page's number default by CommitsRangeSize func (c *Commit) CommitsByFileAndRange(file string, page, pageSize int) (*list.List, error) { - return c.repo.CommitsByFileAndRange(c.ID.String(), file, page) + return c.repo.CommitsByFileAndRange(c.ID.String(), file, page, pageSize) } // CommitsBefore returns all the commits before current revision diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go index 8efbb601f..889dc3967 100644 --- a/modules/git/repo_commit.go +++ b/modules/git/repo_commit.go @@ -214,7 +214,7 @@ func (repo *Repository) GetFirstAndLastCommitByPath(revision, relpath string) (* } // CommitsByFileAndRange return the commits according revision file and the page -func (repo *Repository) CommitsByFileAndRange(revision, file string, page int) (*list.List, error) { +func (repo *Repository) CommitsByFileAndRange(revision, file string, page int, pageSize int) (*list.List, error) { skip := (page - 1) * setting.Git.CommitsRangeSize stdoutReader, stdoutWriter := io.Pipe() @@ -223,9 +223,12 @@ func (repo *Repository) CommitsByFileAndRange(revision, file string, page int) ( _ = stdoutWriter.Close() }() go func() { + if pageSize <= 0 { + pageSize = setting.Git.CommitsRangeSize + } stderr := strings.Builder{} err := NewCommand("log", revision, "--follow", - "--max-count="+strconv.Itoa(setting.Git.CommitsRangeSize*page), + "--max-count="+strconv.Itoa(pageSize*page), prettyLogFormat, "--", file). RunInDirPipeline(repo.Path, stdoutWriter, &stderr) if err != nil { diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index 98f533686..aa032c7ec 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -230,11 +230,12 @@ func FileHistory(ctx *context.Context) { } page := ctx.QueryInt("page") + limit := ctx.QueryInt("limit") if page <= 1 { page = 1 } - commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page) + commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page, limit) if err != nil { ctx.ServerError("CommitsByFileAndRange", err) return