diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffCommand.java index 0159beec9a..246d4cfb52 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffCommand.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffCommand.java @@ -62,12 +62,11 @@ public class GitDiffCommand extends AbstractGitCommand implements DiffCommand { @Override public DiffCommandBuilder.OutputStreamConsumer getDiffResult(DiffCommandRequest request) throws IOException { - WorkingCopyCloser closer = new WorkingCopyCloser(); if (Strings.isNullOrEmpty(request.getMergeChangeset())) { Differ.Diff diff = Differ.diff(open(), request); - List entries = diff.getEntries(); - return computeDiff(entries, open(), closer); + return computeDiff(diff.getEntries(), open()); } else { + WorkingCopyCloser closer = new WorkingCopyCloser(); return inCloneWithPostponedClose(git -> new GitCloneWorker(git) { @Override DiffCommandBuilder.OutputStreamConsumer run() throws IOException { @@ -82,9 +81,9 @@ public class GitDiffCommand extends AbstractGitCommand implements DiffCommand { throw new InternalRepositoryException(context.getRepository(), "could not merge branch " + request.getRevision() + " into " + request.getMergeChangeset(), e); } - CanonicalTreeParser treeParser = new CanonicalTreeParser(); - ObjectId treeId = git.getRepository().resolve(request.getMergeChangeset() + "^{tree}"); return outputStream -> { + CanonicalTreeParser treeParser = new CanonicalTreeParser(); + ObjectId treeId = git.getRepository().resolve(request.getMergeChangeset() + "^{tree}"); try (ObjectReader reader = git.getRepository().newObjectReader()) { treeParser.reset(reader, treeId); git @@ -96,6 +95,8 @@ public class GitDiffCommand extends AbstractGitCommand implements DiffCommand { clone.setRevision(sourceRevision.name()); } catch (GitAPIException e) { throw new InternalRepositoryException(repository, "could not calculate diff", e); + } finally { + closer.close(); } }; } @@ -103,7 +104,7 @@ public class GitDiffCommand extends AbstractGitCommand implements DiffCommand { } } - private DiffCommandBuilder.OutputStreamConsumer computeDiff(List entries, org.eclipse.jgit.lib.Repository repository, WorkingCopyCloser closer) throws IOException { + private DiffCommandBuilder.OutputStreamConsumer computeDiff(List entries, org.eclipse.jgit.lib.Repository repository) throws IOException { return output -> { try (DiffFormatter formatter = new DiffFormatter(output)) { @@ -116,8 +117,6 @@ public class GitDiffCommand extends AbstractGitCommand implements DiffCommand { } formatter.flush(); - } finally { - closer.close(); } }; }