mirror of
				https://github.com/scm-manager/scm-manager.git
				synced 2025-10-31 18:46:07 +01:00 
			
		
		
		
	Fix offset in recursion
This commit is contained in:
		| @@ -135,17 +135,18 @@ public class SvnBrowseCommand extends AbstractSvnCommand | ||||
|   { | ||||
|     List<SVNDirEntry> entries = new ArrayList<>(svnRepository.getDir(parent.getPath(), revisionNumber, null, (Collection) null)); | ||||
|     sort(entries, entry -> entry.getKind() == SVNNodeKind.DIR, SVNDirEntry::getName); | ||||
|     for (Iterator<SVNDirEntry> iterator = entries.iterator(); resultCount < request.getLimit() + request.getOffset() && iterator.hasNext(); ++resultCount) { | ||||
|     for (Iterator<SVNDirEntry> iterator = entries.iterator(); resultCount < request.getLimit() + request.getOffset() && iterator.hasNext(); ) { | ||||
|       ++resultCount; | ||||
|       SVNDirEntry entry = iterator.next(); | ||||
|       FileObject child = createFileObject(request, svnRepository, revisionNumber, entry, basePath); | ||||
|  | ||||
|       if (resultCount >= request.getOffset()) { | ||||
|         parent.addChild(child); | ||||
|       } | ||||
|  | ||||
|       if (child.isDirectory() && request.isRecursive()) { | ||||
|         traverse(svnRepository, revisionNumber, request, child, createBasePath(child.getPath())); | ||||
|       } | ||||
|  | ||||
|       if (resultCount > request.getOffset()) { | ||||
|         parent.addChild(child); | ||||
|       } | ||||
|     } | ||||
|     if (resultCount >= request.getLimit() + request.getOffset()) { | ||||
|       parent.setTruncated(true); | ||||
|   | ||||
| @@ -206,6 +206,75 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase | ||||
|     assertThat(foList).extracting("name").containsExactly("a.txt"); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void testRecursiveLimit() throws IOException { | ||||
|     BrowseCommandRequest request = new BrowseCommandRequest(); | ||||
|  | ||||
|     request.setLimit(4); | ||||
|     request.setRecursive(true); | ||||
|  | ||||
|     FileObject root = createCommand().getBrowserResult(request).getFile(); | ||||
|  | ||||
|     Collection<FileObject> foList = root.getChildren(); | ||||
|  | ||||
|     assertThat(foList) | ||||
|       .extracting("name") | ||||
|       .containsExactly("c", "a.txt"); | ||||
|  | ||||
|     FileObject c = getFileObject(foList, "c"); | ||||
|  | ||||
|     Collection<FileObject> cChildren = c.getChildren(); | ||||
|     assertThat(cChildren) | ||||
|       .extracting("name") | ||||
|       .containsExactly("d.txt", "e.txt"); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void testRecursiveLimitInSubDir() throws IOException { | ||||
|     BrowseCommandRequest request = new BrowseCommandRequest(); | ||||
|  | ||||
|     request.setLimit(2); | ||||
|     request.setRecursive(true); | ||||
|  | ||||
|     FileObject root = createCommand().getBrowserResult(request).getFile(); | ||||
|  | ||||
|     Collection<FileObject> foList = root.getChildren(); | ||||
|  | ||||
|     assertThat(foList) | ||||
|       .extracting("name") | ||||
|       .containsExactly("c"); | ||||
|  | ||||
|     FileObject c = getFileObject(foList, "c"); | ||||
|  | ||||
|     Collection<FileObject> cChildren = c.getChildren(); | ||||
|     assertThat(cChildren) | ||||
|       .extracting("name") | ||||
|       .containsExactly("d.txt"); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void testRecursiveOffset() throws IOException { | ||||
|     BrowseCommandRequest request = new BrowseCommandRequest(); | ||||
|  | ||||
|     request.setOffset(2); | ||||
|     request.setRecursive(true); | ||||
|  | ||||
|     FileObject root = createCommand().getBrowserResult(request).getFile(); | ||||
|  | ||||
|     Collection<FileObject> foList = root.getChildren(); | ||||
|  | ||||
|     assertThat(foList) | ||||
|       .extracting("name") | ||||
|       .containsExactly("c", "a.txt"); | ||||
|  | ||||
|     FileObject c = getFileObject(foList, "c"); | ||||
|  | ||||
|     Collection<FileObject> cChildren = c.getChildren(); | ||||
|     assertThat(cChildren) | ||||
|       .extracting("name") | ||||
|       .containsExactly("e.txt"); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Method description | ||||
|    * | ||||
|   | ||||
		Reference in New Issue
	
	Block a user