summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2023-10-13 00:44:33 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2023-10-13 00:51:04 +0200
commit1618c3e49881fa8e1cc75f2e8690cba1bcfd393b (patch)
treee07a11930fa5019e33d0d4bfea5f843faf931421 /org.eclipse.jgit.test
parent6483c7d20901bf285aed5b0bc77d608ea7813a47 (diff)
parent1175f14c1d1fba93795c3f815e63bca5a0113657 (diff)
downloadjgit-1618c3e49881fa8e1cc75f2e8690cba1bcfd393b.tar.gz
jgit-1618c3e49881fa8e1cc75f2e8690cba1bcfd393b.zip
Merge branch 'stable-6.1' into stable-6.2
* stable-6.1: 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: Ib4e4fe407dce334c7537bf278baa39db93aa2f09
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcKeepFilesTest.java156
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;
+ }
}