]> source.dussan.org Git - jgit.git/commitdiff
DiffCommand: Open DiffFormatter in try-with-resource 37/118737/1
authorDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 6 Mar 2018 01:40:35 +0000 (10:40 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 6 Mar 2018 01:40:35 +0000 (10:40 +0900)
Change-Id: I22bd1062d64b01bb98cdaf612482538114624b7f
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
org.eclipse.jgit/src/org/eclipse/jgit/api/DiffCommand.java

index 4c6f3511429037cf4be07158f6707cda47082eac..f65b5735de2029e94847afbbce19625d7d13f5be 100644 (file)
@@ -104,6 +104,12 @@ public class DiffCommand extends GitCommand<List<DiffEntry>> {
                super(repo);
        }
 
+       private DiffFormatter getDiffFormatter() {
+               return out != null && !showNameAndStatusOnly
+                               ? new DiffFormatter(new BufferedOutputStream(out))
+                               : new DiffFormatter(NullOutputStream.INSTANCE);
+       }
+
        /**
         * {@inheritDoc}
         * <p>
@@ -114,14 +120,9 @@ public class DiffCommand extends GitCommand<List<DiffEntry>> {
         */
        @Override
        public List<DiffEntry> call() throws GitAPIException {
-               final DiffFormatter diffFmt;
-               if (out != null && !showNameAndStatusOnly)
-                       diffFmt = new DiffFormatter(new BufferedOutputStream(out));
-               else
-                       diffFmt = new DiffFormatter(NullOutputStream.INSTANCE);
-               diffFmt.setRepository(repo);
-               diffFmt.setProgressMonitor(monitor);
-               try {
+               try (DiffFormatter diffFmt = getDiffFormatter()) {
+                       diffFmt.setRepository(repo);
+                       diffFmt.setProgressMonitor(monitor);
                        if (cached) {
                                if (oldTree == null) {
                                        ObjectId head = repo.resolve(HEAD + "^{tree}"); //$NON-NLS-1$
@@ -159,8 +160,6 @@ public class DiffCommand extends GitCommand<List<DiffEntry>> {
                        }
                } catch (IOException e) {
                        throw new JGitInternalException(e.getMessage(), e);
-               } finally {
-                       diffFmt.close();
                }
        }