Example usage for org.eclipse.jgit.api GarbageCollectCommand setAggressive

List of usage examples for org.eclipse.jgit.api GarbageCollectCommand setAggressive

Introduction

In this page you can find the example usage for org.eclipse.jgit.api GarbageCollectCommand setAggressive.

Prototype

public GarbageCollectCommand setAggressive(boolean aggressive) 

Source Link

Document

Whether to use aggressive mode or not.

Usage

From source file:com.google.gerrit.server.git.GarbageCollection.java

License:Apache License

public GarbageCollectionResult run(List<Project.NameKey> projectNames, boolean aggressive, PrintWriter writer) {
    GarbageCollectionResult result = new GarbageCollectionResult();
    Set<Project.NameKey> projectsToGc = gcQueue.addAll(projectNames);
    for (Project.NameKey projectName : Sets.difference(Sets.newHashSet(projectNames), projectsToGc)) {
        result.addError(new GarbageCollectionResult.Error(
                GarbageCollectionResult.Error.Type.GC_ALREADY_SCHEDULED, projectName));
    }/*from w  w  w. j a  v  a 2s  . c  o m*/
    for (Project.NameKey p : projectsToGc) {
        try (Repository repo = repoManager.openRepository(p)) {
            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);
            Properties statistics = gc.call();
            logGcInfo(p, "after: ", statistics);
            print(writer, "done.\n\n");
            fire(p, statistics);
        } catch (RepositoryNotFoundException e) {
            logGcError(writer, p, e);
            result.addError(new GarbageCollectionResult.Error(
                    GarbageCollectionResult.Error.Type.REPOSITORY_NOT_FOUND, p));
        } catch (Exception e) {
            logGcError(writer, p, e);
            result.addError(new GarbageCollectionResult.Error(GarbageCollectionResult.Error.Type.GC_FAILED, p));
        } finally {
            gcQueue.gcFinished(p);
        }
    }
    return result;
}