Search in sources :

Example 11 with CommitInfo

use of com.google.gerrit.extensions.common.CommitInfo in project gerrit by GerritCodeReview.

the class StickyApprovalsIT method updateFirstParent.

private void updateFirstParent(String changeId) throws Exception {
    ChangeInfo c = detailedChange(changeId);
    List<CommitInfo> parents = c.revisions.get(c.currentRevision).commit.parents;
    String parent1 = parents.get(0).commit;
    String parent2 = parents.get(1).commit;
    RevCommit commitParent2 = testRepo.getRevWalk().parseCommit(ObjectId.fromString(parent2));
    testRepo.reset(parent1);
    PushOneCommit.Result newParent1 = createChange("new parent 1", "p1-1.txt", "content 1-1");
    PushOneCommit merge = pushFactory.create(db, admin.getIdent(), testRepo, changeId);
    merge.setParents(ImmutableList.of(newParent1.getCommit(), commitParent2));
    PushOneCommit.Result result = merge.to("refs/for/master");
    result.assertOkStatus();
    assertThat(getChangeKind(changeId)).isEqualTo(MERGE_FIRST_PARENT_UPDATE);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) CommitInfo(com.google.gerrit.extensions.common.CommitInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 12 with CommitInfo

use of com.google.gerrit.extensions.common.CommitInfo in project gerrit by GerritCodeReview.

the class GetRelatedIT method changeAndCommit.

private static ChangeAndCommit changeAndCommit(PatchSet.Id psId, ObjectId commitId, int currentRevisionNum) {
    ChangeAndCommit result = new ChangeAndCommit();
    result._changeNumber = psId.getParentKey().get();
    result.commit = new CommitInfo();
    result.commit.commit = commitId.name();
    result._revisionNumber = psId.get();
    result._currentRevisionNumber = currentRevisionNum;
    result.status = "NEW";
    return result;
}
Also used : CommitInfo(com.google.gerrit.extensions.common.CommitInfo) ChangeAndCommit(com.google.gerrit.server.change.GetRelated.ChangeAndCommit)

Example 13 with CommitInfo

use of com.google.gerrit.extensions.common.CommitInfo in project gerrit by GerritCodeReview.

the class GetCommit method apply.

@Override
public Response<CommitInfo> apply(RevisionResource rsrc) throws IOException {
    Project.NameKey p = rsrc.getChange().getProject();
    try (Repository repo = repoManager.openRepository(p);
        RevWalk rw = new RevWalk(repo)) {
        String rev = rsrc.getPatchSet().getRevision().get();
        RevCommit commit = rw.parseCommit(ObjectId.fromString(rev));
        rw.parseBody(commit);
        CommitInfo info = json.noOptions().toCommit(rsrc.getControl(), rw, commit, addLinks, true);
        Response<CommitInfo> r = Response.ok(info);
        if (rsrc.isCacheable()) {
            r.caching(CacheControl.PRIVATE(7, TimeUnit.DAYS));
        }
        return r;
    }
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) Repository(org.eclipse.jgit.lib.Repository) CommitInfo(com.google.gerrit.extensions.common.CommitInfo) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 14 with CommitInfo

use of com.google.gerrit.extensions.common.CommitInfo in project gerrit by GerritCodeReview.

the class RevisionApiImpl method getMergeList.

@Override
public MergeListRequest getMergeList() throws RestApiException {
    return new MergeListRequest() {

        @Override
        public List<CommitInfo> get() throws RestApiException {
            try {
                GetMergeList gml = getMergeList.get();
                gml.setUninterestingParent(getUninterestingParent());
                gml.setAddLinks(getAddLinks());
                return gml.apply(revision).value();
            } catch (Exception e) {
                throw asRestApiException("Cannot get merge list", e);
            }
        }
    };
}
Also used : CommitInfo(com.google.gerrit.extensions.common.CommitInfo) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) GetMergeList(com.google.gerrit.server.change.GetMergeList)

Example 15 with CommitInfo

use of com.google.gerrit.extensions.common.CommitInfo in project gerrit by GerritCodeReview.

the class GetCommit method toCommitInfo.

private static CommitInfo toCommitInfo(RevCommit commit) {
    CommitInfo info = new CommitInfo();
    info.commit = commit.getName();
    info.author = CommonConverters.toGitPerson(commit.getAuthorIdent());
    info.committer = CommonConverters.toGitPerson(commit.getCommitterIdent());
    info.subject = commit.getShortMessage();
    info.message = commit.getFullMessage();
    info.parents = new ArrayList<>(commit.getParentCount());
    for (int i = 0; i < commit.getParentCount(); i++) {
        RevCommit p = commit.getParent(i);
        CommitInfo parentInfo = new CommitInfo();
        parentInfo.commit = p.getName();
        parentInfo.subject = p.getShortMessage();
        info.parents.add(parentInfo);
    }
    return info;
}
Also used : CommitInfo(com.google.gerrit.extensions.common.CommitInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

CommitInfo (com.google.gerrit.extensions.common.CommitInfo)15 RevCommit (org.eclipse.jgit.revwalk.RevCommit)9 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)6 Test (org.junit.Test)6 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)5 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)4 Project (com.google.gerrit.reviewdb.client.Project)4 WebLinkInfo (com.google.gerrit.extensions.common.WebLinkInfo)2 Repository (org.eclipse.jgit.lib.Repository)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 RestResponse (com.google.gerrit.acceptance.RestResponse)1 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)1 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)1 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)1 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)1 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)1 PatchSetWebLink (com.google.gerrit.extensions.webui.PatchSetWebLink)1