diff options
author | Antonio Barone <syntonyze@gmail.com> | 2023-10-05 21:58:13 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2023-10-12 22:51:14 +0200 |
commit | f103a1d5c605f5f4545050c1176a9a202151f942 (patch) | |
tree | 0e02f74591968f0f983156f97ec6eec0ef75fe9c /org.eclipse.jgit.test/tst/org/eclipse/jgit/internal | |
parent | f5f4bf0ad97f67ff56db18033c0a0795b722e96e (diff) | |
download | jgit-f103a1d5c605f5f4545050c1176a9a202151f942.tar.gz jgit-f103a1d5c605f5f4545050c1176a9a202151f942.zip |
Add support for git config repack.packKeptObjects
Change Ide3445e652 introduced the `--pack-kept-objects` option to GC for
including the objects contained in the locked packfiles during the
repack phase.
Whilst this allowed to explicitly pass a command line argument to the
jgit gc program, it did not allow the option to be read from
configuration.
Allow the pack kept objects option to be configured exactly as C-Git
documents [1], by introducing a new `repack.packKeptObjects`
configuration.
`repack.packKeptObjects` defaults to `true`, when the
`pack.buildBitmaps` is `true` (which is the default case), `false`
otherwise.
[1] https://git-scm.com/docs/git-config#Documentation/git-config.txt-repackpackKeptObjects
Bug: 582292
Change-Id: Ia931667277410d71bc079d27c097a57094299840
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 | 96 |
1 files changed, 88 insertions, 8 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 5919192e54..074728b680 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,6 +10,10 @@ 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; @@ -20,7 +24,9 @@ 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 { @@ -55,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(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); @@ -78,17 +85,91 @@ public class GcKeepFilesTest extends GcTestCase { } @Test - public void testKeptObjectsAreIncluded() throws Exception { + 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()); + assertTrue(getSinglePack().getPackFile().create(PackExt.KEEP) + .createNewFile()); bb.commit().create(); - gc.setPackKeptObjects(true); gc.gc(); stats = gc.getStatistics(); assertEquals(2 * COMMIT_AND_TREE_OBJECTS + 1, @@ -110,15 +191,15 @@ public class GcKeepFilesTest extends GcTestCase { assertTrue(newPackIdx.hasObject(commitObjectInLockedPack)); } - @Test - public void testKeptObjectsAreNotIncludedByDefault() throws Exception { + 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()); + assertTrue(getSinglePack().getPackFile().create(PackExt.KEEP) + .createNewFile()); bb.commit().create(); gc.gc(); @@ -142,8 +223,7 @@ public class GcKeepFilesTest extends GcTestCase { } private Pack getSinglePack() { - Iterator<Pack> packIt = repo.getObjectDatabase().getPacks() - .iterator(); + Iterator<Pack> packIt = repo.getObjectDatabase().getPacks().iterator(); Pack singlePack = packIt.next(); assertFalse(packIt.hasNext()); return singlePack; |