}
List<CommitMongo> commits = new FetchValidCommitsQuery(mongoConnection,
fromRevisionId, toRevisionId).execute();
CommitMongo toCommit = getCommit(commits, toRevisionId);
CommitMongo fromCommit;
if (toRevisionId.equals(fromRevisionId)) {
fromCommit = toCommit;
} else {
fromCommit = getCommit(commits, fromRevisionId);
if (fromCommit == null || (fromCommit.getTimestamp() > toCommit.getTimestamp())) {
// negative range, return empty journal
return "[]";
}
}
JsopBuilder commitBuff = new JsopBuilder().array();
// iterate over commits in chronological order,
// starting with oldest commit
for (int i = commits.size() - 1; i >= 0; i--) {
CommitMongo commit = commits.get(i);
//if (commit.getParentId() == null) {
// continue;
//}
String diff = commit.getDiff();
// FIXME Check that filter really works.
if (!filtered || commit.getAffectedPaths().contains(path)) {
commitBuff.object()
.key("id").value(String.valueOf(commit.getRevisionId()))
.key("ts").value(commit.getTimestamp())
.key("msg").value(commit.getMessage())
.key("changes").value(diff).endObject();
}
}
return commitBuff.endArray().toString();
}