From 13cfc83b2b1b6ca0eba50357d39487c7f8bef403 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Fri, 3 Apr 2015 01:03:15 +0200 Subject: [PATCH] Use try-with-resource to close resources in DfsGarbageCollector Change-Id: Iaa51a46a9dde13d6f5c0f9ff54a68cea0ef1fde3 Signed-off-by: Matthias Sohn --- .../storage/dfs/DfsGarbageCollector.java | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java index deb6b7ff4..be370c7ed 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java +++ b/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. 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(); } }