for (String configN : configNames) {
if (configN.equals(configName)) {
Remote remote = new Remote(cloneLocation, db, configN);
JSONObject result = remote.toJSON();
if (!result.has(ProtocolConstants.KEY_CHILDREN)) {
return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, result);
}
JSONArray children = result.getJSONArray(ProtocolConstants.KEY_CHILDREN);
JSONArray filteredChildren = new JSONArray();
if (children.length() == 0 || (commitsSize == 0 && pageSize < 0)) {
if (nameFilter != null && !nameFilter.equals("")) {
for (int i = 0; i < children.length(); i++) {
JSONObject test = (JSONObject) children.get(i);
String name = (String) test.get("Name");
if (name.toLowerCase().contains(nameFilter.toLowerCase())) {
filteredChildren.put(test);
}
}
result.put(ProtocolConstants.KEY_CHILDREN, filteredChildren);
}
return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, result);
}
int firstChild = pageSize > 0 ? pageSize * (pageNo - 1) : 0;
int lastChild = pageSize > 0 ? firstChild + pageSize - 1 : children.length() - 1;
lastChild = lastChild > children.length() - 1 ? children.length() - 1 : lastChild;
if (pageNo > 1 && baseLocation != null) {
String prev = baseLocation + "?page=" + (pageNo - 1) + "&pageSize=" + pageSize;
if (commitsSize > 0) {
prev += "&" + GitConstants.KEY_TAG_COMMITS + "=" + commitsSize;
}
result.put(ProtocolConstants.KEY_PREVIOUS_LOCATION, prev);
}
if (lastChild < children.length() - 1) {
String next = baseLocation + "?page=" + (pageNo + 1) + "&pageSize=" + pageSize;
if (commitsSize > 0) {
next += "&" + GitConstants.KEY_TAG_COMMITS + "=" + commitsSize;
}
result.put(ProtocolConstants.KEY_NEXT_LOCATION, next);
}
JSONArray newChildren = new JSONArray();
for (int i = firstChild; i <= lastChild; i++) {
if (monitor.isCanceled()) {
return new Status(IStatus.CANCEL, GitActivator.PI_GIT, "Cancelled");
}
JSONObject branch = children.getJSONObject(i);
if (commitsSize == 0) {
newChildren.put(branch);
} else {
LogCommand lc = git.log();
String branchName = branch.getString(ProtocolConstants.KEY_ID);
ObjectId toObjectId = db.resolve(branchName);
Ref toRefId = db.getRef(branchName);
if (toObjectId == null) {
String msg = NLS.bind("No ref or commit found: {0}", branchName);
return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null);
}
toObjectId = getCommitObjectId(db, toObjectId);
// set the commit range
lc.add(toObjectId);
lc.setMaxCount(this.commitsSize);
Iterable<RevCommit> commits = lc.call();
Log log = new Log(cloneLocation, db, commits, null, null, toRefId);
log.setPaging(1, commitsSize);
branch.put(GitConstants.KEY_TAG_COMMIT, log.toJSON());
newChildren.put(branch);
}
}
result.put(ProtocolConstants.KEY_CHILDREN, newChildren);
return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, result);
}
}
String msg = NLS.bind("Couldn't find remote : {0}", configName);
return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null);
} catch (Exception e) {
String msg = NLS.bind("Couldn't get remote details : {0}", configName);
return new Status(IStatus.ERROR, GitActivator.PI_GIT, msg, e);
} finally {
if (db != null) {