Search in sources :

Example 26 with PatchSetApproval

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

the class ChangeNotesParser method updatePatchSetStates.

private void updatePatchSetStates() {
    Set<PatchSet.Id> missing = new TreeSet<>(ReviewDbUtil.intKeyOrdering());
    for (Iterator<PatchSet> it = patchSets.values().iterator(); it.hasNext(); ) {
        PatchSet ps = it.next();
        if (ps.getRevision().equals(PARTIAL_PATCH_SET)) {
            missing.add(ps.getId());
            it.remove();
        }
    }
    for (Map.Entry<PatchSet.Id, PatchSetState> e : patchSetStates.entrySet()) {
        switch(e.getValue()) {
            case PUBLISHED:
            default:
                break;
            case DELETED:
                patchSets.remove(e.getKey());
                break;
            case DRAFT:
                PatchSet ps = patchSets.get(e.getKey());
                if (ps != null) {
                    ps.setDraft(true);
                }
                break;
        }
    }
    // Post-process other collections to remove items corresponding to deleted
    // (or otherwise missing) patch sets. This is safer than trying to prevent
    // insertion, as it will also filter out items racily added after the patch
    // set was deleted.
    changeMessagesByPatchSet.keys().retainAll(patchSets.keySet());
    int pruned = pruneEntitiesForMissingPatchSets(allChangeMessages, ChangeMessage::getPatchSetId, missing);
    pruned += pruneEntitiesForMissingPatchSets(comments.values(), c -> new PatchSet.Id(id, c.key.patchSetId), missing);
    pruned += pruneEntitiesForMissingPatchSets(approvals.values(), PatchSetApproval::getPatchSetId, missing);
    if (!missing.isEmpty()) {
        log.warn("ignoring {} additional entities due to missing patch sets: {}", pruned, missing);
    }
}
Also used : PatchLineComment(com.google.gerrit.reviewdb.client.PatchLineComment) FOOTER_SUBMITTED_WITH(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_SUBMITTED_WITH) ListMultimap(com.google.common.collect.ListMultimap) MultimapBuilder(com.google.common.collect.MultimapBuilder) LoggerFactory(org.slf4j.LoggerFactory) FOOTER_HASHTAGS(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_HASHTAGS) HashBasedTable(com.google.common.collect.HashBasedTable) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) ReviewerSet(com.google.gerrit.server.ReviewerSet) FooterKey(org.eclipse.jgit.revwalk.FooterKey) FOOTER_ASSIGNEE(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_ASSIGNEE) Comment(com.google.gerrit.reviewdb.client.Comment) InvalidObjectIdException(org.eclipse.jgit.errors.InvalidObjectIdException) FOOTER_PATCH_SET_DESCRIPTION(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_PATCH_SET_DESCRIPTION) Tables(com.google.common.collect.Tables) Locale(java.util.Locale) Map(java.util.Map) GitDateParser(org.eclipse.jgit.util.GitDateParser) ParseException(java.text.ParseException) Splitter(com.google.common.base.Splitter) NoteMap(org.eclipse.jgit.notes.NoteMap) LinkedListMultimap(com.google.common.collect.LinkedListMultimap) Timer1(com.google.gerrit.metrics.Timer1) FOOTER_WORK_IN_PROGRESS(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_WORK_IN_PROGRESS) CHANGES(com.google.gerrit.server.notedb.NoteDbTable.CHANGES) ImmutableSet(com.google.common.collect.ImmutableSet) FOOTER_SUBJECT(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_SUBJECT) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) RawParseUtils(org.eclipse.jgit.util.RawParseUtils) ChangeNotesRevWalk(com.google.gerrit.server.notedb.ChangeNotesCommit.ChangeNotesRevWalk) Set(java.util.Set) ReviewerStatusUpdate(com.google.gerrit.server.ReviewerStatusUpdate) LabelType(com.google.gerrit.common.data.LabelType) Collectors.joining(java.util.stream.Collectors.joining) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) PersonIdent(org.eclipse.jgit.lib.PersonIdent) List(java.util.List) FOOTER_STATUS(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_STATUS) RefNames(com.google.gerrit.reviewdb.client.RefNames) AutoValue(com.google.auto.value.AutoValue) Optional(java.util.Optional) FOOTER_LABEL(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_LABEL) LabelId(com.google.gerrit.reviewdb.client.LabelId) FOOTER_READ_ONLY_UNTIL(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_READ_ONLY_UNTIL) FOOTER_SUBMISSION_ID(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_SUBMISSION_ID) FOOTER_COMMIT(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_COMMIT) FOOTER_CHANGE_ID(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_CHANGE_ID) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) Change(com.google.gerrit.reviewdb.client.Change) HashMap(java.util.HashMap) Function(java.util.function.Function) TreeSet(java.util.TreeSet) Enums(com.google.common.base.Enums) SubmitRecord(com.google.gerrit.common.data.SubmitRecord) ArrayList(java.util.ArrayList) FOOTER_TAG(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_TAG) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) FOOTER_REAL_USER(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_REAL_USER) Lists(com.google.common.collect.Lists) Charset(java.nio.charset.Charset) Account(com.google.gerrit.reviewdb.client.Account) FOOTER_BRANCH(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_BRANCH) FOOTER_PATCH_SET(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_PATCH_SET) FOOTER_GROUPS(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_GROUPS) FOOTER_PRIVATE(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_PRIVATE) FOOTER_TOPIC(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_TOPIC) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) FOOTER_CURRENT(com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_CURRENT) ReviewDbUtil(com.google.gerrit.reviewdb.server.ReviewDbUtil) IOException(java.io.IOException) Ints(com.google.common.primitives.Ints) ObjectId(org.eclipse.jgit.lib.ObjectId) Address(com.google.gerrit.server.mail.Address) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) LabelVote(com.google.gerrit.server.util.LabelVote) ReviewerByEmailSet(com.google.gerrit.server.ReviewerByEmailSet) Table(com.google.common.collect.Table) Collections(java.util.Collections) ObjectReader(org.eclipse.jgit.lib.ObjectReader) RevId(com.google.gerrit.reviewdb.client.RevId) TreeSet(java.util.TreeSet) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) LabelId(com.google.gerrit.reviewdb.client.LabelId) ObjectId(org.eclipse.jgit.lib.ObjectId) RevId(com.google.gerrit.reviewdb.client.RevId) Map(java.util.Map) NoteMap(org.eclipse.jgit.notes.NoteMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 27 with PatchSetApproval

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

the class ChangeNotesParser method parseRemoveApproval.

private PatchSetApproval parseRemoveApproval(PatchSet.Id psId, Account.Id committerId, Account.Id realAccountId, Timestamp ts, String line) throws ConfigInvalidException {
    // See comments in parseAddApproval about the various users involved.
    Account.Id effectiveAccountId;
    String label;
    int s = line.indexOf(' ');
    if (s > 0) {
        label = line.substring(1, s);
        PersonIdent ident = RawParseUtils.parsePersonIdent(line.substring(s + 1));
        checkFooter(ident != null, FOOTER_LABEL, line);
        effectiveAccountId = noteUtil.parseIdent(ident, id);
    } else {
        label = line.substring(1);
        effectiveAccountId = committerId;
    }
    try {
        LabelType.checkNameInternal(label);
    } catch (IllegalArgumentException e) {
        ConfigInvalidException pe = parseException("invalid %s: %s", FOOTER_LABEL, line);
        pe.initCause(e);
        throw pe;
    }
    // Store an actual 0-vote approval in the map for a removed approval, for
    // several reasons:
    //  - This is closer to the ReviewDb representation, which leads to less
    //    confusion and special-casing of NoteDb.
    //  - More importantly, ApprovalCopier needs an actual approval in order to
    //    block copying an earlier approval over a later delete.
    PatchSetApproval remove = new PatchSetApproval(new PatchSetApproval.Key(psId, effectiveAccountId, new LabelId(label)), (short) 0, ts);
    if (!Objects.equals(realAccountId, committerId)) {
        remove.setRealAccountId(realAccountId);
    }
    ApprovalKey k = ApprovalKey.create(psId, effectiveAccountId, label);
    if (!approvals.containsKey(k)) {
        approvals.put(k, remove);
    }
    return remove;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) PersonIdent(org.eclipse.jgit.lib.PersonIdent) LabelId(com.google.gerrit.reviewdb.client.LabelId) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval)

Example 28 with PatchSetApproval

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

the class ChangeNotesParser method parseStatus.

private Change.Status parseStatus(ChangeNotesCommit commit) throws ConfigInvalidException {
    List<String> statusLines = commit.getFooterLineValues(FOOTER_STATUS);
    if (statusLines.isEmpty()) {
        return null;
    } else if (statusLines.size() > 1) {
        throw expectedOneFooter(FOOTER_STATUS, statusLines);
    }
    Change.Status status = Enums.getIfPresent(Change.Status.class, statusLines.get(0).toUpperCase()).orNull();
    if (status == null) {
        throw invalidFooter(FOOTER_STATUS, statusLines.get(0));
    }
    // up sorted after the submit during rebuilding.
    if (status == Change.Status.MERGED) {
        for (PatchSetApproval psa : bufferedApprovals) {
            if (!psa.isLegacySubmit()) {
                psa.setPostSubmit(true);
            }
        }
    }
    bufferedApprovals.clear();
    return status;
}
Also used : Change(com.google.gerrit.reviewdb.client.Change) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval)

Example 29 with PatchSetApproval

use of com.google.gerrit.reviewdb.client.PatchSetApproval 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 30 with PatchSetApproval

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

the class LabelNormalizerTest method copy.

private PatchSetApproval copy(PatchSetApproval src, int newValue) {
    PatchSetApproval result = new PatchSetApproval(src.getKey().getParentKey(), src);
    result.setValue((short) newValue);
    return result;
}
Also used : PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval)

Aggregations

PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)71 Change (com.google.gerrit.reviewdb.client.Change)37 Test (org.junit.Test)32 Account (com.google.gerrit.reviewdb.client.Account)17 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)17 LabelType (com.google.gerrit.common.data.LabelType)14 LabelId (com.google.gerrit.reviewdb.client.LabelId)13 ChangeMessage (com.google.gerrit.reviewdb.client.ChangeMessage)10 ChangeData (com.google.gerrit.server.query.change.ChangeData)10 ObjectId (org.eclipse.jgit.lib.ObjectId)10 RevId (com.google.gerrit.reviewdb.client.RevId)8 Timestamp (java.sql.Timestamp)8 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)7 HashMap (java.util.HashMap)7 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)6 LabelTypes (com.google.gerrit.common.data.LabelTypes)6 ArrayList (java.util.ArrayList)6 LinkedHashMap (java.util.LinkedHashMap)6 Map (java.util.Map)6 RequestId (com.google.gerrit.server.util.RequestId)5