Use git log instead of git rev-list

This commit is contained in:
Thomas Sayen 2025-06-05 15:42:43 +00:00 committed by Thomas Sayen
parent 29b28002aa
commit 19028303b1
1 changed files with 11 additions and 3 deletions

View File

@ -6,6 +6,7 @@ package git
import (
"bytes"
"fmt"
"io"
"os"
"strconv"
@ -232,7 +233,9 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
}()
go func() {
stderr := strings.Builder{}
gitCmd := NewCommand("rev-list").
gitCmd := NewCommand(repo.Ctx, "--no-pager", "log").
AddOptionFormat("--follow").
AddOptionFormat("--pretty=format:%%H").
AddOptionFormat("--max-count=%d", setting.Git.CommitsRangeSize).
AddOptionFormat("--skip=%d", (opts.Page-1)*setting.Git.CommitsRangeSize)
gitCmd.AddDynamicArguments(opts.Revision)
@ -248,12 +251,15 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
}
gitCmd.AddDashesAndList(opts.File)
fmt.Print(gitCmd)
fmt.Fprint(os.Stdout, "")
err := gitCmd.Run(repo.Ctx, &RunOpts{
Dir: repo.Path,
Stdout: stdoutWriter,
Stderr: &stderr,
})
if err != nil {
fmt.Print("1 ", err)
if err != nil && err != io.ErrUnexpectedEOF {
_ = stdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
} else {
_ = stdoutWriter.Close()
@ -261,6 +267,7 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
}()
objectFormat, err := repo.GetObjectFormat()
fmt.Print("object", err)
if err != nil {
return nil, err
}
@ -270,8 +277,9 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
shaline := make([]byte, length+1)
for {
n, err := io.ReadFull(stdoutReader, shaline)
fmt.Print("io", err)
if err != nil || n < length {
if err == io.EOF {
if err == io.EOF || err == io.ErrUnexpectedEOF {
err = nil
}
return commits, err