]> source.dussan.org Git - jgit.git/commitdiff
Close RevWalk in BranchTrackingStatus.of() 54/116754/1
authorMatthias Sohn <matthias.sohn@sap.com>
Tue, 6 Feb 2018 00:10:26 +0000 (01:10 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Tue, 6 Feb 2018 00:10:26 +0000 (01:10 +0100)
Bug: 530757
Change-Id: I985ee5395e1468981c28ae0a80797732e2f528d2
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchTrackingStatus.java

index ac1529f990e339ff2afc42a453e0ccfe53f8b6b0..51b5b80fc430b02bc3afadb82be315e0dc2fff7b 100644 (file)
@@ -87,22 +87,25 @@ public class BranchTrackingStatus {
                if (local == null)
                        return null;
 
-               RevWalk walk = new RevWalk(repository);
+               try (RevWalk walk = new RevWalk(repository)) {
 
-               RevCommit localCommit = walk.parseCommit(local.getObjectId());
-               RevCommit trackingCommit = walk.parseCommit(tracking.getObjectId());
+                       RevCommit localCommit = walk.parseCommit(local.getObjectId());
+                       RevCommit trackingCommit = walk.parseCommit(tracking.getObjectId());
 
-               walk.setRevFilter(RevFilter.MERGE_BASE);
-               walk.markStart(localCommit);
-               walk.markStart(trackingCommit);
-               RevCommit mergeBase = walk.next();
+                       walk.setRevFilter(RevFilter.MERGE_BASE);
+                       walk.markStart(localCommit);
+                       walk.markStart(trackingCommit);
+                       RevCommit mergeBase = walk.next();
 
-               walk.reset();
-               walk.setRevFilter(RevFilter.ALL);
-               int aheadCount = RevWalkUtils.count(walk, localCommit, mergeBase);
-               int behindCount = RevWalkUtils.count(walk, trackingCommit, mergeBase);
+                       walk.reset();
+                       walk.setRevFilter(RevFilter.ALL);
+                       int aheadCount = RevWalkUtils.count(walk, localCommit, mergeBase);
+                       int behindCount = RevWalkUtils.count(walk, trackingCommit,
+                                       mergeBase);
 
-               return new BranchTrackingStatus(trackingBranch, aheadCount, behindCount);
+                       return new BranchTrackingStatus(trackingBranch, aheadCount,
+                                       behindCount);
+               }
        }
 
        private final String remoteTrackingBranch;