summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-03-04 00:48:19 +0000
committerGitHub <noreply@github.com>2021-03-04 02:48:19 +0200
commit59d1cc49f1d7c63d25e2a139befc8c02b830ba09 (patch)
tree25719d01e5f1c24eac8febc034d4a08806054913 /modules
parent0bdeb2b3029dc46c3e409dc043d07bf36d581be5 (diff)
downloadgitea-59d1cc49f1d7c63d25e2a139befc8c02b830ba09.tar.gz
gitea-59d1cc49f1d7c63d25e2a139befc8c02b830ba09.zip
Fix paging of file commit logs (#14831)
Unfortunately `git log revision ... --skip=x -- path` skips the number of commits not the number of commits relating to the path. This PR changes the function to have a reader that reads and skips the necessary number of commits by hand instead. Fix #8716 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'modules')
-rw-r--r--modules/git/repo_commit.go36
1 files changed, 34 insertions, 2 deletions
diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go
index caf91e59fd..5bf113ba49 100644
--- a/modules/git/repo_commit.go
+++ b/modules/git/repo_commit.go
@@ -8,6 +8,8 @@ package git
import (
"bytes"
"container/list"
+ "io"
+ "io/ioutil"
"strconv"
"strings"
)
@@ -232,8 +234,38 @@ func (repo *Repository) FileCommitsCount(revision, file string) (int64, error) {
// CommitsByFileAndRange return the commits according revison file and the page
func (repo *Repository) CommitsByFileAndRange(revision, file string, page int) (*list.List, error) {
- stdout, err := NewCommand("log", revision, "--follow", "--skip="+strconv.Itoa((page-1)*50),
- "--max-count="+strconv.Itoa(CommitsRangeSize), prettyLogFormat, "--", file).RunInDirBytes(repo.Path)
+ skip := (page - 1) * CommitsRangeSize
+
+ stdoutReader, stdoutWriter := io.Pipe()
+ defer func() {
+ _ = stdoutReader.Close()
+ _ = stdoutWriter.Close()
+ }()
+ go func() {
+ stderr := strings.Builder{}
+ err := NewCommand("log", revision, "--follow",
+ "--max-count="+strconv.Itoa(CommitsRangeSize*page),
+ prettyLogFormat, "--", file).
+ RunInDirPipeline(repo.Path, stdoutWriter, &stderr)
+ if err != nil {
+ _ = stdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
+ } else {
+ _ = stdoutWriter.Close()
+ }
+ }()
+
+ if skip > 0 {
+ _, err := io.CopyN(ioutil.Discard, stdoutReader, int64(skip*41))
+ if err != nil {
+ if err == io.EOF {
+ return list.New(), nil
+ }
+ _ = stdoutReader.CloseWithError(err)
+ return nil, err
+ }
+ }
+
+ stdout, err := ioutil.ReadAll(stdoutReader)
if err != nil {
return nil, err
}