mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-01 19:15:52 +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 java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.tmatesoft.svn.core.SVNErrorCode.FS_NO_SUCH_REVISION;
|
||||
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
||||
@@ -73,6 +74,8 @@ public class SvnBrowseCommand extends AbstractSvnCommand
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(SvnBrowseCommand.class);
|
||||
|
||||
private int resultCount = 0;
|
||||
|
||||
SvnBrowseCommand(SvnContext context, Repository repository)
|
||||
{
|
||||
super(context, repository);
|
||||
@@ -128,11 +131,13 @@ public class SvnBrowseCommand extends AbstractSvnCommand
|
||||
throws SVNException
|
||||
{
|
||||
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);
|
||||
|
||||
if (resultCount >= request.getProceedFrom()) {
|
||||
parent.addChild(child);
|
||||
}
|
||||
|
||||
if (child.isDirectory() && request.isRecursive()) {
|
||||
traverse(svnRepository, revisionNumber, request, child, createBasePath(child.getPath()));
|
||||
|
||||
@@ -40,10 +40,10 @@ import sonia.scm.repository.FileObject;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
@@ -65,7 +65,17 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
||||
|
||||
@Test
|
||||
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 c = getFileObject(foList, "c");
|
||||
@@ -140,7 +150,17 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
||||
|
||||
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");
|
||||
|
||||
@@ -168,6 +188,32 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
||||
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
|
||||
*
|
||||
@@ -198,17 +244,4 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
||||
.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