Search in sources :

Example 51 with PatchSet

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

the class ChangeBundle method diffPatchSetApprovals.

private static void diffPatchSetApprovals(List<String> diffs, ChangeBundle bundleA, ChangeBundle bundleB) {
    Map<PatchSetApproval.Key, PatchSetApproval> as = bundleA.filterPatchSetApprovals();
    Map<PatchSetApproval.Key, PatchSetApproval> bs = bundleB.filterPatchSetApprovals();
    for (PatchSetApproval.Key k : diffKeySets(diffs, as, bs)) {
        PatchSetApproval a = as.get(k);
        PatchSetApproval b = bs.get(k);
        String desc = describe(k);
        // ReviewDb allows timestamps before patch set was created, but NoteDb
        // truncates this to the patch set creation timestamp.
        //
        // ChangeRebuilder ensures all post-submit approvals happen after the
        // actual submit, so the timestamps may not line up. This shouldn't really
        // happen, because postSubmit shouldn't be set in ReviewDb until after the
        // change is submitted in ReviewDb, but you never know.
        //
        // Due to a quirk of PostReview, post-submit 0 votes might not have the
        // postSubmit bit set in ReviewDb. As these are only used for tombstone
        // purposes, ignore the postSubmit bit in NoteDb in this case.
        Timestamp ta = a.getGranted();
        Timestamp tb = b.getGranted();
        PatchSet psa = checkNotNull(bundleA.patchSets.get(a.getPatchSetId()));
        PatchSet psb = checkNotNull(bundleB.patchSets.get(b.getPatchSetId()));
        boolean excludeGranted = false;
        boolean excludePostSubmit = false;
        List<String> exclude = new ArrayList<>(1);
        if (bundleA.source == REVIEW_DB && bundleB.source == NOTE_DB) {
            excludeGranted = (ta.before(psa.getCreatedOn()) && tb.equals(psb.getCreatedOn())) || ta.compareTo(tb) < 0;
            excludePostSubmit = a.getValue() == 0 && b.isPostSubmit();
        } else if (bundleA.source == NOTE_DB && bundleB.source == REVIEW_DB) {
            excludeGranted = tb.before(psb.getCreatedOn()) && ta.equals(psa.getCreatedOn()) || tb.compareTo(ta) < 0;
            excludePostSubmit = b.getValue() == 0 && a.isPostSubmit();
        }
        // Legacy submit approvals may or may not have tags associated with them,
        // depending on whether ChangeRebuilder happened to group them with the
        // status change.
        boolean excludeTag = bundleA.source != bundleB.source && a.isLegacySubmit() && b.isLegacySubmit();
        if (excludeGranted) {
            exclude.add("granted");
        }
        if (excludePostSubmit) {
            exclude.add("postSubmit");
        }
        if (excludeTag) {
            exclude.add("tag");
        }
        diffColumnsExcluding(diffs, PatchSetApproval.class, desc, bundleA, a, bundleB, b, exclude);
    }
}
Also used : ArrayList(java.util.ArrayList) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Timestamp(java.sql.Timestamp)

Example 52 with PatchSet

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

the class ChangeNotes method getPatchSets.

public ImmutableSortedMap<PatchSet.Id, PatchSet> getPatchSets() {
    if (patchSets == null) {
        ImmutableSortedMap.Builder<PatchSet.Id, PatchSet> b = ImmutableSortedMap.orderedBy(comparing(PatchSet.Id::get));
        for (Map.Entry<PatchSet.Id, PatchSet> e : state.patchSets()) {
            b.put(e.getKey(), new PatchSet(e.getValue()));
        }
        patchSets = b.build();
    }
    return patchSets;
}
Also used : ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ObjectId(org.eclipse.jgit.lib.ObjectId) RevId(com.google.gerrit.reviewdb.client.RevId) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap)

Example 53 with PatchSet

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

the class PRED_uploader_1 method exec.

@Override
public Operation exec(Prolog engine) throws PrologException {
    engine.setB0();
    Term a1 = arg1.dereference();
    PatchSet patchSet = StoredValues.getPatchSet(engine);
    if (patchSet == null) {
        log.error("Failed to load current patch set of change " + StoredValues.getChange(engine).getChangeId());
        return engine.fail();
    }
    Account.Id uploaderId = patchSet.getUploader();
    if (!a1.unify(new StructureTerm(user, new IntegerTerm(uploaderId.get())), engine.trail)) {
        return engine.fail();
    }
    return cont;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Term(com.googlecode.prolog_cafe.lang.Term) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm)

Example 54 with PatchSet

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

the class ChangeBundleTest method latest.

private static List<PatchSet> latest(Change c) {
    PatchSet ps = new PatchSet(c.currentPatchSetId());
    ps.setCreatedOn(c.getLastUpdatedOn());
    return ImmutableList.of(ps);
}
Also used : PatchSet(com.google.gerrit.reviewdb.client.PatchSet)

Example 55 with PatchSet

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

the class ChangeBundleTest method diffChangesTakesMaxEntityTimestampFromReviewDb.

@Test
public void diffChangesTakesMaxEntityTimestampFromReviewDb() throws Exception {
    Change c1 = TestChanges.newChange(new Project.NameKey("project"), new Account.Id(100));
    PatchSet ps = new PatchSet(c1.currentPatchSetId());
    ps.setRevision(new RevId("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
    ps.setUploader(accountId);
    ps.setCreatedOn(TimeUtil.nowTs());
    PatchSetApproval a = new PatchSetApproval(new PatchSetApproval.Key(c1.currentPatchSetId(), accountId, new LabelId("Code-Review")), (short) 1, TimeUtil.nowTs());
    Change c2 = clone(c1);
    c2.setLastUpdatedOn(a.getGranted());
    // Both ReviewDb, exact match required.
    ChangeBundle b1 = new ChangeBundle(c1, messages(), patchSets(ps), approvals(a), comments(), reviewers(), REVIEW_DB);
    ChangeBundle b2 = new ChangeBundle(c2, messages(), patchSets(ps), approvals(a), comments(), reviewers(), REVIEW_DB);
    assertDiffs(b1, b2, "effective last updated time differs for Change.Id " + c1.getId() + ":" + " {2009-09-30 17:00:00.0} != {2009-09-30 17:00:12.0}");
    // NoteDb allows latest timestamp from all entities in bundle.
    b2 = new ChangeBundle(c2, messages(), patchSets(ps), approvals(a), comments(), reviewers(), NOTE_DB);
    assertNoDiffs(b1, b2);
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) Account(com.google.gerrit.reviewdb.client.Account) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) LabelId(com.google.gerrit.reviewdb.client.LabelId) RevId(com.google.gerrit.reviewdb.client.RevId) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Test(org.junit.Test)

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