diff options
author | zeripath <art27@cantab.net> | 2021-02-10 07:00:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-10 07:00:57 +0000 |
commit | f9abf94bd99b5b9c603037aaad4dd327b68263bd (patch) | |
tree | 05a1ad16773a0bf778f7ceec6bb1c21c2b3f387b /modules/git/commit_test.go | |
parent | c0c59a4c99538fcc246ec3209a14db41a5f7dc3f (diff) | |
download | gitea-f9abf94bd99b5b9c603037aaad4dd327b68263bd.tar.gz gitea-f9abf94bd99b5b9c603037aaad4dd327b68263bd.zip |
HasPreviousCommit causes recursive load of commits unnecessarily (#14598)
This PR improves HasPreviousCommit to prevent the automatic and recursive loading
of previous commits using git merge-base --is-ancestor and git rev-list
Fix #13684
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/git/commit_test.go')
-rw-r--r-- | modules/git/commit_test.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/modules/git/commit_test.go b/modules/git/commit_test.go index 9b5fc8f660..0925a6ce6a 100644 --- a/modules/git/commit_test.go +++ b/modules/git/commit_test.go @@ -105,3 +105,28 @@ empty commit`, commitFromReader.Signature.Payload) commitFromReader.Signature.Payload += "\n\n" assert.EqualValues(t, commitFromReader, commitFromReader2) } + +func TestHasPreviousCommit(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare") + + repo, err := OpenRepository(bareRepo1Path) + assert.NoError(t, err) + + commit, err := repo.GetCommit("8006ff9adbf0cb94da7dad9e537e53817f9fa5c0") + assert.NoError(t, err) + + parentSHA := MustIDFromString("8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2") + notParentSHA := MustIDFromString("2839944139e0de9737a044f78b0e4b40d989a9e3") + + haz, err := commit.HasPreviousCommit(parentSHA) + assert.NoError(t, err) + assert.True(t, haz) + + hazNot, err := commit.HasPreviousCommit(notParentSHA) + assert.NoError(t, err) + assert.False(t, hazNot) + + selfNot, err := commit.HasPreviousCommit(commit.ID) + assert.NoError(t, err) + assert.False(t, selfNot) +} |