mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-25 13:46:13 +01:00
Backport #32944 by wxiaoguang Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
e1026feddc
commit
e18e31d557
@ -216,8 +216,6 @@ type CommitsByFileAndRangeOptions struct {
|
|||||||
|
|
||||||
// CommitsByFileAndRange return the commits according revision file and the page
|
// CommitsByFileAndRange return the commits according revision file and the page
|
||||||
func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions) ([]*Commit, error) {
|
func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions) ([]*Commit, error) {
|
||||||
skip := (opts.Page - 1) * setting.Git.CommitsRangeSize
|
|
||||||
|
|
||||||
stdoutReader, stdoutWriter := io.Pipe()
|
stdoutReader, stdoutWriter := io.Pipe()
|
||||||
defer func() {
|
defer func() {
|
||||||
_ = stdoutReader.Close()
|
_ = stdoutReader.Close()
|
||||||
@ -226,8 +224,8 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
|
|||||||
go func() {
|
go func() {
|
||||||
stderr := strings.Builder{}
|
stderr := strings.Builder{}
|
||||||
gitCmd := NewCommand(repo.Ctx, "rev-list").
|
gitCmd := NewCommand(repo.Ctx, "rev-list").
|
||||||
AddOptionFormat("--max-count=%d", setting.Git.CommitsRangeSize*opts.Page).
|
AddOptionFormat("--max-count=%d", setting.Git.CommitsRangeSize).
|
||||||
AddOptionFormat("--skip=%d", skip)
|
AddOptionFormat("--skip=%d", (opts.Page-1)*setting.Git.CommitsRangeSize)
|
||||||
gitCmd.AddDynamicArguments(opts.Revision)
|
gitCmd.AddDynamicArguments(opts.Revision)
|
||||||
|
|
||||||
if opts.Not != "" {
|
if opts.Not != "" {
|
||||||
|
@ -8,7 +8,11 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/test"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRepository_GetCommitBranches(t *testing.T) {
|
func TestRepository_GetCommitBranches(t *testing.T) {
|
||||||
@ -126,3 +130,21 @@ func TestGetRefCommitID(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCommitsByFileAndRange(t *testing.T) {
|
||||||
|
defer test.MockVariableValue(&setting.Git.CommitsRangeSize, 2)()
|
||||||
|
|
||||||
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
|
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer bareRepo1.Close()
|
||||||
|
|
||||||
|
// "foo" has 3 commits in "master" branch
|
||||||
|
commits, err := bareRepo1.CommitsByFileAndRange(CommitsByFileAndRangeOptions{Revision: "master", File: "foo", Page: 1})
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Len(t, commits, 2)
|
||||||
|
|
||||||
|
commits, err = bareRepo1.CommitsByFileAndRange(CommitsByFileAndRangeOptions{Revision: "master", File: "foo", Page: 2})
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Len(t, commits, 1)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user