]> source.dussan.org Git - jgit.git/commitdiff
Use try-with-resource to close resources in DfsGarbageCollector 91/45191/2
authorMatthias Sohn <matthias.sohn@sap.com>
Thu, 2 Apr 2015 23:03:15 +0000 (01:03 +0200)
committerShawn Pearce <spearce@spearce.org>
Wed, 8 Apr 2015 19:22:31 +0000 (12:22 -0700)
Change-Id: Iaa51a46a9dde13d6f5c0f9ff54a68cea0ef1fde3
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java

index deb6b7ff43d2a4b7365f7d1441d2b9fbe14b6cc0..be370c7eda5985751298d73c3b0eb3ecaac802b3 100644 (file)
@@ -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);
-               pw.setDeltaBaseAsOffset(true);
-               pw.setReuseDeltaCommits(true);
-               try {
-                       RevWalk pool = new RevWalk(ctx);
+               try (PackWriter pw = new PackWriter(cfg, ctx);
+                               RevWalk pool = new RevWalk(ctx)) {
+                       pw.setDeltaBaseAsOffset(true);
+                       pw.setReuseDeltaCommits(true);
                        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();
                }
        }