mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-10 12:15:43 +01:00
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>
This commit is contained in:
parent
0bdeb2b302
commit
59d1cc49f1
1 changed files with 34 additions and 2 deletions
|
@ -8,6 +8,8 @@ package git
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"container/list"
|
"container/list"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -232,8 +234,38 @@ func (repo *Repository) FileCommitsCount(revision, file string) (int64, error) {
|
||||||
|
|
||||||
// CommitsByFileAndRange return the commits according revison file and the page
|
// CommitsByFileAndRange return the commits according revison 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) (*list.List, error) {
|
||||||
stdout, err := NewCommand("log", revision, "--follow", "--skip="+strconv.Itoa((page-1)*50),
|
skip := (page - 1) * CommitsRangeSize
|
||||||
"--max-count="+strconv.Itoa(CommitsRangeSize), prettyLogFormat, "--", file).RunInDirBytes(repo.Path)
|
|
||||||
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue