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 7d5e45a5c2..5d5f27806b 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 @@ -1,19 +1,19 @@ /** * Copyright (c) 2010, Sebastian Sdorra * All rights reserved. - * + *
* Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + *
* 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. + * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. * 3. Neither the name of SCM-Manager; nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -24,9 +24,8 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + *
* http://bitbucket.org/sdorra/scm-manager
- *
*/
@@ -36,84 +35,39 @@ package sonia.scm.repository.spi;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffFormatter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import sonia.scm.repository.GitUtil;
import sonia.scm.repository.Repository;
import java.io.BufferedOutputStream;
+import java.io.IOException;
import java.io.OutputStream;
/**
*
* @author Sebastian Sdorra
*/
-public class GitDiffCommand extends AbstractGitCommand implements DiffCommand
-{
+public class GitDiffCommand extends AbstractGitCommand implements DiffCommand {
- /**
- * the logger for GitDiffCommand
- */
- private static final Logger logger =
- LoggerFactory.getLogger(GitDiffCommand.class);
-
- //~--- constructors ---------------------------------------------------------
-
- /**
- * Constructs ...
- *
- *
- *
- * @param context
- * @param repository
- */
- GitDiffCommand(GitContext context, Repository repository)
- {
+ GitDiffCommand(GitContext context, Repository repository) {
super(context, repository);
}
- //~--- get methods ----------------------------------------------------------
-
- /**
- * Method description
- *
- *
- * @param request
- * @param output
- */
@Override
- public void getDiffResult(DiffCommandRequest request, OutputStream output)
- {
- DiffFormatter formatter = null;
-
- try
- {
- org.eclipse.jgit.lib.Repository repository = open();
-
- formatter = new DiffFormatter(new BufferedOutputStream(output));
+ public void getDiffResult(DiffCommandRequest request, OutputStream output) throws IOException {
+ @SuppressWarnings("squid:S2095") // repository will be closed with the RepositoryService
+ org.eclipse.jgit.lib.Repository repository = open();
+ try (DiffFormatter formatter = new DiffFormatter(new BufferedOutputStream(output))) {
formatter.setRepository(repository);
Differ.Diff diff = Differ.diff(repository, request);
- for (DiffEntry e : diff.getEntries())
- {
- if (!e.getOldId().equals(e.getNewId()))
- {
+ for (DiffEntry e : diff.getEntries()) {
+ if (!e.getOldId().equals(e.getNewId())) {
formatter.format(e);
}
}
formatter.flush();
}
- catch (Exception ex)
- {
- // TODO throw exception
- logger.error("could not create diff", ex);
- }
- finally
- {
- GitUtil.release(formatter);
- }
}
}
diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffResultCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffResultCommand.java
index 0d5f4f7b9e..a3f63b8f5a 100644
--- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffResultCommand.java
+++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffResultCommand.java
@@ -4,6 +4,7 @@ import com.google.common.base.Throwables;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffFormatter;
import sonia.scm.repository.GitUtil;
+import sonia.scm.repository.InternalRepositoryException;
import sonia.scm.repository.Repository;
import sonia.scm.repository.api.DiffFile;
import sonia.scm.repository.api.DiffResult;
@@ -47,7 +48,11 @@ public class GitDiffResultCommand extends AbstractGitCommand implements DiffResu
@Override
public Iterator