mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-22 22:33:33 +01:00
Merge pull request 'fix: keep commit count limit in file history pagination static and not increase with every page' (#6337) from emilylange/fix-file-history-commit-pagination-limit into forgejo
Some checks are pending
/ release (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions
Some checks are pending
/ release (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6337 Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
commit
1e7b922e44
2 changed files with 62 additions and 1 deletions
|
@ -230,7 +230,7 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
|
|||
go func() {
|
||||
stderr := strings.Builder{}
|
||||
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)
|
||||
gitCmd.AddDynamicArguments(opts.Revision)
|
||||
|
||||
|
|
|
@ -7,6 +7,9 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -138,3 +141,61 @@ func TestGetTagCommit(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
assert.EqualValues(t, lTagCommitID, lTag.ID.String())
|
||||
}
|
||||
|
||||
func TestCommitsByRange(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||
require.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
baseCommit, err := bareRepo1.GetBranchCommit("master")
|
||||
require.NoError(t, err)
|
||||
|
||||
testCases := []struct {
|
||||
Page int
|
||||
ExpectedCommitCount int
|
||||
}{
|
||||
{1, 3},
|
||||
{2, 3},
|
||||
{3, 1},
|
||||
{4, 0},
|
||||
}
|
||||
for _, testCase := range testCases {
|
||||
commits, err := baseCommit.CommitsByRange(testCase.Page, 3, "")
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, commits, testCase.ExpectedCommitCount, "page: %d", testCase.Page)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommitsByFileAndRange(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||
require.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
defer test.MockVariableValue(&setting.Git.CommitsRangeSize, 2)()
|
||||
|
||||
testCases := []struct {
|
||||
File string
|
||||
Page int
|
||||
ExpectedCommitCount int
|
||||
}{
|
||||
{"file1.txt", 1, 1},
|
||||
{"file2.txt", 1, 1},
|
||||
{"file*.txt", 1, 2},
|
||||
{"foo", 1, 2},
|
||||
{"foo", 2, 1},
|
||||
{"foo", 3, 0},
|
||||
{"f*", 1, 2},
|
||||
{"f*", 2, 2},
|
||||
{"f*", 3, 1},
|
||||
}
|
||||
for _, testCase := range testCases {
|
||||
commits, err := bareRepo1.CommitsByFileAndRange(CommitsByFileAndRangeOptions{
|
||||
Revision: "master",
|
||||
File: testCase.File,
|
||||
Page: testCase.Page,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, commits, testCase.ExpectedCommitCount, "file: '%s', page: %d", testCase.File, testCase.Page)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue