Example usage for org.eclipse.jgit.revwalk RevCommit getFooterLines

List of usage examples for org.eclipse.jgit.revwalk RevCommit getFooterLines

Introduction

In this page you can find the example usage for org.eclipse.jgit.revwalk RevCommit getFooterLines.

Prototype

public final List<String> getFooterLines(FooterKey keyName) 

Source Link

Document

Get the values of all footer lines with the given key.

Usage

From source file:com.google.gerrit.acceptance.GitUtil.java

License:Apache License

public static Optional<String> getChangeId(TestRepository<?> tr, ObjectId id) throws IOException {
    RevCommit c = tr.getRevWalk().parseCommit(id);
    tr.getRevWalk().parseBody(c);//from  w w  w . j  a va2s  .  c o  m
    List<String> ids = c.getFooterLines(FooterConstants.CHANGE_ID);
    if (ids.isEmpty()) {
        return Optional.absent();
    }
    return Optional.of(ids.get(ids.size() - 1));
}

From source file:com.google.gerrit.acceptance.rest.change.AbstractSubmit.java

License:Apache License

protected void assertCherryPick(TestRepository<?> testRepo, boolean contentMerge) throws IOException {
    assertRebase(testRepo, contentMerge);
    RevCommit remoteHead = getRemoteHead();
    assertThat(remoteHead.getFooterLines("Reviewed-On")).isNotEmpty();
    assertThat(remoteHead.getFooterLines("Reviewed-By")).isNotEmpty();
}

From source file:com.google.gerrit.acceptance.rest.change.SubmitByRebaseAlwaysIT.java

License:Apache License

@Test
@TestProjectInput(useContentMerge = InheritableBoolean.TRUE)
public void changeMessageOnSubmit() throws Exception {
    PushOneCommit.Result change1 = createChange();
    PushOneCommit.Result change2 = createChange();

    RegistrationHandle handle = changeMessageModifiers.add(new ChangeMessageModifier() {
        @Override/*from  ww  w  .j  a v a2  s  . c o m*/
        public String onSubmit(String newCommitMessage, RevCommit original, RevCommit mergeTip,
                Branch.NameKey destination) {
            List<String> custom = mergeTip.getFooterLines("Custom");
            if (!custom.isEmpty()) {
                newCommitMessage += "Custom-Parent: " + custom.get(0) + "\n";
            }
            return newCommitMessage + "Custom: " + destination.get();
        }
    });
    try {
        // change1 is a fast-forward, but should be rebased in cherry pick style
        // anyway, making change2 not a fast-forward, requiring a rebase.
        approve(change1.getChangeId());
        submit(change2.getChangeId());
    } finally {
        handle.remove();
    }
    // ... but both changes should get custom footers.
    assertThat(getCurrentCommit(change1).getFooterLines("Custom")).containsExactly("refs/heads/master");
    assertThat(getCurrentCommit(change2).getFooterLines("Custom")).containsExactly("refs/heads/master");
    assertThat(getCurrentCommit(change2).getFooterLines("Custom-Parent")).containsExactly("refs/heads/master");
}

From source file:com.google.gerrit.acceptance.rest.change.SubmitByRebaseAlwaysIT.java

License:Apache License

private void assertLatestRevisionHasFooters(PushOneCommit.Result change) throws Exception {
    RevCommit c = getCurrentCommit(change);
    assertThat(c.getFooterLines(FooterConstants.CHANGE_ID)).isNotEmpty();
    assertThat(c.getFooterLines(FooterConstants.REVIEWED_BY)).isNotEmpty();
    assertThat(c.getFooterLines(FooterConstants.REVIEWED_ON)).isNotEmpty();
}

From source file:com.google.gerrit.acceptance.server.change.ConsistencyCheckerIT.java

License:Apache License

@Test
public void createNewPatchSetForExpectedMergeCommitWithNoChangeId() throws Exception {
    Change c = insertChange();/*w  w w . ja  v  a 2s .  co  m*/
    c.setStatus(Change.Status.MERGED);
    RevCommit parent = testRepo.branch(c.getDest().get()).commit().message("parent").create();
    PatchSet ps = insertPatchSet(c);
    RevCommit commit = parseCommit(ps);

    RevCommit mergedAs = testRepo.commit().parent(parent).message(commit.getShortMessage()).create();
    testRepo.getRevWalk().parseBody(mergedAs);
    assertThat(mergedAs.getFooterLines(FooterConstants.CHANGE_ID)).isEmpty();
    testRepo.update(c.getDest().get(), mergedAs);

    assertProblems(c, "Patch set 1 (" + commit.name() + ") is not merged into"
            + " destination ref refs/heads/master (" + mergedAs.name() + "), but change status is MERGED");

    FixInput fix = new FixInput();
    fix.expectMergedAs = mergedAs.name();
    List<ProblemInfo> problems = checker.check(c, fix).problems();
    assertThat(problems).hasSize(1);
    ProblemInfo p = problems.get(0);
    assertThat(p.message).isEqualTo("No patch set found for merged commit " + mergedAs.name());
    assertThat(p.status).isEqualTo(ProblemInfo.Status.FIXED);
    assertThat(p.outcome).isEqualTo("Inserted as patch set 2");

    c = db.changes().get(c.getId());
    PatchSet.Id psId2 = new PatchSet.Id(c.getId(), 2);
    assertThat(c.currentPatchSetId()).isEqualTo(psId2);
    assertThat(db.patchSets().get(psId2).getRevision().get()).isEqualTo(mergedAs.name());

    assertProblems(c);
}

From source file:com.google.gerrit.acceptance.server.change.ConsistencyCheckerIT.java

License:Apache License

@Test
public void createNewPatchSetForExpectedMergeCommitWithChangeId() throws Exception {
    Change c = insertChange();/*from  ww w .ja  va  2 s  . c o m*/
    c.setStatus(Change.Status.MERGED);
    RevCommit parent = testRepo.branch(c.getDest().get()).commit().message("parent").create();
    PatchSet ps = insertPatchSet(c);
    RevCommit commit = parseCommit(ps);

    RevCommit mergedAs = testRepo.commit().parent(parent)
            .message(commit.getShortMessage() + "\n" + "\n" + "Change-Id: " + c.getKey().get() + "\n").create();
    testRepo.getRevWalk().parseBody(mergedAs);
    assertThat(mergedAs.getFooterLines(FooterConstants.CHANGE_ID)).containsExactly(c.getKey().get());
    testRepo.update(c.getDest().get(), mergedAs);

    assertProblems(c, "Patch set 1 (" + commit.name() + ") is not merged into"
            + " destination ref refs/heads/master (" + mergedAs.name() + "), but change status is MERGED");

    FixInput fix = new FixInput();
    fix.expectMergedAs = mergedAs.name();
    List<ProblemInfo> problems = checker.check(c, fix).problems();
    assertThat(problems).hasSize(1);
    ProblemInfo p = problems.get(0);
    assertThat(p.message).isEqualTo("No patch set found for merged commit " + mergedAs.name());
    assertThat(p.status).isEqualTo(ProblemInfo.Status.FIXED);
    assertThat(p.outcome).isEqualTo("Inserted as patch set 2");

    c = db.changes().get(c.getId());
    PatchSet.Id psId2 = new PatchSet.Id(c.getId(), 2);
    assertThat(c.currentPatchSetId()).isEqualTo(psId2);
    assertThat(db.patchSets().get(psId2).getRevision().get()).isEqualTo(mergedAs.name());

    assertProblems(c);
}

From source file:com.google.gerrit.httpd.rpc.project.ReviewProjectAccess.java

License:Apache License

private static Change.Key getChangeId(RevCommit commit) {
    List<String> idList = commit.getFooterLines(FooterConstants.CHANGE_ID);
    Change.Key changeKey = !idList.isEmpty() ? new Change.Key(idList.get(idList.size() - 1).trim())
            : new Change.Key("I" + commit.name());
    return changeKey;
}

From source file:com.google.gerrit.server.change.ConsistencyChecker.java

License:Apache License

private void checkExpectMergedAs() {
    ObjectId objId = parseObjectId(fix.expectMergedAs, "expected merged commit");
    RevCommit commit = parseCommit(objId, "expected merged commit");
    if (commit == null) {
        return;/*from  w ww.ja v a 2 s.c o m*/
    }
    if (Objects.equals(commit, currPsCommit)) {
        // Caller gave us latest patch set SHA-1; verified in checkPatchSets.
        return;
    }

    try {
        if (!rw.isMergedInto(commit, tip)) {
            problem(String.format("Expected merged commit %s is not merged into" + " destination ref %s (%s)",
                    commit.name(), change.getDest().get(), tip.name()));
            return;
        }

        RevId revId = new RevId(commit.name());
        List<PatchSet> patchSets = FluentIterable.from(db.get().patchSets().byRevision(revId))
                .filter(new Predicate<PatchSet>() {
                    @Override
                    public boolean apply(PatchSet ps) {
                        try {
                            Change c = db.get().changes().get(ps.getId().getParentKey());
                            return c != null && c.getDest().equals(change.getDest());
                        } catch (OrmException e) {
                            warn(e);
                            return true; // Should cause an error below, that's good.
                        }
                    }
                }).toSortedList(ChangeUtil.PS_ID_ORDER);
        switch (patchSets.size()) {
        case 0:
            // No patch set for this commit; insert one.
            rw.parseBody(commit);
            String changeId = Iterables.getFirst(commit.getFooterLines(FooterConstants.CHANGE_ID), null);
            // Missing Change-Id footer is ok, but mismatched is not.
            if (changeId != null && !changeId.equals(change.getKey().get())) {
                problem(String.format("Expected merged commit %s has Change-Id: %s," + " but expected %s",
                        commit.name(), changeId, change.getKey().get()));
                return;
            }
            PatchSet ps = insertPatchSet(commit);
            if (ps != null) {
                checkMergedBitMatchesStatus(ps, commit, true);
            }
            break;

        case 1:
            // Existing patch set of this commit; check that it is the current
            // patch set.
            // TODO(dborowitz): This could be fixed if it's an older patch set of
            // the current change.
            PatchSet.Id id = patchSets.get(0).getId();
            if (!id.equals(change.currentPatchSetId())) {
                problem(String.format(
                        "Expected merged commit %s corresponds to"
                                + " patch set %s, which is not the current patch set %s",
                        commit.name(), id, change.currentPatchSetId()));
            }
            break;

        default:
            problem(String.format("Multiple patch sets for expected merged commit %s: %s", commit.name(),
                    patchSets));
            break;
        }
    } catch (OrmException | IOException e) {
        error("Error looking up expected merged commit " + fix.expectMergedAs, e);
    }
}

From source file:com.google.gerrit.server.change.CreateChange.java

License:Apache License

private static Change.Key getChangeId(ObjectId id, RevCommit emptyCommit) {
    List<String> idList = emptyCommit.getFooterLines(FooterConstants.CHANGE_ID);
    Change.Key changeKey = !idList.isEmpty() ? new Change.Key(idList.get(idList.size() - 1).trim())
            : new Change.Key("I" + id.name());
    return changeKey;
}

From source file:com.google.gerrit.server.git.CreateCodeReviewNotes.java

License:Apache License

private ObjectId createNoteContent(Change change, RevCommit commit)
        throws CodeReviewNoteCreationException, IOException {
    try {// w w  w . j ava  2  s .c  om
        ReviewNoteHeaderFormatter formatter = new ReviewNoteHeaderFormatter(author.getTimeZone());
        final List<String> idList = commit.getFooterLines(CHANGE_ID);
        if (idList.isEmpty())
            formatter.appendChangeId(change.getKey());
        ResultSet<PatchSetApproval> approvals = schema.patchSetApprovals()
                .byPatchSet(change.currentPatchSetId());
        PatchSetApproval submit = null;
        for (PatchSetApproval a : approvals) {
            if (a.getValue() == 0) {
                // Ignore 0 values.
            } else if (ApprovalCategory.SUBMIT.equals(a.getCategoryId())) {
                submit = a;
            } else {
                ApprovalType type = approvalTypes.byId(a.getCategoryId());
                if (type != null) {
                    formatter.appendApproval(type.getCategory(), a.getValue(),
                            accountCache.get(a.getAccountId()).getAccount());
                }
            }
        }

        if (submit != null) {
            formatter.appendSubmittedBy(accountCache.get(submit.getAccountId()).getAccount());
            formatter.appendSubmittedAt(submit.getGranted());
        }
        if (canonicalWebUrl != null) {
            formatter.appendReviewedOn(canonicalWebUrl, change.getId());
        }
        formatter.appendProject(change.getProject().get());
        formatter.appendBranch(change.getDest());
        return inserter.insert(Constants.OBJ_BLOB, formatter.toString().getBytes("UTF-8"));
    } catch (OrmException e) {
        throw new CodeReviewNoteCreationException(commit, e);
    }
}