1 /*******************************************************************************
2 * Copyright (C) 2012, 2013 Matthias Sohn <matthias.sohn@sap.com> and others.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
10 *******************************************************************************/
11 package org
.eclipse
.egit
.core
.op
;
13 import org
.eclipse
.core
.runtime
.CoreException
;
14 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
15 import org
.eclipse
.core
.runtime
.IStatus
;
16 import org
.eclipse
.core
.runtime
.Status
;
17 import org
.eclipse
.core
.runtime
.jobs
.ISchedulingRule
;
18 import org
.eclipse
.egit
.core
.Activator
;
19 import org
.eclipse
.egit
.core
.EclipseGitProgressTransformer
;
20 import org
.eclipse
.egit
.core
.internal
.job
.RuleUtil
;
21 import org
.eclipse
.jgit
.api
.Git
;
22 import org
.eclipse
.jgit
.api
.errors
.GitAPIException
;
23 import org
.eclipse
.jgit
.lib
.Repository
;
26 * Operation to garbage collect a git repository
28 public class GarbageCollectOperation
implements IEGitOperation
{
30 private Repository repository
;
33 * @param repository the repository to garbage collect
35 public GarbageCollectOperation(Repository repository
) {
36 this.repository
= repository
;
40 * Execute garbage collection
43 public void execute(IProgressMonitor monitor
) throws CoreException
{
44 try (Git git
= new Git(repository
)) {
45 git
.gc().setProgressMonitor(
46 new EclipseGitProgressTransformer(monitor
)).call();
47 } catch (GitAPIException e
) {
48 throw new CoreException(new Status(IStatus
.ERROR
,
49 Activator
.getPluginId(), e
.getMessage(), e
));
54 public ISchedulingRule
getSchedulingRule() {
55 return RuleUtil
.getRule(repository
);