mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
Add truncated flag for git
This commit is contained in:
@@ -87,7 +87,7 @@ public class FileObject implements LastModifiedAware, Serializable
|
|||||||
final FileObject other = (FileObject) obj;
|
final FileObject other = (FileObject) obj;
|
||||||
|
|
||||||
//J-
|
//J-
|
||||||
return Objects.equal(name, other.name)
|
return Objects.equal(name, other.name)
|
||||||
&& Objects.equal(path, other.path)
|
&& Objects.equal(path, other.path)
|
||||||
&& Objects.equal(directory, other.directory)
|
&& Objects.equal(directory, other.directory)
|
||||||
&& Objects.equal(description, other.description)
|
&& Objects.equal(description, other.description)
|
||||||
@@ -282,6 +282,10 @@ public class FileObject implements LastModifiedAware, Serializable
|
|||||||
return computationAborted;
|
return computationAborted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isTruncated() {
|
||||||
|
return truncated;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- set methods ----------------------------------------------------------
|
//~--- set methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -403,6 +407,10 @@ public class FileObject implements LastModifiedAware, Serializable
|
|||||||
this.children.add(child);
|
this.children.add(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTruncated(boolean truncated) {
|
||||||
|
this.truncated = truncated;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** file description */
|
/** file description */
|
||||||
@@ -435,4 +443,6 @@ public class FileObject implements LastModifiedAware, Serializable
|
|||||||
|
|
||||||
/** Children of this file (aka directory). */
|
/** Children of this file (aka directory). */
|
||||||
private Collection<FileObject> children = new ArrayList<>();
|
private Collection<FileObject> children = new ArrayList<>();
|
||||||
|
|
||||||
|
private boolean truncated;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ public class GitBrowseCommand extends AbstractGitCommand
|
|||||||
fileObject.setName("");
|
fileObject.setName("");
|
||||||
fileObject.setPath("");
|
fileObject.setPath("");
|
||||||
fileObject.setDirectory(true);
|
fileObject.setDirectory(true);
|
||||||
|
fileObject.setTruncated(false);
|
||||||
return fileObject;
|
return fileObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,7 +254,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() + request.getProceedFrom())
|
while (treeWalk.next() && ++resultCount <= request.getLimit() + request.getProceedFrom())
|
||||||
{
|
{
|
||||||
|
|
||||||
FileObject fileObject = createFileObject(repo, request, revId, treeWalk);
|
FileObject fileObject = createFileObject(repo, request, revId, treeWalk);
|
||||||
@@ -262,12 +263,10 @@ public class GitBrowseCommand extends AbstractGitCommand
|
|||||||
return fileObject;
|
return fileObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resultCount >= request.getProceedFrom()) {
|
if (resultCount > request.getProceedFrom()) {
|
||||||
files.add(fileObject);
|
files.add(fileObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
++resultCount;
|
|
||||||
|
|
||||||
if (request.isRecursive() && fileObject.isDirectory()) {
|
if (request.isRecursive() && fileObject.isDirectory()) {
|
||||||
treeWalk.enterSubtree();
|
treeWalk.enterSubtree();
|
||||||
FileObject rc = findChildren(fileObject, repo, request, revId, treeWalk);
|
FileObject rc = findChildren(fileObject, repo, request, revId, treeWalk);
|
||||||
@@ -279,6 +278,10 @@ public class GitBrowseCommand extends AbstractGitCommand
|
|||||||
|
|
||||||
parent.setChildren(files);
|
parent.setChildren(files);
|
||||||
|
|
||||||
|
if (resultCount > request.getLimit() + request.getProceedFrom()) {
|
||||||
|
parent.setTruncated(true);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase {
|
|||||||
BrowserResult result = createCommand().getBrowserResult(request);
|
BrowserResult result = createCommand().getBrowserResult(request);
|
||||||
FileObject fileObject = result.getFile();
|
FileObject fileObject = result.getFile();
|
||||||
assertEquals("a.txt", fileObject.getName());
|
assertEquals("a.txt", fileObject.getName());
|
||||||
|
assertFalse(fileObject.isTruncated());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -247,6 +248,7 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase {
|
|||||||
Collection<FileObject> foList = root.getChildren();
|
Collection<FileObject> foList = root.getChildren();
|
||||||
|
|
||||||
assertThat(foList).hasSize(2);
|
assertThat(foList).hasSize(2);
|
||||||
|
assertTrue(root.isTruncated());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -261,6 +263,7 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase {
|
|||||||
Collection<FileObject> foList = root.getChildren();
|
Collection<FileObject> foList = root.getChildren();
|
||||||
|
|
||||||
assertThat(foList).extracting("name").contains("c", "f.txt");
|
assertThat(foList).extracting("name").contains("c", "f.txt");
|
||||||
|
assertFalse(root.isTruncated());
|
||||||
}
|
}
|
||||||
|
|
||||||
private FileObject findFile(Collection<FileObject> foList, String name) {
|
private FileObject findFile(Collection<FileObject> foList, String name) {
|
||||||
|
|||||||
Reference in New Issue
Block a user