Search in sources :

Example 1 with RevisionJson

use of com.google.gerrit.server.change.RevisionJson in project gerrit by GerritCodeReview.

the class GetMergeList method apply.

@Override
public Response<List<CommitInfo>> apply(RevisionResource rsrc) throws BadRequestException, IOException {
    Project.NameKey p = rsrc.getChange().getProject();
    try (Repository repo = repoManager.openRepository(p);
        RevWalk rw = new RevWalk(repo)) {
        RevCommit commit = rw.parseCommit(rsrc.getPatchSet().commitId());
        rw.parseBody(commit);
        if (uninterestingParent < 1 || uninterestingParent > commit.getParentCount()) {
            throw new BadRequestException("No such parent: " + uninterestingParent);
        }
        if (commit.getParentCount() < 2) {
            return createResponse(rsrc, ImmutableList.of());
        }
        List<RevCommit> commits = MergeListBuilder.build(rw, commit, uninterestingParent);
        List<CommitInfo> result = new ArrayList<>(commits.size());
        RevisionJson changeJson = json.create(ImmutableSet.of());
        for (RevCommit c : commits) {
            result.add(changeJson.getCommitInfo(rsrc.getProject(), rw, c, addLinks, /* fillCommit= */
            true, rsrc.getChange().getDest().branch()));
        }
        return createResponse(rsrc, result);
    }
}
Also used : Project(com.google.gerrit.entities.Project) Repository(org.eclipse.jgit.lib.Repository) ArrayList(java.util.ArrayList) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) CommitInfo(com.google.gerrit.extensions.common.CommitInfo) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevisionJson(com.google.gerrit.server.change.RevisionJson) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

Project (com.google.gerrit.entities.Project)1 CommitInfo (com.google.gerrit.extensions.common.CommitInfo)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 RevisionJson (com.google.gerrit.server.change.RevisionJson)1 ArrayList (java.util.ArrayList)1 Repository (org.eclipse.jgit.lib.Repository)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 RevWalk (org.eclipse.jgit.revwalk.RevWalk)1