diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-05-02 11:42:53 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-05-02 11:51:43 +0300 |
commit | 7582fb70145ea3669029d525a8a57145dc297b02 (patch) | |
tree | aec892868580a61c8cb9e006a198af6629535fbf | |
parent | 684c78d67ccf6395614bab73ae8442a197e6470b (diff) |
git/stats: Adapt tests to Git enabling reverse indices by default
With 849c8b3dbf (Merge branch 'tb/pack-revindex-on-disk', 2023-04-27),
Git is about to enable reverse indices by default. This is nothing that
greatly impacts us as we have enabled writing reverse indices starting
with c03d267876 (git: Inject `pack.writeReverseIndex` into commands
generating packfiles, 2021-04-01) already.
That being said, some of the tests for repository statistics depend on
reverse indices not being enabled by default as we run git-repack(1)
manually there and then check whether reverse indices have been written
or not. These tests thus break with the upstream change.
Adapt the tests to explicitly enable writing reverse indices so that
they succeed with and without the upstream change.
-rw-r--r-- | internal/git/stats/repository_info_test.go | 63 |
1 files changed, 35 insertions, 28 deletions
diff --git a/internal/git/stats/repository_info_test.go b/internal/git/stats/repository_info_test.go index 0cbe9405a..8ff8c9269 100644 --- a/internal/git/stats/repository_info_test.go +++ b/internal/git/stats/repository_info_test.go @@ -208,12 +208,13 @@ func TestRepositoryInfoForRepository(t *testing.T) { blobID := gittest.WriteBlob(t, cfg, repoPath, []byte("x")) gittest.WriteRef(t, cfg, repoPath, "refs/tags/blob", blobID) // We use `-d`, which also prunes objects that have been packed. - gittest.Exec(t, cfg, "-C", repoPath, "repack", "-Ad") + gittest.Exec(t, cfg, "-c", "pack.writeReverseIndex=true", "-C", repoPath, "repack", "-Ad") }, expectedInfo: RepositoryInfo{ Packfiles: PackfilesInfo{ - Count: 1, - Size: hashDependentSize(42, 54), + Count: 1, + Size: hashDependentSize(42, 54), + ReverseIndexCount: 1, Bitmap: BitmapInfo{ Exists: true, Version: 1, @@ -232,7 +233,7 @@ func TestRepositoryInfoForRepository(t *testing.T) { gittest.WriteRef(t, cfg, repoPath, "refs/tags/blob", blobID) // This time we don't use `-d`, so the object will exist both in // loose and packed form. - gittest.Exec(t, cfg, "-C", repoPath, "repack", "-a") + gittest.Exec(t, cfg, "-c", "pack.writeReverseIndex=true", "-C", repoPath, "repack", "-a") }, expectedInfo: RepositoryInfo{ LooseObjects: LooseObjectsInfo{ @@ -240,8 +241,9 @@ func TestRepositoryInfoForRepository(t *testing.T) { Size: 16, }, Packfiles: PackfilesInfo{ - Count: 1, - Size: hashDependentSize(42, 54), + Count: 1, + Size: hashDependentSize(42, 54), + ReverseIndexCount: 1, Bitmap: BitmapInfo{ Exists: true, Version: 1, @@ -375,7 +377,7 @@ func TestRepositoryInfoForRepository(t *testing.T) { // We write a single packed blob. blobID := gittest.WriteBlob(t, cfg, repoPath, []byte("x")) gittest.WriteRef(t, cfg, repoPath, "refs/tags/blob", blobID) - gittest.Exec(t, cfg, "-C", repoPath, "repack", "-Ad") + gittest.Exec(t, cfg, "-c", "pack.writeReverseIndex=true", "-C", repoPath, "repack", "-Ad") // And two loose ones. gittest.WriteBlob(t, cfg, repoPath, []byte("1")) @@ -394,10 +396,11 @@ func TestRepositoryInfoForRepository(t *testing.T) { Size: 32, }, Packfiles: PackfilesInfo{ - Count: 1, - Size: hashDependentSize(42, 54), - GarbageCount: 3, - GarbageSize: 3, + Count: 1, + Size: hashDependentSize(42, 54), + ReverseIndexCount: 1, + GarbageCount: 3, + GarbageSize: 3, Bitmap: BitmapInfo{ Exists: true, Version: 1, @@ -811,11 +814,12 @@ func TestPackfileInfoForRepository(t *testing.T) { desc: "multi-pack-index", seedRepository: func(t *testing.T, repoPath string) { gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main")) - gittest.Exec(t, cfg, "-C", repoPath, "repack", "-Ad", "--write-midx") + gittest.Exec(t, cfg, "-c", "pack.writeReverseIndex=true", "-C", repoPath, "repack", "-Ad", "--write-midx") }, expectedInfo: PackfilesInfo{ - Count: 1, - Size: hashDependentSize(163, 189), + Count: 1, + Size: hashDependentSize(163, 189), + ReverseIndexCount: 1, MultiPackIndex: MultiPackIndexInfo{ Exists: true, Version: 1, @@ -827,11 +831,12 @@ func TestPackfileInfoForRepository(t *testing.T) { desc: "multi-pack-index with bitmap", seedRepository: func(t *testing.T, repoPath string) { gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main")) - gittest.Exec(t, cfg, "-C", repoPath, "repack", "-Adb", "--write-midx") + gittest.Exec(t, cfg, "-c", "pack.writeReverseIndex=true", "-C", repoPath, "repack", "-Adb", "--write-midx") }, expectedInfo: PackfilesInfo{ - Count: 1, - Size: hashDependentSize(163, 189), + Count: 1, + Size: hashDependentSize(163, 189), + ReverseIndexCount: 1, MultiPackIndex: MultiPackIndexInfo{ Exists: true, Version: 1, @@ -848,17 +853,18 @@ func TestPackfileInfoForRepository(t *testing.T) { desc: "multiple packfiles with other data structures", seedRepository: func(t *testing.T, repoPath string) { gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("first"), gittest.WithBranch("first")) - gittest.Exec(t, cfg, "-c", "repack.writeBitmaps=false", "-C", repoPath, "repack", "-Ad") + gittest.Exec(t, cfg, "-c", "repack.writeBitmaps=false", "-c", "pack.writeReverseIndex=false", "-C", repoPath, "repack", "-Ad") gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("second"), gittest.WithBranch("second")) - gittest.Exec(t, cfg, "-C", repoPath, "repack", "-db", "--write-midx") + gittest.Exec(t, cfg, "-c", "pack.writeReverseIndex=true", "-C", repoPath, "repack", "-db", "--write-midx") require.NoError(t, os.WriteFile(filepath.Join(repoPath, "objects", "pack", "garbage"), []byte("1"), perm.SharedFile)) }, expectedInfo: PackfilesInfo{ - Count: 2, - Size: hashDependentSize(315, 367), - GarbageCount: 1, - GarbageSize: 1, + Count: 2, + Size: hashDependentSize(315, 367), + ReverseIndexCount: 1, + GarbageCount: 1, + GarbageSize: 1, MultiPackIndex: MultiPackIndexInfo{ Exists: true, Version: 1, @@ -876,13 +882,14 @@ func TestPackfileInfoForRepository(t *testing.T) { seedRepository: func(t *testing.T, repoPath string) { gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("first"), gittest.WithBranch("first")) gittest.WriteCommit(t, cfg, repoPath, gittest.WithMessage("unreachable")) - gittest.Exec(t, cfg, "-C", repoPath, "repack", "--cruft", "-db", "--write-midx") + gittest.Exec(t, cfg, "-c", "pack.writeReverseIndex=true", "-C", repoPath, "repack", "--cruft", "-db", "--write-midx") }, expectedInfo: PackfilesInfo{ - Count: 2, - Size: hashDependentSize(318, 371), - CruftCount: 1, - CruftSize: hashDependentSize(156, 183), + Count: 2, + Size: hashDependentSize(318, 371), + ReverseIndexCount: 2, + CruftCount: 1, + CruftSize: hashDependentSize(156, 183), MultiPackIndex: MultiPackIndexInfo{ Exists: true, Version: 1, |