diff options
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit')
-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; + } } |