}
walk = new RevWalk(repo);
// add try catch to catch failures
RevCommit commit = walk.parseCommit(head);
RevTree tree = commit.getTree();
treeWalk = new TreeWalk(repo);
treeWalk.addTree(tree);
treeWalk.setRecursive(false);
if (!pattern.equals("")) { //$NON-NLS-1$
PathFilter pathFilter = PathFilter.create(pattern);
treeWalk.setFilter(pathFilter);
}
JSONArray contents = new JSONArray();
JSONObject result = null;
ArrayList<JSONObject> parents = new ArrayList<JSONObject>();
URI baseLocation = ServletResourceHandler.getURI(request);
Path basePath = new Path(baseLocation.getPath());
IPath tmp = new Path("/"); //$NON-NLS-1$
for (int i = 0; i < 5; i++) {
tmp = tmp.append(basePath.segment(i));
}
URI cloneLocation = new URI(baseLocation.getScheme(), baseLocation.getAuthority(), tmp.toPortableString(), null, baseLocation.getFragment());
JSONObject ref = listEntry(gitSegment, 0, true, 0, cloneLocation, GitUtils.encode(gitSegment));
parents.add(ref);
parents.add(listEntry(new Path(cloneLocation.getPath()).lastSegment(), 0, true, 0, cloneLocation, null));
URI locationWalk = URIUtil.append(cloneLocation, GitUtils.encode(gitSegment));
while (treeWalk.next()) {
if (treeWalk.isSubtree()) {
if (treeWalk.getPathLength() > pattern.length()) {
String name = treeWalk.getNameString();
contents.put(listEntry(name, 0, true, 0, locationWalk, name));
}
if (treeWalk.getPathLength() <= pattern.length()) {
locationWalk = URIUtil.append(locationWalk, treeWalk.getNameString());
parents.add(0, listEntry(treeWalk.getNameString(), 0, true, 0, locationWalk, null));
treeWalk.enterSubtree();
}
} else {
ObjectId objId = treeWalk.getObjectId(0);
ObjectLoader loader = repo.open(objId);
long size = loader.getSize();
if (treeWalk.getPathLength() == pattern.length()) {
if ("meta".equals(meta)) { //$NON-NLS-1$
result = listEntry(treeWalk.getNameString(), 0, false, 0, locationWalk, treeWalk.getNameString());
} else {
return getFileContents(request, response, repo, treeWalk, tree);
}
} else {
String name = treeWalk.getNameString();
contents.put(listEntry(name, 0, false, size, locationWalk, name));
}
}
}
if (result == null) {
result = parents.remove(0);
result.put("Children", contents); //$NON-NLS-1$
}
result.put("Parents", new JSONArray(parents)); //$NON-NLS-1$
response.setContentType("application/json"); //$NON-NLS-1$
response.setHeader("Cache-Control", "no-cache"); //$NON-NLS-1$
response.setHeader("ETag", "\"" + tree.getId().getName() + "\""); //$NON-NLS-1$
OrionServlet.writeJSONResponse(request, response, result);
return true;
} catch (Exception e) {
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"An error occured when requesting commit info.", e));