mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-01 11:05:56 +01:00
Implement request limit for svn
This commit is contained in:
@@ -52,6 +52,7 @@ import sonia.scm.repository.SvnUtil;
|
|||||||
import sonia.scm.util.Util;
|
import sonia.scm.util.Util;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import static org.tmatesoft.svn.core.SVNErrorCode.FS_NO_SUCH_REVISION;
|
import static org.tmatesoft.svn.core.SVNErrorCode.FS_NO_SUCH_REVISION;
|
||||||
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
||||||
@@ -73,6 +74,8 @@ public class SvnBrowseCommand extends AbstractSvnCommand
|
|||||||
private static final Logger logger =
|
private static final Logger logger =
|
||||||
LoggerFactory.getLogger(SvnBrowseCommand.class);
|
LoggerFactory.getLogger(SvnBrowseCommand.class);
|
||||||
|
|
||||||
|
private int resultCount = 0;
|
||||||
|
|
||||||
SvnBrowseCommand(SvnContext context, Repository repository)
|
SvnBrowseCommand(SvnContext context, Repository repository)
|
||||||
{
|
{
|
||||||
super(context, repository);
|
super(context, repository);
|
||||||
@@ -128,11 +131,13 @@ public class SvnBrowseCommand extends AbstractSvnCommand
|
|||||||
throws SVNException
|
throws SVNException
|
||||||
{
|
{
|
||||||
Collection<SVNDirEntry> entries = svnRepository.getDir(parent.getPath(), revisionNumber, null, (Collection) null);
|
Collection<SVNDirEntry> entries = svnRepository.getDir(parent.getPath(), revisionNumber, null, (Collection) null);
|
||||||
for (SVNDirEntry entry : entries)
|
for (Iterator<SVNDirEntry> iterator = entries.iterator(); resultCount < request.getLimit() + request.getProceedFrom() && iterator.hasNext(); ++resultCount) {
|
||||||
{
|
SVNDirEntry entry = iterator.next();
|
||||||
FileObject child = createFileObject(request, svnRepository, revisionNumber, entry, basePath);
|
FileObject child = createFileObject(request, svnRepository, revisionNumber, entry, basePath);
|
||||||
|
|
||||||
parent.addChild(child);
|
if (resultCount >= request.getProceedFrom()) {
|
||||||
|
parent.addChild(child);
|
||||||
|
}
|
||||||
|
|
||||||
if (child.isDirectory() && request.isRecursive()) {
|
if (child.isDirectory() && request.isRecursive()) {
|
||||||
traverse(svnRepository, revisionNumber, request, child, createBasePath(child.getPath()));
|
traverse(svnRepository, revisionNumber, request, child, createBasePath(child.getPath()));
|
||||||
|
|||||||
@@ -40,10 +40,10 @@ import sonia.scm.repository.FileObject;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,7 +65,17 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBrowse() {
|
public void testBrowse() {
|
||||||
Collection<FileObject> foList = getRootFromTip(new BrowseCommandRequest());
|
BrowserResult result = createCommand().getBrowserResult(new BrowseCommandRequest());
|
||||||
|
|
||||||
|
assertNotNull(result);
|
||||||
|
|
||||||
|
Collection<FileObject> foList1 = result.getFile().getChildren();
|
||||||
|
|
||||||
|
assertNotNull(foList1);
|
||||||
|
assertFalse(foList1.isEmpty());
|
||||||
|
assertEquals(2, foList1.size());
|
||||||
|
|
||||||
|
Collection<FileObject> foList = foList1;
|
||||||
|
|
||||||
FileObject a = getFileObject(foList, "a.txt");
|
FileObject a = getFileObject(foList, "a.txt");
|
||||||
FileObject c = getFileObject(foList, "c");
|
FileObject c = getFileObject(foList, "c");
|
||||||
@@ -140,14 +150,24 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
|||||||
|
|
||||||
request.setDisableLastCommit(true);
|
request.setDisableLastCommit(true);
|
||||||
|
|
||||||
Collection<FileObject> foList = getRootFromTip(request);
|
BrowserResult result = createCommand().getBrowserResult(request);
|
||||||
|
|
||||||
|
assertNotNull(result);
|
||||||
|
|
||||||
|
Collection<FileObject> foList1 = result.getFile().getChildren();
|
||||||
|
|
||||||
|
assertNotNull(foList1);
|
||||||
|
assertFalse(foList1.isEmpty());
|
||||||
|
assertEquals(2, foList1.size());
|
||||||
|
|
||||||
|
Collection<FileObject> foList = foList1;
|
||||||
|
|
||||||
FileObject a = getFileObject(foList, "a.txt");
|
FileObject a = getFileObject(foList, "a.txt");
|
||||||
|
|
||||||
assertFalse(a.getDescription().isPresent());
|
assertFalse(a.getDescription().isPresent());
|
||||||
assertFalse(a.getCommitDate().isPresent());
|
assertFalse(a.getCommitDate().isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRecursive() {
|
public void testRecursive() {
|
||||||
BrowseCommandRequest request = new BrowseCommandRequest();
|
BrowseCommandRequest request = new BrowseCommandRequest();
|
||||||
@@ -168,6 +188,32 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
|||||||
assertEquals(2, c.getChildren().size());
|
assertEquals(2, c.getChildren().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLimit() {
|
||||||
|
BrowseCommandRequest request = new BrowseCommandRequest();
|
||||||
|
request.setLimit(1);
|
||||||
|
BrowserResult result = createCommand().getBrowserResult(request);
|
||||||
|
|
||||||
|
assertNotNull(result);
|
||||||
|
|
||||||
|
Collection<FileObject> foList = result.getFile().getChildren();
|
||||||
|
|
||||||
|
assertThat(foList).extracting("name").containsExactlyInAnyOrder("a.txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testProceedFrom() {
|
||||||
|
BrowseCommandRequest request = new BrowseCommandRequest();
|
||||||
|
request.setProceedFrom(1);
|
||||||
|
BrowserResult result = createCommand().getBrowserResult(request);
|
||||||
|
|
||||||
|
assertNotNull(result);
|
||||||
|
|
||||||
|
Collection<FileObject> foList = result.getFile().getChildren();
|
||||||
|
|
||||||
|
assertThat(foList).extracting("name").containsExactlyInAnyOrder("c");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -198,17 +244,4 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
|||||||
.orElseThrow(() -> new AssertionError("file " + name + " not found"));
|
.orElseThrow(() -> new AssertionError("file " + name + " not found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection<FileObject> getRootFromTip(BrowseCommandRequest request) {
|
|
||||||
BrowserResult result = createCommand().getBrowserResult(request);
|
|
||||||
|
|
||||||
assertNotNull(result);
|
|
||||||
|
|
||||||
Collection<FileObject> foList = result.getFile().getChildren();
|
|
||||||
|
|
||||||
assertNotNull(foList);
|
|
||||||
assertFalse(foList.isEmpty());
|
|
||||||
assertEquals(2, foList.size());
|
|
||||||
|
|
||||||
return foList;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user