diff --git a/Documentation/rest-api-projects.txt b/Documentation/rest-api-projects.txt index a909ab4c44..a25c7bba2f 100644 --- a/Documentation/rest-api-projects.txt +++ b/Documentation/rest-api-projects.txt @@ -2116,6 +2116,8 @@ collection. |Field Name ||Description |`show_progress` |`false` if not set| Whether progress information should be shown. +|`aggressive` |`false` if not set| +Whether an aggressive garbage collection should be done. |============================= [[head-input]] diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/GarbageCollection.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/GarbageCollection.java index 24af14d8d8..55672cf942 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/GarbageCollection.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/GarbageCollection.java @@ -63,6 +63,11 @@ public class GarbageCollection { public GarbageCollectionResult run(List projectNames, PrintWriter writer) { + return run(projectNames, false, writer); + } + + public GarbageCollectionResult run(List projectNames, + boolean aggressive, PrintWriter writer) { GarbageCollectionResult result = new GarbageCollectionResult(); Set projectsToGc = gcQueue.addAll(projectNames); for (Project.NameKey projectName : Sets.difference( @@ -74,9 +79,10 @@ public class GarbageCollection { Repository repo = null; try { repo = repoManager.openRepository(p); - logGcConfiguration(p, repo); + logGcConfiguration(p, repo, aggressive); print(writer, "collecting garbage for \"" + p + "\":\n"); GarbageCollectCommand gc = Git.wrap(repo).gc(); + gc.setAggressive(aggressive); logGcInfo(p, "before:", gc.getStatistics()); gc.setProgressMonitor(writer != null ? new TextProgressMonitor(writer) : NullProgressMonitor.INSTANCE); @@ -123,9 +129,10 @@ public class GarbageCollection { } private static void logGcConfiguration(Project.NameKey projectName, - Repository repo) { + Repository repo, boolean aggressive) { StringBuilder b = new StringBuilder(); Config cfg = repo.getConfig(); + b.append("gc.aggressive=").append(aggressive).append("; "); b.append(formatConfigValues(cfg, ConfigConstants.CONFIG_GC_SECTION, null)); for (String subsection : cfg.getSubsections(ConfigConstants.CONFIG_GC_SECTION)) { b.append(formatConfigValues(cfg, ConfigConstants.CONFIG_GC_SECTION, diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/project/GarbageCollect.java b/gerrit-server/src/main/java/com/google/gerrit/server/project/GarbageCollect.java index fe1086b6f1..a5a96b16ce 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/project/GarbageCollect.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/project/GarbageCollect.java @@ -41,6 +41,7 @@ public class GarbageCollect implements RestModifyView, UiAction { public static class Input { public boolean showProgress; + public boolean aggressive; } private final boolean canGC; @@ -68,8 +69,10 @@ public class GarbageCollect implements RestModifyView, } }; try { - GarbageCollectionResult result = garbageCollectionFactory.create().run( - Collections.singletonList(rsrc.getNameKey()), input.showProgress ? writer : null); + GarbageCollectionResult result = + garbageCollectionFactory.create().run( + Collections.singletonList(rsrc.getNameKey()), input.aggressive, + input.showProgress ? writer : null); String msg = "Garbage collection completed successfully."; if (result.hasErrors()) { for (GarbageCollectionResult.Error e : result.getErrors()) {