mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
Implement proceed from for git
This commit is contained in:
@@ -315,6 +315,18 @@ public final class BrowseCommandBuilder
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Proceed the list from the given number on (zero based).
|
||||
*
|
||||
* @param proceedFrom The number of the entry, the result should start with (zero based).
|
||||
* All preceding entries will be omitted.
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public BrowseCommandBuilder setProceedFrom(int proceedFrom) {
|
||||
request.setProceedFrom(proceedFrom);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void updateCache(BrowserResult updatedResult) {
|
||||
if (!disableCache) {
|
||||
CacheKey key = new CacheKey(repository, request);
|
||||
|
||||
@@ -52,6 +52,7 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
|
||||
public static final int DEFAULT_REQUEST_LIMIT = 1000;
|
||||
|
||||
private static final long serialVersionUID = 7956624623516803183L;
|
||||
private int proceedFrom;
|
||||
|
||||
public BrowseCommandRequest() {
|
||||
this(null);
|
||||
@@ -203,6 +204,17 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Proceed the list from the given number on (zero based).
|
||||
*
|
||||
* @param proceedFrom The number of the entry, the result should start with (zero based).
|
||||
* All preceding entries will be omitted.
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public void setProceedFrom(int proceedFrom) {
|
||||
this.proceedFrom = proceedFrom;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -253,6 +265,15 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
|
||||
return limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* The number of the entry, the result start with. All preceding entries will be omitted.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public int getProceedFrom() {
|
||||
return proceedFrom;
|
||||
}
|
||||
|
||||
public void updateCache(BrowserResult update) {
|
||||
if (updater != null) {
|
||||
updater.accept(update);
|
||||
|
||||
@@ -253,7 +253,7 @@ public class GitBrowseCommand extends AbstractGitCommand
|
||||
|
||||
private FileObject findChildren(FileObject parent, org.eclipse.jgit.lib.Repository repo, BrowseCommandRequest request, ObjectId revId, TreeWalk treeWalk) throws IOException {
|
||||
List<FileObject> files = Lists.newArrayList();
|
||||
while (treeWalk.next() && resultCount < request.getLimit())
|
||||
while (treeWalk.next() && resultCount < request.getLimit() + request.getProceedFrom())
|
||||
{
|
||||
|
||||
FileObject fileObject = createFileObject(repo, request, revId, treeWalk);
|
||||
@@ -262,7 +262,9 @@ public class GitBrowseCommand extends AbstractGitCommand
|
||||
return fileObject;
|
||||
}
|
||||
|
||||
if (resultCount >= request.getProceedFrom()) {
|
||||
files.add(fileObject);
|
||||
}
|
||||
|
||||
++resultCount;
|
||||
|
||||
|
||||
@@ -249,6 +249,20 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase {
|
||||
assertThat(foList).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBrowseProceedFrom() throws IOException {
|
||||
BrowseCommandRequest request = new BrowseCommandRequest();
|
||||
request.setLimit(2);
|
||||
request.setProceedFrom(2);
|
||||
FileObject root = createCommand()
|
||||
.getBrowserResult(request).getFile();
|
||||
assertNotNull(root);
|
||||
|
||||
Collection<FileObject> foList = root.getChildren();
|
||||
|
||||
assertThat(foList).extracting("name").contains("c", "f.txt");
|
||||
}
|
||||
|
||||
private FileObject findFile(Collection<FileObject> foList, String name) {
|
||||
return foList.stream()
|
||||
.filter(f -> name.equals(f.getName()))
|
||||
|
||||
Reference in New Issue
Block a user