use of com.google.gerrit.server.project.CommitResource in project gerrit by GerritCodeReview.
the class CommitsCollection method parse.
@Override
public CommitResource parse(ProjectResource parent, IdString id) throws RestApiException, IOException {
parent.getProjectState().checkStatePermitsRead();
ObjectId objectId;
try {
objectId = ObjectId.fromString(id.get());
} catch (IllegalArgumentException e) {
throw new ResourceNotFoundException(id, e);
}
try (Repository repo = repoManager.openRepository(parent.getNameKey());
RevWalk rw = new RevWalk(repo)) {
RevCommit commit = rw.parseCommit(objectId);
if (!canRead(parent.getProjectState(), repo, commit)) {
throw new ResourceNotFoundException(id);
}
// GetCommit depends on the body of both the commit and parent being parsed, to get the
// subject.
rw.parseBody(commit);
for (int i = 0; i < commit.getParentCount(); i++) {
rw.parseBody(rw.parseCommit(commit.getParent(i)));
}
return new CommitResource(parent, commit);
} catch (MissingObjectException | IncorrectObjectTypeException e) {
throw new ResourceNotFoundException(id, e);
}
}
Aggregations