mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 06:55:47 +01:00
improve performance of git repository api
This commit is contained in:
@@ -31,6 +31,10 @@
|
||||
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.junit.After;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -38,6 +42,34 @@ package sonia.scm.repository.spi;
|
||||
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
|
||||
*
|
||||
@@ -61,4 +93,9 @@ public class AbstractGitCommandTestBase extends ZippedRepositoryTestBase
|
||||
{
|
||||
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");
|
||||
|
||||
BlameResult result = new GitBlameCommand(repository,
|
||||
repositoryDirectory).getBlameResult(request);
|
||||
BlameResult result = createCommand().getBlameResult(request);
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(2, result.getTotal());
|
||||
@@ -103,8 +102,7 @@ public class GitBlameCommandTest extends AbstractGitCommandTestBase
|
||||
request.setPath("a.txt");
|
||||
request.setRevision("86a6645eceefe8b9a247db5eb16e3d89a7e6e6d1");
|
||||
|
||||
BlameResult result = new GitBlameCommand(repository,
|
||||
repositoryDirectory).getBlameResult(request);
|
||||
BlameResult result = createCommand().getBlameResult(request);
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(1, result.getTotal());
|
||||
@@ -131,4 +129,15 @@ public class GitBlameCommandTest extends AbstractGitCommandTestBase
|
||||
assertEquals("Douglas Adams", line.getAuthor().getName());
|
||||
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
|
||||
public void testBrowse() throws IOException, RepositoryException
|
||||
{
|
||||
BrowserResult result = new GitBrowseCommand(
|
||||
repository,
|
||||
repositoryDirectory).getBrowserResult(
|
||||
new BrowseCommandRequest());
|
||||
BrowserResult result =
|
||||
createCommand().getBrowserResult(new BrowseCommandRequest());
|
||||
|
||||
assertNotNull(result);
|
||||
|
||||
@@ -119,8 +117,7 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase
|
||||
|
||||
request.setPath("c");
|
||||
|
||||
BrowserResult result = new GitBrowseCommand(repository,
|
||||
repositoryDirectory).getBrowserResult(request);
|
||||
BrowserResult result = createCommand().getBrowserResult(request);
|
||||
|
||||
assertNotNull(result);
|
||||
|
||||
@@ -160,4 +157,15 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase
|
||||
assertTrue(e.getLength() > 0);
|
||||
checkDate(e.getLastModified());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private GitBrowseCommand createCommand()
|
||||
{
|
||||
return new GitBrowseCommand(createContext(), repository);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public class GitCatCommandTest extends AbstractGitCommandTestBase
|
||||
|
||||
try
|
||||
{
|
||||
new GitCatCommand(repository, repositoryDirectory).getCatResult(request,
|
||||
new GitCatCommand(createContext(), repository).getCatResult(request,
|
||||
baos);
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -63,10 +63,8 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
@Test
|
||||
public void testGetAll() throws IOException
|
||||
{
|
||||
ChangesetPagingResult result = new GitLogCommand(
|
||||
repository,
|
||||
repositoryDirectory).getChangesets(
|
||||
new LogCommandRequest());
|
||||
ChangesetPagingResult result =
|
||||
createCommand().getChangesets(new LogCommandRequest());
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(5, result.getTotal());
|
||||
@@ -86,8 +84,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
|
||||
request.setPath("a.txt");
|
||||
|
||||
ChangesetPagingResult result =
|
||||
new GitLogCommand(repository, repositoryDirectory).getChangesets(request);
|
||||
ChangesetPagingResult result = createCommand().getChangesets(request);
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(3, result.getTotal());
|
||||
@@ -110,8 +107,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
|
||||
request.setPagingLimit(2);
|
||||
|
||||
ChangesetPagingResult result =
|
||||
new GitLogCommand(repository, repositoryDirectory).getChangesets(request);
|
||||
ChangesetPagingResult result = createCommand().getChangesets(request);
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(5, result.getTotal());
|
||||
@@ -142,8 +138,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
request.setPagingStart(1);
|
||||
request.setPagingLimit(2);
|
||||
|
||||
ChangesetPagingResult result =
|
||||
new GitLogCommand(repository, repositoryDirectory).getChangesets(request);
|
||||
ChangesetPagingResult result = createCommand().getChangesets(request);
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(5, result.getTotal());
|
||||
@@ -167,7 +162,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
@Test
|
||||
public void testGetCommit()
|
||||
{
|
||||
GitLogCommand command = new GitLogCommand(repository, repositoryDirectory);
|
||||
GitLogCommand command = createCommand();
|
||||
Changeset c = command.getChangeset("435df2f061add3589cb3");
|
||||
|
||||
assertNotNull(c);
|
||||
@@ -202,8 +197,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
request.setStartChangeset("592d797cd36432e59141");
|
||||
request.setEndChangeset("435df2f061add3589cb3");
|
||||
|
||||
ChangesetPagingResult result =
|
||||
new GitLogCommand(repository, repositoryDirectory).getChangesets(request);
|
||||
ChangesetPagingResult result = createCommand().getChangesets(request);
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(2, result.getTotal());
|
||||
@@ -217,4 +211,15 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
assertNotNull(c2);
|
||||
assertEquals("435df2f061add3589cb3", c2.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private GitLogCommand createCommand()
|
||||
{
|
||||
return new GitLogCommand(createContext(), repository);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user