Browse Source

Use try-with-resource to close resources in DfsGarbageCollector

Change-Id: Iaa51a46a9dde13d6f5c0f9ff54a68cea0ef1fde3
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-4.1
Matthias Sohn 10 years ago committed by Shawn Pearce
parent
commit
13cfc83b2b
  1. 17
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java

17
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java

@ -272,14 +272,11 @@ public class DfsGarbageCollector {
if (allHeads.isEmpty())
return;
PackWriter pw = newPackWriter();
try {
try (PackWriter pw = newPackWriter()) {
pw.setTagTargets(tagTargets);
pw.preparePack(pm, allHeads, Collections.<ObjectId> emptySet());
if (0 < pw.getObjectCount())
writePack(GC, pw, pm);
} finally {
pw.release();
}
}
@ -287,15 +284,12 @@ public class DfsGarbageCollector {
if (nonHeads.isEmpty())
return;
PackWriter pw = newPackWriter();
try {
try (PackWriter pw = newPackWriter()) {
for (PackWriter.ObjectIdSet packedObjs : newPackObj)
pw.excludeObjects(packedObjs);
pw.preparePack(pm, nonHeads, allHeads);
if (0 < pw.getObjectCount())
writePack(GC, pw, pm);
} finally {
pw.release();
}
}
@ -307,11 +301,10 @@ public class DfsGarbageCollector {
cfg.setDeltaCompress(false);
cfg.setBuildBitmaps(false);
PackWriter pw = new PackWriter(cfg, ctx);
try (PackWriter pw = new PackWriter(cfg, ctx);
RevWalk pool = new RevWalk(ctx)) {
pw.setDeltaBaseAsOffset(true);
pw.setReuseDeltaCommits(true);
try {
RevWalk pool = new RevWalk(ctx);
pm.beginTask("Finding garbage", objectsBefore());
for (DfsPackFile oldPack : packsBefore) {
PackIndex oldIdx = oldPack.getPackIndex(ctx);
@ -328,8 +321,6 @@ public class DfsGarbageCollector {
pm.endTask();
if (0 < pw.getObjectCount())
writePack(UNREACHABLE_GARBAGE, pw, pm);
} finally {
pw.release();
}
}

Loading…
Cancel
Save