Name things

This commit is contained in:
René Pfeuffer
2018-10-17 08:05:29 +02:00
parent a67d26575a
commit 8c46a7f714

View File

@@ -38,7 +38,6 @@ package sonia.scm.repository.spi;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader; import org.eclipse.jgit.lib.ObjectLoader;
@@ -282,15 +281,14 @@ public class GitBrowseCommand extends AbstractGitCommand
} }
else else
{ {
// TODO throw exception throw new IllegalStateException("could not find tree for " + revId.name());
logger.error("could not find tree for {}", revId.name());
} }
if (isRootRequest(request)) { if (isRootRequest(request)) {
result = createEmtpyRoot(); result = createEmtpyRoot();
findChildren(result, repo, request, revId, treeWalk); findChildren(result, repo, request, revId, treeWalk);
} else { } else {
result = first(repo, request, revId, treeWalk); result = findFirstMatch(repo, request, revId, treeWalk);
if ( result.isDirectory() ) { if ( result.isDirectory() ) {
treeWalk.enterSubtree(); treeWalk.enterSubtree();
findChildren(result, repo, request, revId, treeWalk); findChildren(result, repo, request, revId, treeWalk);
@@ -338,19 +336,19 @@ public class GitBrowseCommand extends AbstractGitCommand
return null; return null;
} }
private FileObject first(org.eclipse.jgit.lib.Repository repo, private FileObject findFirstMatch(org.eclipse.jgit.lib.Repository repo,
BrowseCommandRequest request, ObjectId revId, TreeWalk treeWalk) throws IOException, NotFoundException { BrowseCommandRequest request, ObjectId revId, TreeWalk treeWalk) throws IOException, NotFoundException {
String[] parts = request.getPath().split("/"); String[] pathElements = request.getPath().split("/");
int current = 0; int currentDepth = 0;
int limit = parts.length; int limit = pathElements.length;
while (treeWalk.next()) { while (treeWalk.next()) {
String name = treeWalk.getNameString(); String name = treeWalk.getNameString();
if (name.equalsIgnoreCase(parts[current])) { if (name.equalsIgnoreCase(pathElements[currentDepth])) {
current++; currentDepth++;
if (current >= limit) { if (currentDepth >= limit) {
return createFileObject(repo, request, revId, treeWalk); return createFileObject(repo, request, revId, treeWalk);
} else { } else {
treeWalk.enterSubtree(); treeWalk.enterSubtree();