[cli] Add options --pack-refs and --no-pack-refs to Gc command Bug: jgit-241 Change-Id: I4608f816b40332ffb190f8bafd7aa99bccbfc4cd
diff --git a/Documentation/config-options.md b/Documentation/config-options.md index 20c2b58..3d48115 100644 --- a/Documentation/config-options.md +++ b/Documentation/config-options.md
@@ -80,6 +80,7 @@ | `gc.autoDetach` | `true` | ✅ | Make auto gc return immediately and run in background. | | `gc.autoPackLimit` | `50` | ✅ | Number of packs until auto gc consolidates existing packs (except those marked with a .keep file) into a single pack. Setting `gc.autoPackLimit` to 0 disables automatic consolidation of packs. | | `gc.logExpiry` | `1.day.ago` | ✅ | If the file `gc.log` exists, then auto gc will print its content and exit successfully instead of running unless that file is more than `gc.logExpiry` old. | +| `gc.packRefs`| `true` | ✅ | This variable determines whether JGit garbage collection will also pack refs. This can be set to `notbare` to enable it within all non-bare repos or it can be set to a boolean value. | | `gc.pruneExpire` | `2.weeks.ago` | ✅ | Grace period after which unreachable objects will be pruned. | | `gc.prunePackExpire` | `1.hour.ago` | ⃞ | Grace period after which packfiles only containing unreachable objects will be pruned. | | `gc.writeChangedPaths` | `false`| ⃞ | Whether bloom filter should be written to commit-graph during a gc operation. |
diff --git a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties index 606b29d..96ecf2a 100644 --- a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties +++ b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties
@@ -284,6 +284,8 @@ usage_DisplayTheVersionOfJgit=Display the version of jgit usage_Exclude=Do not consider tags matching the given glob(7) pattern, excluding the "refs/tags/" prefix usage_Gc=Cleanup unnecessary files and optimize the local repository +usage_GcPackRefs=Pack all refs except symbolic refs, default can be configured by "gc.packRefs" which defaults to true +usage_GcNoPackRefs=Do not pack refs usage_Glog=View commit history as a graph usage_DiffGuiTool=When git-difftool is invoked with the -g or --gui option the default diff tool will be read from the configured diff.guitool variable instead of diff.tool. usage_MergeGuiTool=When git-mergetool is invoked with the -g or --gui option the default merge tool will be read from the configured merge.guitool variable instead of merge.tool.
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Gc.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Gc.java index 35ac7a1..f278e55 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Gc.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Gc.java
@@ -13,6 +13,8 @@ import org.eclipse.jgit.api.GarbageCollectCommand; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.lib.GcConfig; +import org.eclipse.jgit.lib.GcConfig.PackRefsMode; import org.eclipse.jgit.lib.TextProgressMonitor; import org.kohsuke.args4j.Option; @@ -30,6 +32,16 @@ class Gc extends TextBuiltin { @Option(name = "--pack-kept-objects", usage = "usage_PackKeptObjects") private Boolean packKeptObjects; + @Option(name = "--pack-refs", forbids = { + "--no-pack-refs" }, usage = "usage_GcPackRefs") + private Boolean packRefs; + + @Option(name = "--no-pack-refs", forbids = { + "--pack-refs" }, usage = "usage_GcNoPackRefs") + void noPackRefs(@SuppressWarnings("unused") final boolean ignored) { + packRefs = Boolean.FALSE; + } + /** {@inheritDoc} */ @Override protected void run() { @@ -46,6 +58,11 @@ protected void run() { if (packKeptObjects != null) { command.setPackKeptObjects(packKeptObjects.booleanValue()); } + if (packRefs != null) { + command.setGcConfig( + new GcConfig(packRefs.booleanValue() ? PackRefsMode.TRUE + : PackRefsMode.FALSE)); + } command.call(); } catch (GitAPIException e) { throw die(e.getMessage(), e);