Search in sources :

Example 6 with TextProgressMonitor

use of org.eclipse.jgit.lib.TextProgressMonitor in project gerrit by GerritCodeReview.

the class RebuildNoteDb method rebuildProject.

private boolean rebuildProject(ReviewDb db, ImmutableListMultimap<Project.NameKey, Change.Id> allChanges, Project.NameKey project, Repository allUsersRepo) throws IOException, OrmException {
    checkArgument(allChanges.containsKey(project));
    boolean ok = true;
    ProgressMonitor pm = new TextProgressMonitor(new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out, UTF_8))));
    pm.beginTask(FormatUtil.elide(project.get(), 50), allChanges.get(project).size());
    try (NoteDbUpdateManager manager = updateManagerFactory.create(project);
        ObjectInserter allUsersInserter = allUsersRepo.newObjectInserter();
        ObjectReader reader = allUsersInserter.newReader();
        RevWalk allUsersRw = new RevWalk(reader)) {
        manager.setAllUsersRepo(allUsersRepo, allUsersRw, allUsersInserter, new ChainedReceiveCommands(allUsersRepo));
        for (Change.Id changeId : allChanges.get(project)) {
            try {
                rebuilder.buildUpdates(manager, bundleReader.fromReviewDb(db, changeId));
            } catch (NoPatchSetsException e) {
                log.warn(e.getMessage());
            } catch (Throwable t) {
                log.error("Failed to rebuild change " + changeId, t);
                ok = false;
            }
            pm.update(1);
        }
        manager.execute();
    } finally {
        pm.endTask();
    }
    return ok;
}
Also used : ChainedReceiveCommands(com.google.gerrit.server.update.ChainedReceiveCommands) NoteDbUpdateManager(com.google.gerrit.server.notedb.NoteDbUpdateManager) Change(com.google.gerrit.reviewdb.client.Change) TextProgressMonitor(org.eclipse.jgit.lib.TextProgressMonitor) RevWalk(org.eclipse.jgit.revwalk.RevWalk) BufferedWriter(java.io.BufferedWriter) TextProgressMonitor(org.eclipse.jgit.lib.TextProgressMonitor) NullProgressMonitor(org.eclipse.jgit.lib.NullProgressMonitor) ProgressMonitor(org.eclipse.jgit.lib.ProgressMonitor) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) NoPatchSetsException(com.google.gerrit.server.notedb.rebuild.ChangeRebuilder.NoPatchSetsException) OutputStreamWriter(java.io.OutputStreamWriter) ObjectReader(org.eclipse.jgit.lib.ObjectReader) PrintWriter(java.io.PrintWriter)

Example 7 with TextProgressMonitor

use of org.eclipse.jgit.lib.TextProgressMonitor in project gerrit by GerritCodeReview.

the class GarbageCollection method run.

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));
    }
    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;
}
Also used : GarbageCollectCommand(org.eclipse.jgit.api.GarbageCollectCommand) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) TextProgressMonitor(org.eclipse.jgit.lib.TextProgressMonitor) Properties(java.util.Properties) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) Project(com.google.gerrit.reviewdb.client.Project) Repository(org.eclipse.jgit.lib.Repository) GarbageCollectionResult(com.google.gerrit.common.data.GarbageCollectionResult)

Aggregations

TextProgressMonitor (org.eclipse.jgit.lib.TextProgressMonitor)7 ProgressMonitor (org.eclipse.jgit.lib.ProgressMonitor)5 Stopwatch (com.google.common.base.Stopwatch)3 OrmException (com.google.gwtorm.server.OrmException)3 PrintWriter (java.io.PrintWriter)3 Repository (org.eclipse.jgit.lib.Repository)3 Change (com.google.gerrit.reviewdb.client.Change)2 Project (com.google.gerrit.reviewdb.client.Project)2 SiteIndexer (com.google.gerrit.server.index.SiteIndexer)2 IOException (java.io.IOException)2 Map (java.util.Map)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 GarbageCollectionResult (com.google.gerrit.common.data.GarbageCollectionResult)1 Account (com.google.gerrit.reviewdb.client.Account)1 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)1 MultiProgressMonitor (com.google.gerrit.server.git.MultiProgressMonitor)1 NoteDbUpdateManager (com.google.gerrit.server.notedb.NoteDbUpdateManager)1 NoPatchSetsException (com.google.gerrit.server.notedb.rebuild.ChangeRebuilder.NoPatchSetsException)1 ChainedReceiveCommands (com.google.gerrit.server.update.ChainedReceiveCommands)1 RelationModel (com.google.gwtorm.schema.RelationModel)1