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);
}
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations