aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/GarbageCollectCommand.java16
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java14
2 files changed, 29 insertions, 1 deletions
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 a2fbd411f6..2e09d4a8e3 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/GarbageCollectCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/GarbageCollectCommand.java
@@ -62,6 +62,8 @@ public class GarbageCollectCommand extends GitCommand<Properties> {
private PackConfig pconfig;
+ private boolean packKeptObjects;
+
/**
* Constructor for GarbageCollectCommand.
*
@@ -131,6 +133,19 @@ public class GarbageCollectCommand extends GitCommand<Properties> {
}
/**
+ * Whether to include objects in `.keep` packs when repacking.
+ *
+ * @param packKeptObjects
+ * whether to include objects in `.keep` files when repacking.
+ * @return this instance
+ * @since 5.13.3
+ */
+ public GarbageCollectCommand setPackKeptObjects(boolean packKeptObjects) {
+ this.packKeptObjects = packKeptObjects;
+ return this;
+ }
+
+ /**
* Whether to preserve old pack files instead of deleting them.
*
* @since 4.7
@@ -174,6 +189,7 @@ public class GarbageCollectCommand extends GitCommand<Properties> {
gc.setProgressMonitor(monitor);
if (this.expire != null)
gc.setExpire(expire);
+ gc.setPackKeptObjects(packKeptObjects);
try {
gc.gc();
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 4db922b2c1..63edfa64b9 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,6 +158,8 @@ public class GC {
private Date packExpire;
+ private boolean packKeptObjects;
+
private PackConfig pconfig;
/**
@@ -839,8 +841,9 @@ public class GC {
List<ObjectIdSet> excluded = new LinkedList<>();
for (Pack p : repo.getObjectDatabase().getPacks()) {
checkCancelled();
- if (p.shouldBeKept())
+ if (!packKeptObjects && p.shouldBeKept()) {
excluded.add(p.getIndex());
+ }
}
// Don't exclude tags that are also branch tips
@@ -1308,6 +1311,15 @@ public class GC {
}
/**
+ * Define whether to include objects in `.keep` files when repacking.
+ *
+ * @param packKeptObjects Whether to include objects in `.keep` files when repacking.
+ */
+ public void setPackKeptObjects(boolean packKeptObjects) {
+ this.packKeptObjects = packKeptObjects;
+ }
+
+ /**
* A class holding statistical data for a FileRepository regarding how many
* objects are stored as loose or packed objects
*/