Browse Source

Support DfsRepository from GarbageCollectCommand

Bug: 406379
Change-Id: I7f4f23cd50d46ffcde69d6abfe3ca0cc6fa86604
stable-3.6
Shawn Pearce 10 years ago
parent
commit
b2f0fd03d8
  1. 47
      org.eclipse.jgit/src/org/eclipse/jgit/api/GarbageCollectCommand.java

47
org.eclipse.jgit/src/org/eclipse/jgit/api/GarbageCollectCommand.java

@ -51,6 +51,8 @@ import java.util.Properties;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.internal.storage.dfs.DfsGarbageCollector;
import org.eclipse.jgit.internal.storage.dfs.DfsRepository;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.internal.storage.file.GC;
import org.eclipse.jgit.internal.storage.file.GC.RepoStatistics;
@ -99,9 +101,6 @@ public class GarbageCollectCommand extends GitCommand<Properties> {
*/
protected GarbageCollectCommand(Repository repo) {
super(repo);
if (!(repo instanceof FileRepository))
throw new UnsupportedOperationException(MessageFormat.format(
JGitText.get().unsupportedGC, repo.getClass().toString()));
pconfig = new PackConfig(repo);
}
@ -164,19 +163,33 @@ public class GarbageCollectCommand extends GitCommand<Properties> {
public Properties call() throws GitAPIException {
checkCallable();
GC gc = new GC((FileRepository) repo);
gc.setPackConfig(pconfig);
gc.setProgressMonitor(monitor);
if (this.expire != null)
gc.setExpire(expire);
try {
gc.gc();
return toProperties(gc.getStatistics());
if (repo instanceof FileRepository) {
GC gc = new GC((FileRepository) repo);
gc.setPackConfig(pconfig);
gc.setProgressMonitor(monitor);
if (this.expire != null)
gc.setExpire(expire);
try {
gc.gc();
return toProperties(gc.getStatistics());
} catch (ParseException e) {
throw new JGitInternalException(JGitText.get().gcFailed, e);
}
} else if (repo instanceof DfsRepository) {
DfsGarbageCollector gc =
new DfsGarbageCollector((DfsRepository) repo);
gc.setPackConfig(pconfig);
gc.pack(monitor);
return new Properties();
} else {
throw new UnsupportedOperationException(MessageFormat.format(
JGitText.get().unsupportedGC,
repo.getClass().toString()));
}
} catch (IOException e) {
throw new JGitInternalException(JGitText.get().gcFailed, e);
} catch (ParseException e) {
throw new JGitInternalException(JGitText.get().gcFailed, e);
}
}
@ -190,8 +203,12 @@ public class GarbageCollectCommand extends GitCommand<Properties> {
*/
public Properties getStatistics() throws GitAPIException {
try {
GC gc = new GC((FileRepository) repo);
return toProperties(gc.getStatistics());
if (repo instanceof FileRepository) {
GC gc = new GC((FileRepository) repo);
return toProperties(gc.getStatistics());
} else {
return new Properties();
}
} catch (IOException e) {
throw new JGitInternalException(
JGitText.get().couldNotGetRepoStatistics, e);

Loading…
Cancel
Save