Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntonio Barone2023-10-05 19:58:13 +0000
committerMatthias Sohn2023-10-12 20:51:14 +0000
commitf103a1d5c605f5f4545050c1176a9a202151f942 (patch)
tree0e02f74591968f0f983156f97ec6eec0ef75fe9c
parentf5f4bf0ad97f67ff56db18033c0a0795b722e96e (diff)
downloadjgit-f103a1d5c605f5f4545050c1176a9a202151f942.tar.gz
jgit-f103a1d5c605f5f4545050c1176a9a202151f942.tar.xz
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
-rw-r--r--Documentation/config-options.md6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcKeepFilesTest.java96
-rw-r--r--org.eclipse.jgit/.settings/.api_filters24
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/GarbageCollectCommand.java9
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java12
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java13
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackConfig.java48
7 files changed, 191 insertions, 17 deletions
diff --git a/Documentation/config-options.md b/Documentation/config-options.md
index 5d76483acf..7221cceb35 100644
--- a/Documentation/config-options.md
+++ b/Documentation/config-options.md
@@ -110,3 +110,9 @@ Proxy configuration uses the standard Java mechanisms via class `java.net.ProxyS
| `pack.waitPreventRacyPack` | `false` | ⃞ | Whether we wait before opening a newly written pack to prevent its lastModified timestamp could be racy. |
| `pack.window` | `10` | ✅ | Number of objects to try when looking for a delta base per thread searching for deltas. |
| `pack.windowMemory` | `0` (unlimited) | ✅ | Maximum number of bytes to put into the delta search window. |
+
+## __repack__ options
+
+| option | default | git option | description |
+|---------|---------|------------|-------------|
+| `repack.packKeptObjects` | `true` when `pack.buildBitmaps` is set, `false` otherwise | ✅ | Include objects in packs locked by a `.keep` file when repacking. | \ No newline at end of file
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;
diff --git a/org.eclipse.jgit/.settings/.api_filters b/org.eclipse.jgit/.settings/.api_filters
index 24c6a3150f..caf331143b 100644
--- a/org.eclipse.jgit/.settings/.api_filters
+++ b/org.eclipse.jgit/.settings/.api_filters
@@ -53,6 +53,18 @@
<message_argument value="SHA1_IMPLEMENTATION"/>
</message_arguments>
</filter>
+ <filter id="1142947843">
+ <message_arguments>
+ <message_argument value="5.13.3"/>
+ <message_argument value="CONFIG_KEY_PACK_KEPT_OBJECTS"/>
+ </message_arguments>
+ </filter>
+ <filter id="1142947843">
+ <message_arguments>
+ <message_argument value="5.13.3"/>
+ <message_argument value="CONFIG_REPACK_SECTION"/>
+ </message_arguments>
+ </filter>
</resource>
<resource path="src/org/eclipse/jgit/lib/Repository.java" type="org.eclipse.jgit.lib.Repository">
<filter id="1142947843">
@@ -72,6 +84,12 @@
<filter id="336658481">
<message_arguments>
<message_argument value="org.eclipse.jgit.storage.pack.PackConfig"/>
+ <message_argument value="DEFAULT_PACK_KEPT_OBJECTS"/>
+ </message_arguments>
+ </filter>
+ <filter id="336658481">
+ <message_arguments>
+ <message_argument value="org.eclipse.jgit.storage.pack.PackConfig"/>
<message_argument value="DEFAULT_SEARCH_FOR_REUSE_TIMEOUT"/>
</message_arguments>
</filter>
@@ -93,6 +111,12 @@
<message_argument value="setBitmapExcludedRefsPrefixes(String[])"/>
</message_arguments>
</filter>
+ <filter id="1142947843">
+ <message_arguments>
+ <message_argument value="5.13.3"/>
+ <message_argument value="DEFAULT_PACK_KEPT_OBJECTS"/>
+ </message_arguments>
+ </filter>
</resource>
<resource path="src/org/eclipse/jgit/transport/BasePackPushConnection.java" type="org.eclipse.jgit.transport.BasePackPushConnection">
<filter id="338792546">
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/GarbageCollectCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/GarbageCollectCommand.java
index 2e09d4a8e3..8b7e3e161f 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/GarbageCollectCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/GarbageCollectCommand.java
@@ -62,7 +62,7 @@ public class GarbageCollectCommand extends GitCommand<Properties> {
private PackConfig pconfig;
- private boolean packKeptObjects;
+ private Boolean packKeptObjects;
/**
* Constructor for GarbageCollectCommand.
@@ -141,7 +141,7 @@ public class GarbageCollectCommand extends GitCommand<Properties> {
* @since 5.13.3
*/
public GarbageCollectCommand setPackKeptObjects(boolean packKeptObjects) {
- this.packKeptObjects = packKeptObjects;
+ this.packKeptObjects = Boolean.valueOf(packKeptObjects);
return this;
}
@@ -189,8 +189,9 @@ public class GarbageCollectCommand extends GitCommand<Properties> {
gc.setProgressMonitor(monitor);
if (this.expire != null)
gc.setExpire(expire);
- gc.setPackKeptObjects(packKeptObjects);
-
+ if (this.packKeptObjects != null) {
+ gc.setPackKeptObjects(packKeptObjects.booleanValue());
+ }
try {
gc.gc();
return toProperties(gc.getStatistics());
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
index 63edfa64b9..c8dd71ca33 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
@@ -158,7 +158,7 @@ public class GC {
private Date packExpire;
- private boolean packKeptObjects;
+ private Boolean packKeptObjects;
private PackConfig pconfig;
@@ -841,7 +841,7 @@ public class GC {
List<ObjectIdSet> excluded = new LinkedList<>();
for (Pack p : repo.getObjectDatabase().getPacks()) {
checkCancelled();
- if (!packKeptObjects && p.shouldBeKept()) {
+ if (!shouldPackKeptObjects() && p.shouldBeKept()) {
excluded.add(p.getIndex());
}
}
@@ -1316,7 +1316,13 @@ public class GC {
* @param packKeptObjects Whether to include objects in `.keep` files when repacking.
*/
public void setPackKeptObjects(boolean packKeptObjects) {
- this.packKeptObjects = packKeptObjects;
+ this.packKeptObjects = Boolean.valueOf(packKeptObjects);
+ }
+
+ @SuppressWarnings("boxing")
+ private boolean shouldPackKeptObjects() {
+ return Optional.ofNullable(packKeptObjects)
+ .orElse(pconfig.isPackKeptObjects());
}
/**
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java
index 634e3f7f86..605b44bee8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java
@@ -59,6 +59,12 @@ public final class ConfigConstants {
/** The "gc" section */
public static final String CONFIG_GC_SECTION = "gc";
+ /**
+ * The "repack" section
+ * @since 5.13.3
+ */
+ public static final String CONFIG_REPACK_SECTION = "repack";
+
/** The "pack" section */
public static final String CONFIG_PACK_SECTION = "pack";
@@ -729,6 +735,13 @@ public final class ConfigConstants {
public static final String CONFIG_KEY_WINDOW_MEMORY = "windowmemory";
/**
+ * The "repack.packKeptObjects" key
+ *
+ * @since 5.13.3
+ */
+ public static final String CONFIG_KEY_PACK_KEPT_OBJECTS = "packkeptobjects";
+
+ /**
* The "feature" section
*
* @since 5.9
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackConfig.java
index 163e475887..47ea733faf 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackConfig.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackConfig.java
@@ -37,8 +37,10 @@ import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_WAIT_PREVENT_RACYP
import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_WINDOW;
import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_WINDOW_MEMORY;
import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_PACK_SECTION;
+import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PACK_KEPT_OBJECTS;
import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PRESERVE_OLD_PACKS;
import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PRUNE_PRESERVED;
+import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_REPACK_SECTION;
import java.time.Duration;
import java.util.concurrent.Executor;
@@ -168,6 +170,16 @@ public class PackConfig {
*/
public static final boolean DEFAULT_BUILD_BITMAPS = true;
+
+ /**
+ * Default value for including objects in packs locked by .keep file when
+ * repacking: {@value}
+ *
+ * @see #setPackKeptObjects(boolean)
+ * @since 5.13.3
+ */
+ public static final boolean DEFAULT_PACK_KEPT_OBJECTS = false;
+
/**
* Default count of most recent commits to select for bitmaps. Only applies
* when bitmaps are enabled: {@value}
@@ -284,6 +296,8 @@ public class PackConfig {
private boolean buildBitmaps = DEFAULT_BUILD_BITMAPS;
+ private boolean packKeptObjects = DEFAULT_PACK_KEPT_OBJECTS;
+
private int bitmapContiguousCommitCount = DEFAULT_BITMAP_CONTIGUOUS_COMMIT_COUNT;
private int bitmapRecentCommitCount = DEFAULT_BITMAP_RECENT_COMMIT_COUNT;
@@ -362,6 +376,7 @@ public class PackConfig {
this.executor = cfg.executor;
this.indexVersion = cfg.indexVersion;
this.buildBitmaps = cfg.buildBitmaps;
+ this.packKeptObjects = cfg.packKeptObjects;
this.bitmapContiguousCommitCount = cfg.bitmapContiguousCommitCount;
this.bitmapRecentCommitCount = cfg.bitmapRecentCommitCount;
this.bitmapRecentCommitSpan = cfg.bitmapRecentCommitSpan;
@@ -990,6 +1005,31 @@ public class PackConfig {
}
/**
+ * Set whether to include objects in `.keep` files when repacking.
+ *
+ * <p>Default setting: {@value #DEFAULT_PACK_KEPT_OBJECTS}
+ *
+ * @param packKeptObjects boolean indicating whether to include objects in
+ * `.keep` files when repacking.
+ * @since 5.13
+ */
+ public void setPackKeptObjects(boolean packKeptObjects) {
+ this.packKeptObjects = packKeptObjects;
+ }
+
+ /**
+ * True if objects in `.keep` files should be included when repacking.
+ *
+ * Default setting: {@value #DEFAULT_PACK_KEPT_OBJECTS}
+ *
+ * @return True if objects in `.keep` files should be included when repacking.
+ * @since 5.13
+ */
+ public boolean isPackKeptObjects() {
+ return packKeptObjects;
+ }
+
+ /**
* Get the count of most recent commits for which to build bitmaps.
*
* Default setting: {@value #DEFAULT_BITMAP_CONTIGUOUS_COMMIT_COUNT}
@@ -1234,8 +1274,12 @@ public class PackConfig {
setSinglePack(rc.getBoolean(CONFIG_PACK_SECTION,
CONFIG_KEY_SINGLE_PACK,
getSinglePack()));
- setBuildBitmaps(rc.getBoolean(CONFIG_PACK_SECTION,
- CONFIG_KEY_BUILD_BITMAPS, isBuildBitmaps()));
+ boolean buildBitmapsFromConfig = rc.getBoolean(CONFIG_PACK_SECTION,
+ CONFIG_KEY_BUILD_BITMAPS, isBuildBitmaps());
+ setBuildBitmaps(buildBitmapsFromConfig);
+ setPackKeptObjects(rc.getBoolean(CONFIG_REPACK_SECTION,
+ CONFIG_KEY_PACK_KEPT_OBJECTS,
+ buildBitmapsFromConfig || isPackKeptObjects()));
setBitmapContiguousCommitCount(rc.getInt(CONFIG_PACK_SECTION,
CONFIG_KEY_BITMAP_CONTIGUOUS_COMMIT_COUNT,
getBitmapContiguousCommitCount()));

Back to the top