Search in sources :

Example 76 with PatchSet

use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.

the class ChangeRebuilderIT method patchSetsOutOfOrder.

@Test
public void patchSetsOutOfOrder() throws Exception {
    String id = createChange().getChangeId();
    amendChange(id);
    PushOneCommit.Result r = amendChange(id);
    ChangeData cd = r.getChange();
    PatchSet.Id psId3 = cd.change().currentPatchSetId();
    assertThat(psId3.get()).isEqualTo(3);
    PatchSet ps1 = db.patchSets().get(new PatchSet.Id(cd.getId(), 1));
    PatchSet ps3 = db.patchSets().get(psId3);
    assertThat(ps1.getCreatedOn()).isLessThan(ps3.getCreatedOn());
    // Simulate an old Gerrit bug by setting the created timestamp of the latest
    // patch set ID to the timestamp of PS1.
    ps3.setCreatedOn(ps1.getCreatedOn());
    db.patchSets().update(Collections.singleton(ps3));
    checker.rebuildAndCheckChanges(cd.getId());
    setNotesMigration(true, true);
    cd = changeDataFactory.create(db, project, cd.getId());
    assertThat(cd.change().currentPatchSetId()).isEqualTo(psId3);
    List<PatchSet> patchSets = ImmutableList.copyOf(cd.patchSets());
    assertThat(patchSets).hasSize(3);
    PatchSet newPs1 = patchSets.get(0);
    assertThat(newPs1.getId()).isEqualTo(ps1.getId());
    assertThat(newPs1.getCreatedOn()).isEqualTo(ps1.getCreatedOn());
    PatchSet newPs2 = patchSets.get(1);
    assertThat(newPs2.getCreatedOn()).isGreaterThan(newPs1.getCreatedOn());
    PatchSet newPs3 = patchSets.get(2);
    assertThat(newPs3.getId()).isEqualTo(ps3.getId());
    // Migrated with a newer timestamp than the original, to preserve ordering.
    assertThat(newPs3.getCreatedOn()).isAtLeast(newPs2.getCreatedOn());
    assertThat(newPs3.getCreatedOn()).isGreaterThan(ps1.getCreatedOn());
}
Also used : PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ChangeData(com.google.gerrit.server.query.change.ChangeData) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 77 with PatchSet

use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.

the class ConsistencyCheckerIT method expectedMergedCommitIsDanglingPatchSetOlderThanCurrent.

@Test
public void expectedMergedCommitIsDanglingPatchSetOlderThanCurrent() throws Exception {
    ChangeControl ctl = insertChange();
    PatchSet ps1 = psUtil.current(db, ctl.getNotes());
    // Create dangling ref so next ID in the database becomes 3.
    PatchSet.Id psId2 = new PatchSet.Id(ctl.getId(), 2);
    RevCommit commit2 = patchSetCommit(psId2);
    String rev2 = commit2.name();
    testRepo.branch(psId2.toRefName()).update(commit2);
    ctl = incrementPatchSet(ctl);
    PatchSet ps3 = psUtil.current(db, ctl.getNotes());
    assertThat(ps3.getId().get()).isEqualTo(3);
    testRepo.branch(ctl.getChange().getDest().get()).update(testRepo.getRevWalk().parseCommit(ObjectId.fromString(rev2)));
    FixInput fix = new FixInput();
    fix.expectMergedAs = rev2;
    assertProblems(ctl, fix, problem("No patch set found for merged commit " + rev2, FIXED, "Marked change as merged"), problem("Expected merge commit " + rev2 + " corresponds to patch set 2," + " not the current patch set 3", FIXED, "Deleted patch set"), problem("Expected merge commit " + rev2 + " corresponds to patch set 2," + " not the current patch set 3", FIXED, "Inserted as patch set 4"));
    ctl = reload(ctl);
    PatchSet.Id psId4 = new PatchSet.Id(ctl.getId(), 4);
    assertThat(ctl.getChange().currentPatchSetId()).isEqualTo(psId4);
    assertThat(ctl.getChange().getStatus()).isEqualTo(Change.Status.MERGED);
    assertThat(psUtil.byChangeAsMap(db, ctl.getNotes()).keySet()).containsExactly(ps1.getId(), ps3.getId(), psId4);
    assertThat(psUtil.get(db, ctl.getNotes(), psId4).getRevision().get()).isEqualTo(rev2);
}
Also used : ChangeControl(com.google.gerrit.server.project.ChangeControl) TestChanges.newPatchSet(com.google.gerrit.testutil.TestChanges.newPatchSet) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ObjectId(org.eclipse.jgit.lib.ObjectId) FixInput(com.google.gerrit.extensions.api.changes.FixInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 78 with PatchSet

use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.

the class MergeSuperSet method completeChangeSetWithoutTopic.

private ChangeSet completeChangeSetWithoutTopic(ReviewDb db, ChangeSet changes, CurrentUser user) throws IOException, OrmException {
    Collection<ChangeData> visibleChanges = new ArrayList<>();
    Collection<ChangeData> nonVisibleChanges = new ArrayList<>();
    // For each target branch we run a separate rev walk to find open changes
    // reachable from changes already in the merge super set.
    ImmutableListMultimap<Branch.NameKey, ChangeData> bc = byBranch(Iterables.concat(changes.changes(), changes.nonVisibleChanges()));
    for (Branch.NameKey b : bc.keySet()) {
        OpenRepo or = getRepo(b.getParentKey());
        List<RevCommit> visibleCommits = new ArrayList<>();
        List<RevCommit> nonVisibleCommits = new ArrayList<>();
        for (ChangeData cd : bc.get(b)) {
            checkState(cd.hasChangeControl(), "completeChangeSet forgot to set changeControl for current user" + " at ChangeData creation time");
            boolean visible = changes.ids().contains(cd.getId());
            if (visible && !cd.changeControl().isVisible(db, cd)) {
                // We thought the change was visible, but it isn't.
                // This can happen if the ACL changes during the
                // completeChangeSet computation, for example.
                visible = false;
            }
            Collection<RevCommit> toWalk = visible ? visibleCommits : nonVisibleCommits;
            // Pick a revision to use for traversal.  If any of the patch sets
            // is visible, we use the most recent one.  Otherwise, use the current
            // patch set.
            PatchSet ps = cd.currentPatchSet();
            boolean visiblePatchSet = visible;
            if (!cd.changeControl().isPatchVisible(ps, cd)) {
                Iterable<PatchSet> visiblePatchSets = cd.visiblePatchSets();
                if (Iterables.isEmpty(visiblePatchSets)) {
                    visiblePatchSet = false;
                } else {
                    ps = Iterables.getLast(visiblePatchSets);
                }
            }
            if (submitType(cd, ps, visiblePatchSet) == SubmitType.CHERRY_PICK) {
                if (visible) {
                    visibleChanges.add(cd);
                } else {
                    nonVisibleChanges.add(cd);
                }
                continue;
            }
            // Get the underlying git commit object
            String objIdStr = ps.getRevision().get();
            RevCommit commit = or.rw.parseCommit(ObjectId.fromString(objIdStr));
            // Always include the input, even if merged. This allows
            // SubmitStrategyOp to correct the situation later, assuming it gets
            // returned by byCommitsOnBranchNotMerged below.
            toWalk.add(commit);
        }
        Set<String> emptySet = Collections.emptySet();
        Set<String> visibleHashes = walkChangesByHashes(visibleCommits, emptySet, or, b);
        List<ChangeData> cds = byCommitsOnBranchNotMerged(or, db, user, b, visibleHashes);
        for (ChangeData chd : cds) {
            chd.changeControl(user);
            visibleChanges.add(chd);
        }
        Set<String> nonVisibleHashes = walkChangesByHashes(nonVisibleCommits, visibleHashes, or, b);
        Iterables.addAll(nonVisibleChanges, byCommitsOnBranchNotMerged(or, db, user, b, nonVisibleHashes));
    }
    return new ChangeSet(visibleChanges, nonVisibleChanges);
}
Also used : ArrayList(java.util.ArrayList) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ChangeData(com.google.gerrit.server.query.change.ChangeData) Branch(com.google.gerrit.reviewdb.client.Branch) OpenRepo(com.google.gerrit.server.git.MergeOpRepoManager.OpenRepo) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 79 with PatchSet

use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.

the class ChangeData method ensureCurrentPatchSetLoaded.

public static void ensureCurrentPatchSetLoaded(Iterable<ChangeData> changes) throws OrmException {
    ChangeData first = Iterables.getFirst(changes, null);
    if (first == null) {
        return;
    } else if (first.notesMigration.readChanges()) {
        for (ChangeData cd : changes) {
            cd.currentPatchSet();
        }
        return;
    }
    Map<PatchSet.Id, ChangeData> missing = new HashMap<>();
    for (ChangeData cd : changes) {
        if (cd.currentPatchSet == null && cd.patchSets == null) {
            missing.put(cd.change().currentPatchSetId(), cd);
        }
    }
    if (missing.isEmpty()) {
        return;
    }
    for (PatchSet ps : first.db.patchSets().get(missing.keySet())) {
        missing.get(ps.getId()).currentPatchSet = ps;
    }
}
Also used : HashMap(java.util.HashMap) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ObjectId(org.eclipse.jgit.lib.ObjectId)

Example 80 with PatchSet

use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.

the class ChangeData method loadCommitData.

private boolean loadCommitData() throws OrmException, RepositoryNotFoundException, IOException, MissingObjectException, IncorrectObjectTypeException {
    PatchSet ps = currentPatchSet();
    if (ps == null) {
        return false;
    }
    String sha1 = ps.getRevision().get();
    try (Repository repo = repoManager.openRepository(project());
        RevWalk walk = new RevWalk(repo)) {
        RevCommit c = walk.parseCommit(ObjectId.fromString(sha1));
        commitMessage = c.getFullMessage();
        commitFooters = c.getFooterLines();
        author = c.getAuthorIdent();
        committer = c.getCommitterIdent();
    }
    return true;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

PatchSet (com.google.gerrit.reviewdb.client.PatchSet)124 Change (com.google.gerrit.reviewdb.client.Change)51 Test (org.junit.Test)44 ObjectId (org.eclipse.jgit.lib.ObjectId)35 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)27 RevCommit (org.eclipse.jgit.revwalk.RevCommit)26 Repository (org.eclipse.jgit.lib.Repository)21 RevId (com.google.gerrit.reviewdb.client.RevId)20 ChangeControl (com.google.gerrit.server.project.ChangeControl)20 ChangeData (com.google.gerrit.server.query.change.ChangeData)19 OrmException (com.google.gwtorm.server.OrmException)19 Timestamp (java.sql.Timestamp)18 RevWalk (org.eclipse.jgit.revwalk.RevWalk)15 Project (com.google.gerrit.reviewdb.client.Project)14 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)11 TestChanges.newPatchSet (com.google.gerrit.testutil.TestChanges.newPatchSet)11 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)10 Account (com.google.gerrit.reviewdb.client.Account)10