]> source.dussan.org Git - jgit.git/commitdiff
SubmoduleWalk: Open Repository in try-with-resource 11/119311/4
authorDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 13 Mar 2018 11:24:45 +0000 (20:24 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Wed, 14 Mar 2018 01:44:23 +0000 (10:44 +0900)
Change-Id: Ib29aaf26b49aa94a5a7cc0b0264a0a93ecff0c16
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java

index 2314cf10dfaec0ba8b4b496d09b73b569e7f4bfb..0fc11f697cd0036c66120b80368e88a90ab44a14 100644 (file)
@@ -754,13 +754,11 @@ public class SubmoduleWalk implements AutoCloseable {
         * @throws java.io.IOException
         */
        public ObjectId getHead() throws IOException {
-               Repository subRepo = getRepository();
-               if (subRepo == null)
-                       return null;
-               try {
+               try (Repository subRepo = getRepository()) {
+                       if (subRepo == null) {
+                               return null;
+                       }
                        return subRepo.resolve(Constants.HEAD);
-               } finally {
-                       subRepo.close();
                }
        }
 
@@ -771,14 +769,12 @@ public class SubmoduleWalk implements AutoCloseable {
         * @throws java.io.IOException
         */
        public String getHeadRef() throws IOException {
-               Repository subRepo = getRepository();
-               if (subRepo == null)
-                       return null;
-               try {
+               try (Repository subRepo = getRepository()) {
+                       if (subRepo == null) {
+                               return null;
+                       }
                        Ref head = subRepo.exactRef(Constants.HEAD);
                        return head != null ? head.getLeaf().getName() : null;
-               } finally {
-                       subRepo.close();
                }
        }