diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBlameCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBlameCommand.java index cbb5bb150a..e210a51d18 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBlameCommand.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBlameCommand.java @@ -33,6 +33,9 @@ package sonia.scm.repository.spi; //~--- non-JDK imports -------------------------------------------------------- +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; + import org.eclipse.jgit.api.Git; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.PersonIdent; @@ -46,7 +49,7 @@ import sonia.scm.repository.BlameResult; import sonia.scm.repository.GitUtil; import sonia.scm.repository.Person; import sonia.scm.repository.Repository; -import sonia.scm.util.AssertUtil; +import sonia.scm.repository.RepositoryException; //~--- JDK imports ------------------------------------------------------------ @@ -92,23 +95,31 @@ public class GitBlameCommand extends AbstractGitCommand implements BlameCommand * @param request * * @return + * + * @throws IOException + * @throws RepositoryException */ @Override public BlameResult getBlameResult(BlameCommandRequest request) + throws IOException, RepositoryException { - AssertUtil.assertIsNotEmpty(request.getPath()); + if (logger.isDebugEnabled()) + { + logger.debug("try to create blame for {}", request); + } + + Preconditions.checkArgument(!Strings.isNullOrEmpty(request.getPath()), + "path is empty or null"); org.eclipse.jgit.blame.BlameResult gitBlameResult = null; sonia.scm.repository.BlameResult blameResult = null; org.eclipse.jgit.lib.Repository gr = null; - Git git = null; try { gr = open(); - git = new Git(gr); - org.eclipse.jgit.api.BlameCommand blame = git.blame(); + org.eclipse.jgit.api.BlameCommand blame = new Git(gr).blame(); blame.setFilePath(request.getPath()); @@ -116,7 +127,13 @@ public class GitBlameCommand extends AbstractGitCommand implements BlameCommand blame.setStartCommit(revId); gitBlameResult = blame.call(); - AssertUtil.assertIsNotNull(gitBlameResult); + + if (gitBlameResult == null) + { + throw new RepositoryException( + "could not create blame result for path ".concat( + request.getPath())); + } List blameLines = new ArrayList(); int total = gitBlameResult.getResultContents().size(); @@ -153,9 +170,9 @@ public class GitBlameCommand extends AbstractGitCommand implements BlameCommand blameResult = new sonia.scm.repository.BlameResult(i, blameLines); } - catch (IOException ex) + finally { - logger.error("could not open repository", ex); + GitUtil.close(gr); } return blameResult; diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBrowseCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBrowseCommand.java index d127c3d5cb..0663eb6067 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBrowseCommand.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBrowseCommand.java @@ -111,8 +111,11 @@ public class GitBrowseCommand extends AbstractGitCommand * @return */ @Override - public BrowserResult getBrowserResult(BrowseCommandRequest request) + public BrowserResult getBrowserResult(BrowseCommandRequest request) throws IOException, RepositoryException { + if ( logger.isDebugEnabled() ){ + logger.debug("try to create browse result for {}", request); + } BrowserResult result = null; org.eclipse.jgit.lib.Repository repo = null; @@ -150,10 +153,6 @@ public class GitBrowseCommand extends AbstractGitCommand new ArrayList()); } } - catch (Exception ex) - { - logger.error("could not fetch browser result", ex); - } finally { GitUtil.close(repo); diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitCatCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitCatCommand.java index f8fd7c4777..d4028f9d79 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitCatCommand.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitCatCommand.java @@ -92,10 +92,19 @@ public class GitCatCommand extends AbstractGitCommand implements CatCommand * * @param request * @param output + * + * @throws IOException + * @throws RepositoryException */ @Override public void getCatResult(CatCommandRequest request, OutputStream output) + throws IOException, RepositoryException { + if (logger.isDebugEnabled()) + { + logger.debug("try to read content for {}", request); + } + org.eclipse.jgit.lib.Repository repo = null; try @@ -106,11 +115,6 @@ public class GitCatCommand extends AbstractGitCommand implements CatCommand getContent(repo, revId, request.getPath(), output); } - catch (Exception ex) - { - //TODO throw - logger.error("could not fetch content", ex); - } finally { GitUtil.close(repo); @@ -132,7 +136,7 @@ public class GitCatCommand extends AbstractGitCommand implements CatCommand * @throws RepositoryException */ void getContent(org.eclipse.jgit.lib.Repository repo, ObjectId revId, - String path, OutputStream output) + String path, OutputStream output) throws IOException, RepositoryException { TreeWalk treeWalk = null; 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 170db0a68e..27e5dc4183 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 @@ -155,6 +155,7 @@ public class GitDiffCommand extends AbstractGitCommand implements DiffCommand } catch (Exception ex) { + // TODO throw exception logger.error("could not create diff", ex); } finally diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogCommand.java index 1fa98e23b2..51d4748b6e 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogCommand.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogCommand.java @@ -57,6 +57,7 @@ import sonia.scm.util.IOUtil; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.List; /** @@ -150,9 +151,12 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand * @param request * * @return + * + * @throws IOException */ @Override public ChangesetPagingResult getChangesets(LogCommandRequest request) + throws IOException { if (logger.isDebugEnabled()) { @@ -242,11 +246,16 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand } catch (NoHeadException ex) { - logger.error("could not read changesets", ex); - } - catch (IOException ex) - { - logger.error("could not open repository", ex); + if (logger.isTraceEnabled()) + { + logger.trace("repository seems to be empty", ex); + } + else if (logger.isWarnEnabled()) + { + logger.warn("repository seems to be empty"); + } + + changesets = new ChangesetPagingResult(0, new ArrayList()); } finally {