mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-17 10:41:06 +01:00
improve performance of git repository api
This commit is contained in:
@@ -35,11 +35,8 @@ package sonia.scm.repository.spi;
|
|||||||
|
|
||||||
import org.eclipse.jgit.lib.Repository;
|
import org.eclipse.jgit.lib.Repository;
|
||||||
|
|
||||||
import sonia.scm.repository.GitUtil;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,14 +50,16 @@ public class AbstractGitCommand
|
|||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
* @param repository
|
* @param repository
|
||||||
* @param repositoryDirectory
|
* @param repositoryDirectory
|
||||||
*/
|
*/
|
||||||
protected AbstractGitCommand(sonia.scm.repository.Repository repository,
|
protected AbstractGitCommand(GitContext context,
|
||||||
File repositoryDirectory)
|
sonia.scm.repository.Repository repository)
|
||||||
{
|
{
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.repositoryDirectory = repositoryDirectory;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
@@ -75,14 +74,14 @@ public class AbstractGitCommand
|
|||||||
*/
|
*/
|
||||||
protected Repository open() throws IOException
|
protected Repository open() throws IOException
|
||||||
{
|
{
|
||||||
return GitUtil.open(repositoryDirectory);
|
return context.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
protected sonia.scm.repository.Repository repository;
|
protected GitContext context;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
protected File repositoryDirectory;
|
protected sonia.scm.repository.Repository repository;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ import sonia.scm.repository.RepositoryException;
|
|||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -78,12 +77,14 @@ public class GitBlameCommand extends AbstractGitCommand implements BlameCommand
|
|||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
* @param repository
|
* @param repository
|
||||||
* @param repositoryDirectory
|
* @param repositoryDirectory
|
||||||
*/
|
*/
|
||||||
public GitBlameCommand(Repository repository, File repositoryDirectory)
|
public GitBlameCommand(GitContext context, Repository repository)
|
||||||
{
|
{
|
||||||
super(repository, repositoryDirectory);
|
super(context, repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
@@ -111,14 +112,7 @@ public class GitBlameCommand extends AbstractGitCommand implements BlameCommand
|
|||||||
Preconditions.checkArgument(!Strings.isNullOrEmpty(request.getPath()),
|
Preconditions.checkArgument(!Strings.isNullOrEmpty(request.getPath()),
|
||||||
"path is empty or null");
|
"path is empty or null");
|
||||||
|
|
||||||
org.eclipse.jgit.blame.BlameResult gitBlameResult = null;
|
org.eclipse.jgit.lib.Repository gr = open();
|
||||||
sonia.scm.repository.BlameResult blameResult = null;
|
|
||||||
org.eclipse.jgit.lib.Repository gr = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
gr = open();
|
|
||||||
|
|
||||||
org.eclipse.jgit.api.BlameCommand blame = new Git(gr).blame();
|
org.eclipse.jgit.api.BlameCommand blame = new Git(gr).blame();
|
||||||
|
|
||||||
blame.setFilePath(request.getPath());
|
blame.setFilePath(request.getPath());
|
||||||
@@ -126,13 +120,13 @@ public class GitBlameCommand extends AbstractGitCommand implements BlameCommand
|
|||||||
ObjectId revId = GitUtil.getRevisionId(gr, request.getRevision());
|
ObjectId revId = GitUtil.getRevisionId(gr, request.getRevision());
|
||||||
|
|
||||||
blame.setStartCommit(revId);
|
blame.setStartCommit(revId);
|
||||||
gitBlameResult = blame.call();
|
|
||||||
|
org.eclipse.jgit.blame.BlameResult gitBlameResult = blame.call();
|
||||||
|
|
||||||
if (gitBlameResult == null)
|
if (gitBlameResult == null)
|
||||||
{
|
{
|
||||||
throw new RepositoryException(
|
throw new RepositoryException(
|
||||||
"could not create blame result for path ".concat(
|
"could not create blame result for path ".concat(request.getPath()));
|
||||||
request.getPath()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BlameLine> blameLines = new ArrayList<BlameLine>();
|
List<BlameLine> blameLines = new ArrayList<BlameLine>();
|
||||||
@@ -168,13 +162,6 @@ public class GitBlameCommand extends AbstractGitCommand implements BlameCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
blameResult = new sonia.scm.repository.BlameResult(i, blameLines);
|
return new sonia.scm.repository.BlameResult(i, blameLines);
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
GitUtil.close(gr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return blameResult;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ import sonia.scm.util.Util;
|
|||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -92,12 +91,14 @@ public class GitBrowseCommand extends AbstractGitCommand
|
|||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
* @param repository
|
* @param repository
|
||||||
* @param repositoryDirectory
|
* @param repositoryDirectory
|
||||||
*/
|
*/
|
||||||
public GitBrowseCommand(Repository repository, File repositoryDirectory)
|
public GitBrowseCommand(GitContext context, Repository repository)
|
||||||
{
|
{
|
||||||
super(repository, repositoryDirectory);
|
super(context, repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
@@ -109,20 +110,21 @@ public class GitBrowseCommand extends AbstractGitCommand
|
|||||||
* @param request
|
* @param request
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* @throws RepositoryException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public BrowserResult getBrowserResult(BrowseCommandRequest request) throws IOException, RepositoryException
|
public BrowserResult getBrowserResult(BrowseCommandRequest request)
|
||||||
|
throws IOException, RepositoryException
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
if ( logger.isDebugEnabled() ){
|
|
||||||
logger.debug("try to create browse result for {}", request);
|
logger.debug("try to create browse result for {}", request);
|
||||||
}
|
}
|
||||||
|
|
||||||
BrowserResult result = null;
|
BrowserResult result = null;
|
||||||
org.eclipse.jgit.lib.Repository repo = null;
|
org.eclipse.jgit.lib.Repository repo = open();
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
repo = open();
|
|
||||||
|
|
||||||
ObjectId revId = null;
|
ObjectId revId = null;
|
||||||
|
|
||||||
if (Util.isEmpty(request.getRevision()))
|
if (Util.isEmpty(request.getRevision()))
|
||||||
@@ -152,11 +154,6 @@ public class GitBrowseCommand extends AbstractGitCommand
|
|||||||
result = new BrowserResult(Constants.HEAD, null, null,
|
result = new BrowserResult(Constants.HEAD, null, null,
|
||||||
new ArrayList<FileObject>());
|
new ArrayList<FileObject>());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
GitUtil.close(repo);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -457,8 +454,8 @@ public class GitBrowseCommand extends AbstractGitCommand
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
new GitCatCommand(repository, repositoryDirectory).getContent(repo,
|
new GitCatCommand(context, repository).getContent(repo, revision,
|
||||||
revision, PATH_MODULES, baos);
|
PATH_MODULES, baos);
|
||||||
subRepositories = GitSubModuleParser.parse(baos.toString());
|
subRepositories = GitSubModuleParser.parse(baos.toString());
|
||||||
}
|
}
|
||||||
catch (PathNotFoundException ex)
|
catch (PathNotFoundException ex)
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ import sonia.scm.util.Util;
|
|||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
@@ -75,13 +74,15 @@ public class GitCatCommand extends AbstractGitCommand implements CatCommand
|
|||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
* @param repository
|
* @param repository
|
||||||
* @param repositoryDirectory
|
* @param repositoryDirectory
|
||||||
*/
|
*/
|
||||||
public GitCatCommand(sonia.scm.repository.Repository repository,
|
public GitCatCommand(GitContext context,
|
||||||
File repositoryDirectory)
|
sonia.scm.repository.Repository repository)
|
||||||
{
|
{
|
||||||
super(repository, repositoryDirectory);
|
super(context, repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
@@ -107,19 +108,12 @@ public class GitCatCommand extends AbstractGitCommand implements CatCommand
|
|||||||
|
|
||||||
org.eclipse.jgit.lib.Repository repo = null;
|
org.eclipse.jgit.lib.Repository repo = null;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
repo = open();
|
repo = open();
|
||||||
|
|
||||||
ObjectId revId = GitUtil.getRevisionId(repo, request.getRevision());
|
ObjectId revId = GitUtil.getRevisionId(repo, request.getRevision());
|
||||||
|
|
||||||
getContent(repo, revId, request.getPath(), output);
|
getContent(repo, revId, request.getPath(), output);
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
GitUtil.close(repo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
|
|||||||
@@ -0,0 +1,121 @@
|
|||||||
|
/**
|
||||||
|
* 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. 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. 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.
|
||||||
|
*
|
||||||
|
* 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 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import sonia.scm.repository.GitUtil;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public class GitContext implements Closeable
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the logger for GitContext
|
||||||
|
*/
|
||||||
|
private static final Logger logger =
|
||||||
|
LoggerFactory.getLogger(GitContext.class);
|
||||||
|
|
||||||
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param directory
|
||||||
|
*/
|
||||||
|
public GitContext(File directory)
|
||||||
|
{
|
||||||
|
this.directory = directory;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void close()
|
||||||
|
{
|
||||||
|
if (logger.isTraceEnabled())
|
||||||
|
{
|
||||||
|
logger.trace("close git repository {}", directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
GitUtil.close(repository);
|
||||||
|
repository = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public org.eclipse.jgit.lib.Repository open() throws IOException
|
||||||
|
{
|
||||||
|
if (repository == null)
|
||||||
|
{
|
||||||
|
if (logger.isTraceEnabled())
|
||||||
|
{
|
||||||
|
logger.trace("open git repository {}", directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
repository = GitUtil.open(directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private File directory;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private org.eclipse.jgit.lib.Repository repository;
|
||||||
|
}
|
||||||
@@ -52,7 +52,6 @@ import sonia.scm.util.Util;
|
|||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -76,12 +75,14 @@ public class GitDiffCommand extends AbstractGitCommand implements DiffCommand
|
|||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
* @param repository
|
* @param repository
|
||||||
* @param repositoryDirectory
|
* @param repositoryDirectory
|
||||||
*/
|
*/
|
||||||
public GitDiffCommand(Repository repository, File repositoryDirectory)
|
public GitDiffCommand(GitContext context, Repository repository)
|
||||||
{
|
{
|
||||||
super(repository, repositoryDirectory);
|
super(context, repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
@@ -96,14 +97,14 @@ public class GitDiffCommand extends AbstractGitCommand implements DiffCommand
|
|||||||
@Override
|
@Override
|
||||||
public void getDiffResult(DiffCommandRequest request, OutputStream output)
|
public void getDiffResult(DiffCommandRequest request, OutputStream output)
|
||||||
{
|
{
|
||||||
org.eclipse.jgit.lib.Repository gr = null;
|
|
||||||
RevWalk walk = null;
|
RevWalk walk = null;
|
||||||
TreeWalk treeWalk = null;
|
TreeWalk treeWalk = null;
|
||||||
DiffFormatter formatter = null;
|
DiffFormatter formatter = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
gr = open();
|
org.eclipse.jgit.lib.Repository gr = open();
|
||||||
|
|
||||||
walk = new RevWalk(gr);
|
walk = new RevWalk(gr);
|
||||||
|
|
||||||
RevCommit commit = walk.parseCommit(gr.resolve(request.getRevision()));
|
RevCommit commit = walk.parseCommit(gr.resolve(request.getRevision()));
|
||||||
@@ -155,6 +156,7 @@ public class GitDiffCommand extends AbstractGitCommand implements DiffCommand
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
||||||
// TODO throw exception
|
// TODO throw exception
|
||||||
logger.error("could not create diff", ex);
|
logger.error("could not create diff", ex);
|
||||||
}
|
}
|
||||||
@@ -163,7 +165,6 @@ public class GitDiffCommand extends AbstractGitCommand implements DiffCommand
|
|||||||
GitUtil.release(walk);
|
GitUtil.release(walk);
|
||||||
GitUtil.release(treeWalk);
|
GitUtil.release(treeWalk);
|
||||||
GitUtil.release(formatter);
|
GitUtil.release(formatter);
|
||||||
GitUtil.close(gr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ import sonia.scm.util.IOUtil;
|
|||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -79,13 +78,14 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
|||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
* @param repository
|
* @param repository
|
||||||
* @param repositoryDirectory
|
* @param repositoryDirectory
|
||||||
*/
|
*/
|
||||||
GitLogCommand(sonia.scm.repository.Repository repository,
|
GitLogCommand(GitContext context, sonia.scm.repository.Repository repository)
|
||||||
File repositoryDirectory)
|
|
||||||
{
|
{
|
||||||
super(repository, repositoryDirectory);
|
super(context, repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
@@ -164,12 +164,11 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
ChangesetPagingResult changesets = null;
|
ChangesetPagingResult changesets = null;
|
||||||
org.eclipse.jgit.lib.Repository gr = null;
|
|
||||||
GitChangesetConverter converter = null;
|
GitChangesetConverter converter = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
gr = open();
|
org.eclipse.jgit.lib.Repository gr = open();
|
||||||
|
|
||||||
if (!gr.getAllRefs().isEmpty())
|
if (!gr.getAllRefs().isEmpty())
|
||||||
{
|
{
|
||||||
@@ -260,7 +259,6 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
IOUtil.close(converter);
|
IOUtil.close(converter);
|
||||||
GitUtil.close(gr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return changesets;
|
return changesets;
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import sonia.scm.repository.api.Command;
|
|||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -70,7 +70,21 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider
|
|||||||
Repository repository)
|
Repository repository)
|
||||||
{
|
{
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.repositoryDirectory = handler.getDirectory(repository);
|
context = new GitContext(handler.getDirectory(repository));
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException
|
||||||
|
{
|
||||||
|
context.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
@@ -84,7 +98,7 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider
|
|||||||
@Override
|
@Override
|
||||||
public BlameCommand getBlameCommand()
|
public BlameCommand getBlameCommand()
|
||||||
{
|
{
|
||||||
return new GitBlameCommand(repository, repositoryDirectory);
|
return new GitBlameCommand(context, repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,7 +110,7 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider
|
|||||||
@Override
|
@Override
|
||||||
public BrowseCommand getBrowseCommand()
|
public BrowseCommand getBrowseCommand()
|
||||||
{
|
{
|
||||||
return new GitBrowseCommand(repository, repositoryDirectory);
|
return new GitBrowseCommand(context, repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -108,7 +122,7 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider
|
|||||||
@Override
|
@Override
|
||||||
public CatCommand getCatCommand()
|
public CatCommand getCatCommand()
|
||||||
{
|
{
|
||||||
return new GitCatCommand(repository, repositoryDirectory);
|
return new GitCatCommand(context, repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,7 +134,7 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider
|
|||||||
@Override
|
@Override
|
||||||
public DiffCommand getDiffCommand()
|
public DiffCommand getDiffCommand()
|
||||||
{
|
{
|
||||||
return new GitDiffCommand(repository, repositoryDirectory);
|
return new GitDiffCommand(context, repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,7 +146,7 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider
|
|||||||
@Override
|
@Override
|
||||||
public LogCommand getLogCommand()
|
public LogCommand getLogCommand()
|
||||||
{
|
{
|
||||||
return new GitLogCommand(repository, repositoryDirectory);
|
return new GitLogCommand(context, repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,8 +164,8 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider
|
|||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Repository repository;
|
private GitContext context;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private File repositoryDirectory;
|
private Repository repository;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,10 @@
|
|||||||
|
|
||||||
package sonia.scm.repository.spi;
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
@@ -38,6 +42,34 @@ package sonia.scm.repository.spi;
|
|||||||
public class AbstractGitCommandTestBase extends ZippedRepositoryTestBase
|
public class AbstractGitCommandTestBase extends ZippedRepositoryTestBase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@After
|
||||||
|
public void close()
|
||||||
|
{
|
||||||
|
context.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected GitContext createContext()
|
||||||
|
{
|
||||||
|
if (context == null)
|
||||||
|
{
|
||||||
|
context = new GitContext(repositoryDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -61,4 +93,9 @@ public class AbstractGitCommandTestBase extends ZippedRepositoryTestBase
|
|||||||
{
|
{
|
||||||
return "sonia/scm/repository/spi/scm-git-spi-test.zip";
|
return "sonia/scm/repository/spi/scm-git-spi-test.zip";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private GitContext context;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,8 +66,7 @@ public class GitBlameCommandTest extends AbstractGitCommandTestBase
|
|||||||
|
|
||||||
request.setPath("a.txt");
|
request.setPath("a.txt");
|
||||||
|
|
||||||
BlameResult result = new GitBlameCommand(repository,
|
BlameResult result = createCommand().getBlameResult(request);
|
||||||
repositoryDirectory).getBlameResult(request);
|
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(2, result.getTotal());
|
assertEquals(2, result.getTotal());
|
||||||
@@ -103,8 +102,7 @@ public class GitBlameCommandTest extends AbstractGitCommandTestBase
|
|||||||
request.setPath("a.txt");
|
request.setPath("a.txt");
|
||||||
request.setRevision("86a6645eceefe8b9a247db5eb16e3d89a7e6e6d1");
|
request.setRevision("86a6645eceefe8b9a247db5eb16e3d89a7e6e6d1");
|
||||||
|
|
||||||
BlameResult result = new GitBlameCommand(repository,
|
BlameResult result = createCommand().getBlameResult(request);
|
||||||
repositoryDirectory).getBlameResult(request);
|
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(1, result.getTotal());
|
assertEquals(1, result.getTotal());
|
||||||
@@ -131,4 +129,15 @@ public class GitBlameCommandTest extends AbstractGitCommandTestBase
|
|||||||
assertEquals("Douglas Adams", line.getAuthor().getName());
|
assertEquals("Douglas Adams", line.getAuthor().getName());
|
||||||
assertEquals("douglas.adams@hitchhiker.com", line.getAuthor().getMail());
|
assertEquals("douglas.adams@hitchhiker.com", line.getAuthor().getMail());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private GitBlameCommand createCommand()
|
||||||
|
{
|
||||||
|
return new GitBlameCommand(createContext(), repository);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,10 +64,8 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase
|
|||||||
@Test
|
@Test
|
||||||
public void testBrowse() throws IOException, RepositoryException
|
public void testBrowse() throws IOException, RepositoryException
|
||||||
{
|
{
|
||||||
BrowserResult result = new GitBrowseCommand(
|
BrowserResult result =
|
||||||
repository,
|
createCommand().getBrowserResult(new BrowseCommandRequest());
|
||||||
repositoryDirectory).getBrowserResult(
|
|
||||||
new BrowseCommandRequest());
|
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
|
|
||||||
@@ -119,8 +117,7 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase
|
|||||||
|
|
||||||
request.setPath("c");
|
request.setPath("c");
|
||||||
|
|
||||||
BrowserResult result = new GitBrowseCommand(repository,
|
BrowserResult result = createCommand().getBrowserResult(request);
|
||||||
repositoryDirectory).getBrowserResult(request);
|
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
|
|
||||||
@@ -160,4 +157,15 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase
|
|||||||
assertTrue(e.getLength() > 0);
|
assertTrue(e.getLength() > 0);
|
||||||
checkDate(e.getLastModified());
|
checkDate(e.getLastModified());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private GitBrowseCommand createCommand()
|
||||||
|
{
|
||||||
|
return new GitBrowseCommand(createContext(), repository);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ public class GitCatCommandTest extends AbstractGitCommandTestBase
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
new GitCatCommand(repository, repositoryDirectory).getCatResult(request,
|
new GitCatCommand(createContext(), repository).getCatResult(request,
|
||||||
baos);
|
baos);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|||||||
@@ -63,10 +63,8 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
|||||||
@Test
|
@Test
|
||||||
public void testGetAll() throws IOException
|
public void testGetAll() throws IOException
|
||||||
{
|
{
|
||||||
ChangesetPagingResult result = new GitLogCommand(
|
ChangesetPagingResult result =
|
||||||
repository,
|
createCommand().getChangesets(new LogCommandRequest());
|
||||||
repositoryDirectory).getChangesets(
|
|
||||||
new LogCommandRequest());
|
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(5, result.getTotal());
|
assertEquals(5, result.getTotal());
|
||||||
@@ -86,8 +84,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
|||||||
|
|
||||||
request.setPath("a.txt");
|
request.setPath("a.txt");
|
||||||
|
|
||||||
ChangesetPagingResult result =
|
ChangesetPagingResult result = createCommand().getChangesets(request);
|
||||||
new GitLogCommand(repository, repositoryDirectory).getChangesets(request);
|
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(3, result.getTotal());
|
assertEquals(3, result.getTotal());
|
||||||
@@ -110,8 +107,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
|||||||
|
|
||||||
request.setPagingLimit(2);
|
request.setPagingLimit(2);
|
||||||
|
|
||||||
ChangesetPagingResult result =
|
ChangesetPagingResult result = createCommand().getChangesets(request);
|
||||||
new GitLogCommand(repository, repositoryDirectory).getChangesets(request);
|
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(5, result.getTotal());
|
assertEquals(5, result.getTotal());
|
||||||
@@ -142,8 +138,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
|||||||
request.setPagingStart(1);
|
request.setPagingStart(1);
|
||||||
request.setPagingLimit(2);
|
request.setPagingLimit(2);
|
||||||
|
|
||||||
ChangesetPagingResult result =
|
ChangesetPagingResult result = createCommand().getChangesets(request);
|
||||||
new GitLogCommand(repository, repositoryDirectory).getChangesets(request);
|
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(5, result.getTotal());
|
assertEquals(5, result.getTotal());
|
||||||
@@ -167,7 +162,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
|||||||
@Test
|
@Test
|
||||||
public void testGetCommit()
|
public void testGetCommit()
|
||||||
{
|
{
|
||||||
GitLogCommand command = new GitLogCommand(repository, repositoryDirectory);
|
GitLogCommand command = createCommand();
|
||||||
Changeset c = command.getChangeset("435df2f061add3589cb3");
|
Changeset c = command.getChangeset("435df2f061add3589cb3");
|
||||||
|
|
||||||
assertNotNull(c);
|
assertNotNull(c);
|
||||||
@@ -202,8 +197,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
|||||||
request.setStartChangeset("592d797cd36432e59141");
|
request.setStartChangeset("592d797cd36432e59141");
|
||||||
request.setEndChangeset("435df2f061add3589cb3");
|
request.setEndChangeset("435df2f061add3589cb3");
|
||||||
|
|
||||||
ChangesetPagingResult result =
|
ChangesetPagingResult result = createCommand().getChangesets(request);
|
||||||
new GitLogCommand(repository, repositoryDirectory).getChangesets(request);
|
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(2, result.getTotal());
|
assertEquals(2, result.getTotal());
|
||||||
@@ -217,4 +211,15 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
|||||||
assertNotNull(c2);
|
assertNotNull(c2);
|
||||||
assertEquals("435df2f061add3589cb3", c2.getId());
|
assertEquals("435df2f061add3589cb3", c2.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private GitLogCommand createCommand()
|
||||||
|
{
|
||||||
|
return new GitLogCommand(createContext(), repository);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user