mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 17:05:43 +01:00
Implement proceed from for git
This commit is contained in:
@@ -315,6 +315,18 @@ public final class BrowseCommandBuilder
|
|||||||
return this;
|
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) {
|
private void updateCache(BrowserResult updatedResult) {
|
||||||
if (!disableCache) {
|
if (!disableCache) {
|
||||||
CacheKey key = new CacheKey(repository, request);
|
CacheKey key = new CacheKey(repository, request);
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
|
|||||||
public static final int DEFAULT_REQUEST_LIMIT = 1000;
|
public static final int DEFAULT_REQUEST_LIMIT = 1000;
|
||||||
|
|
||||||
private static final long serialVersionUID = 7956624623516803183L;
|
private static final long serialVersionUID = 7956624623516803183L;
|
||||||
|
private int proceedFrom;
|
||||||
|
|
||||||
public BrowseCommandRequest() {
|
public BrowseCommandRequest() {
|
||||||
this(null);
|
this(null);
|
||||||
@@ -203,6 +204,17 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
|
|||||||
this.limit = limit;
|
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 ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -253,6 +265,15 @@ public final class BrowseCommandRequest extends FileBaseCommandRequest
|
|||||||
return limit;
|
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) {
|
public void updateCache(BrowserResult update) {
|
||||||
if (updater != null) {
|
if (updater != null) {
|
||||||
updater.accept(update);
|
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 {
|
private FileObject findChildren(FileObject parent, org.eclipse.jgit.lib.Repository repo, BrowseCommandRequest request, ObjectId revId, TreeWalk treeWalk) throws IOException {
|
||||||
List<FileObject> files = Lists.newArrayList();
|
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);
|
FileObject fileObject = createFileObject(repo, request, revId, treeWalk);
|
||||||
@@ -262,7 +262,9 @@ public class GitBrowseCommand extends AbstractGitCommand
|
|||||||
return fileObject;
|
return fileObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
files.add(fileObject);
|
if (resultCount >= request.getProceedFrom()) {
|
||||||
|
files.add(fileObject);
|
||||||
|
}
|
||||||
|
|
||||||
++resultCount;
|
++resultCount;
|
||||||
|
|
||||||
|
|||||||
@@ -249,6 +249,20 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase {
|
|||||||
assertThat(foList).hasSize(2);
|
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) {
|
private FileObject findFile(Collection<FileObject> foList, String name) {
|
||||||
return foList.stream()
|
return foList.stream()
|
||||||
.filter(f -> name.equals(f.getName()))
|
.filter(f -> name.equals(f.getName()))
|
||||||
|
|||||||
Reference in New Issue
Block a user