Implement request limit for svn

This commit is contained in:
Rene Pfeuffer
2020-02-18 12:56:20 +01:00
parent 9e7fd52f9d
commit 9afc3a9580
2 changed files with 58 additions and 20 deletions

View File

@@ -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);
parent.addChild(child);
if (resultCount >= request.getProceedFrom()) {
parent.addChild(child);
}
if (child.isDirectory() && request.isRecursive()) {
traverse(svnRepository, revisionNumber, request, child, createBasePath(child.getPath()));

View File

@@ -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,14 +150,24 @@ 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");
assertFalse(a.getDescription().isPresent());
assertFalse(a.getCommitDate().isPresent());
}
@Test
public void testRecursive() {
BrowseCommandRequest request = new BrowseCommandRequest();
@@ -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;
}
}