diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2023-10-13 09:06:21 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2023-10-13 09:06:21 +0200 |
commit | 01dde5c76774ad95e584e335182ba7333f2e7f95 (patch) | |
tree | 56f5f038f853acca86e8a616df82d6481703986e /org.eclipse.jgit.test/tst/org/eclipse/jgit/internal | |
parent | bb12dd4cbde54234042f607bf923e83040910929 (diff) | |
parent | b6098c549d1ad052917a3515d2d1c19c03b7bce9 (diff) | |
download | jgit-01dde5c76774ad95e584e335182ba7333f2e7f95.tar.gz jgit-01dde5c76774ad95e584e335182ba7333f2e7f95.zip |
Merge branch 'stable-6.6' into stable-6.7
* stable-6.6:
PackConfig: fix @since tags
Remove unused API problem filters
Add support for git config repack.packKeptObjects
Do not exclude objects in locked packs from bitmap processing
Change-Id: I29241619e6c09933bb856e486f379be10dd609c2
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/internal')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcKeepFilesTest.java | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcKeepFilesTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcKeepFilesTest.java index 571f2613e3..9a2935f136 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcKeepFilesTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcKeepFilesTest.java @@ -10,8 +10,13 @@ package org.eclipse.jgit.internal.storage.file; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_BUILD_BITMAPS; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PACK_KEPT_OBJECTS; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_PACK_SECTION; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_REPACK_SECTION; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.Iterator; @@ -19,9 +24,14 @@ import java.util.Iterator; import org.eclipse.jgit.internal.storage.file.PackIndex.MutableEntry; import org.eclipse.jgit.internal.storage.pack.PackExt; import org.eclipse.jgit.junit.TestRepository.BranchBuilder; +import org.eclipse.jgit.lib.Config; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.storage.pack.PackConfig; import org.junit.Test; public class GcKeepFilesTest extends GcTestCase { + private static final int COMMIT_AND_TREE_OBJECTS = 2; + @Test public void testKeepFiles() throws Exception { BranchBuilder bb = tr.branch("refs/heads/master"); @@ -51,6 +61,7 @@ public class GcKeepFilesTest extends GcTestCase { PackFile bitmapFile = singlePack.getPackFile().create(PackExt.BITMAP_INDEX); assertTrue(keepFile.exists()); assertTrue(bitmapFile.delete()); + gc.setPackKeptObjects(false); gc.gc().get(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); @@ -72,4 +83,149 @@ public class GcKeepFilesTest extends GcTestCase { + e.toObjectId(), ind2.hasObject(e.toObjectId())); } + + @Test + public void testKeptObjectsAreIncludedByDefault() throws Exception { + testKeptObjectsAreIncluded(); + } + + @Test + public void testKeptObjectsAreIncludedByDefaultWhenBuildBitmapsIsTrue() + throws Exception { + PackConfig packConfig = new PackConfig(); + Config repoConfig = repo.getObjectDatabase().getConfig(); + repoConfig.setBoolean(CONFIG_PACK_SECTION, null, + CONFIG_KEY_BUILD_BITMAPS, true); + packConfig.fromConfig(repoConfig); + gc.setPackConfig(packConfig); + + testKeptObjectsAreIncluded(); + } + + @Test + public void testKeptObjectsAreIncludedWhenPackKeptObjectsIsFalseButOverriddenViaCommandLine() + throws Exception { + PackConfig packConfig = new PackConfig(); + packConfig.setPackKeptObjects(false); + gc.setPackConfig(packConfig); + gc.setPackKeptObjects(true); + + testKeptObjectsAreIncluded(); + } + + @Test + public void testKeptObjectsAreNotIncludedByDefaultWhenBuildBitmapsIsFalse() + throws Exception { + PackConfig packConfig = new PackConfig(); + packConfig.setBuildBitmaps(false); + gc.setPackConfig(packConfig); + + testKeptObjectsAreNotIncluded(); + } + + @Test + public void testKeptObjectsAreIncludedWhenBuildBitmapsIsFalseButPackKeptObjectsIsTrue() + throws Exception { + PackConfig packConfig = new PackConfig(); + Config repoConfig = repo.getObjectDatabase().getConfig(); + repoConfig.setBoolean(CONFIG_PACK_SECTION, null, + CONFIG_KEY_BUILD_BITMAPS, false); + repoConfig.setBoolean(CONFIG_REPACK_SECTION, null, + CONFIG_KEY_PACK_KEPT_OBJECTS, true); + packConfig.fromConfig(repoConfig); + gc.setPackConfig(packConfig); + + testKeptObjectsAreIncluded(); + } + + @Test + public void testKeptObjectsAreNotIncludedWhenPackKeptObjectsIsTrueButOverriddenViaCommandLine() + throws Exception { + PackConfig packConfig = new PackConfig(); + packConfig.setPackKeptObjects(true); + gc.setPackConfig(packConfig); + gc.setPackKeptObjects(false); + + testKeptObjectsAreNotIncluded(); + } + + @Test + public void testKeptObjectsAreNotIncludedWhenPackKeptObjectsConfigIsFalse() + throws Exception { + PackConfig packConfig = new PackConfig(); + packConfig.setPackKeptObjects(false); + gc.setPackConfig(packConfig); + + testKeptObjectsAreNotIncluded(); + } + + private void testKeptObjectsAreIncluded() throws Exception { + BranchBuilder bb = tr.branch("refs/heads/master"); + ObjectId commitObjectInLockedPack = bb.commit().create().toObjectId(); + gc.gc(); + stats = gc.getStatistics(); + assertEquals(COMMIT_AND_TREE_OBJECTS, stats.numberOfPackedObjects); + assertEquals(1, stats.numberOfPackFiles); + assertTrue(getSinglePack().getPackFile().create(PackExt.KEEP) + .createNewFile()); + + bb.commit().create(); + gc.gc(); + stats = gc.getStatistics(); + assertEquals(2 * COMMIT_AND_TREE_OBJECTS + 1, + stats.numberOfPackedObjects); + assertEquals(2, stats.numberOfPackFiles); + + PackIndex lockedPackIdx = null; + PackIndex newPackIdx = null; + for (Pack pack : repo.getObjectDatabase().getPacks()) { + if (pack.getObjectCount() == COMMIT_AND_TREE_OBJECTS) { + lockedPackIdx = pack.getIndex(); + } else { + newPackIdx = pack.getIndex(); + } + } + assertNotNull(lockedPackIdx); + assertTrue(lockedPackIdx.hasObject(commitObjectInLockedPack)); + assertNotNull(newPackIdx); + assertTrue(newPackIdx.hasObject(commitObjectInLockedPack)); + } + + private void testKeptObjectsAreNotIncluded() throws Exception { + BranchBuilder bb = tr.branch("refs/heads/master"); + ObjectId commitObjectInLockedPack = bb.commit().create().toObjectId(); + gc.gc(); + stats = gc.getStatistics(); + assertEquals(COMMIT_AND_TREE_OBJECTS, stats.numberOfPackedObjects); + assertEquals(1, stats.numberOfPackFiles); + assertTrue(getSinglePack().getPackFile().create(PackExt.KEEP) + .createNewFile()); + + bb.commit().create(); + gc.gc(); + stats = gc.getStatistics(); + assertEquals(COMMIT_AND_TREE_OBJECTS + 1, stats.numberOfPackedObjects); + assertEquals(2, stats.numberOfPackFiles); + + PackIndex lockedPackIdx = null; + PackIndex newPackIdx = null; + for (Pack pack : repo.getObjectDatabase().getPacks()) { + if (pack.getObjectCount() == COMMIT_AND_TREE_OBJECTS) { + lockedPackIdx = pack.getIndex(); + } else { + newPackIdx = pack.getIndex(); + } + } + assertNotNull(lockedPackIdx); + assertTrue(lockedPackIdx.hasObject(commitObjectInLockedPack)); + assertNotNull(newPackIdx); + assertFalse(newPackIdx.hasObject(commitObjectInLockedPack)); + } + + private Pack getSinglePack() { + Iterator<Pack> packIt = repo.getObjectDatabase().getPacks().iterator(); + Pack singlePack = packIt.next(); + assertFalse(packIt.hasNext()); + return singlePack; + } } |