BatchUpdate: Shorten ChangeContext method names
"Change" is implied by the type. Change-Id: If01d523c821126dc14f39055c63770dce52a45ae
This commit is contained in:
@@ -119,7 +119,7 @@ public class Abandon implements RestModifyView<ChangeResource, AbandonInput>,
|
||||
public void updateChange(ChangeContext ctx) throws OrmException,
|
||||
ResourceConflictException {
|
||||
change = ctx.getChange();
|
||||
ChangeUpdate update = ctx.getChangeUpdate();
|
||||
ChangeUpdate update = ctx.getUpdate();
|
||||
if (change == null || !change.getStatus().isOpen()) {
|
||||
throw new ResourceConflictException("change is " + status(change));
|
||||
} else if (change.getStatus() == Change.Status.DRAFT) {
|
||||
|
@@ -241,8 +241,8 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
||||
public void updateChange(ChangeContext ctx) throws OrmException, IOException {
|
||||
change = ctx.getChange(); // Use defensive copy created by ChangeControl.
|
||||
ReviewDb db = ctx.getDb();
|
||||
ChangeControl ctl = ctx.getChangeControl();
|
||||
ChangeUpdate update = ctx.getChangeUpdate();
|
||||
ChangeControl ctl = ctx.getControl();
|
||||
ChangeUpdate update = ctx.getUpdate();
|
||||
patchSetInfo = patchSetInfoFactory.get(
|
||||
ctx.getRevWalk(), commit, patchSet.getId());
|
||||
ctx.getChange().setCurrentPatchSet(patchSetInfo);
|
||||
@@ -268,7 +268,7 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
||||
approvalsUtil.addReviewers(db, update, labelTypes, change,
|
||||
patchSet, patchSetInfo, reviewers, Collections.<Account.Id> emptySet());
|
||||
approvalsUtil.addApprovals(db, update, labelTypes, patchSet,
|
||||
ctx.getChangeControl(), approvals);
|
||||
ctx.getControl(), approvals);
|
||||
if (message != null) {
|
||||
changeMessage =
|
||||
new ChangeMessage(new ChangeMessage.Key(change.getId(),
|
||||
|
@@ -121,7 +121,7 @@ public class CreateDraftComment implements RestModifyView<RevisionResource, Draf
|
||||
setCommentRevId(
|
||||
comment, patchListCache, ctx.getChange(), ps);
|
||||
plcUtil.insertComments(
|
||||
ctx.getDb(), ctx.getChangeUpdate(), Collections.singleton(comment));
|
||||
ctx.getDb(), ctx.getUpdate(), Collections.singleton(comment));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -74,7 +74,7 @@ class DeleteDraftChangeOp extends BatchUpdate.Op {
|
||||
if (!allowDrafts) {
|
||||
throw new MethodNotAllowedException("Draft workflow is disabled");
|
||||
}
|
||||
if (!ctx.getChangeControl().canDeleteDraft(ctx.getDb())) {
|
||||
if (!ctx.getControl().canDeleteDraft(ctx.getDb())) {
|
||||
throw new AuthException("Not permitted to delete this draft change");
|
||||
}
|
||||
List<PatchSet> patchSets = ctx.getDb().patchSets().byChange(id).toList();
|
||||
|
@@ -85,7 +85,7 @@ public class DeleteDraftComment
|
||||
public void updateChange(ChangeContext ctx)
|
||||
throws ResourceNotFoundException, OrmException {
|
||||
Optional<PatchLineComment> maybeComment =
|
||||
plcUtil.get(ctx.getDb(), ctx.getChangeNotes(), key);
|
||||
plcUtil.get(ctx.getDb(), ctx.getNotes(), key);
|
||||
if (!maybeComment.isPresent()) {
|
||||
return; // Nothing to do.
|
||||
}
|
||||
@@ -97,7 +97,7 @@ public class DeleteDraftComment
|
||||
PatchLineComment c = maybeComment.get();
|
||||
setCommentRevId(c, patchListCache, ctx.getChange(), ps);
|
||||
plcUtil.deleteComments(
|
||||
ctx.getDb(), ctx.getChangeUpdate(), Collections.singleton(c));
|
||||
ctx.getDb(), ctx.getUpdate(), Collections.singleton(c));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -108,7 +108,7 @@ public class DeleteDraftPatchSet implements RestModifyView<RevisionResource, Inp
|
||||
if (!allowDrafts) {
|
||||
throw new MethodNotAllowedException("Draft workflow is disabled");
|
||||
}
|
||||
if (!ctx.getChangeControl().canDeleteDraft(ctx.getDb())) {
|
||||
if (!ctx.getControl().canDeleteDraft(ctx.getDb())) {
|
||||
throw new AuthException("Not permitted to delete this draft patch set");
|
||||
}
|
||||
|
||||
|
@@ -95,7 +95,7 @@ public class DeleteVote implements RestModifyView<VoteResource, Input> {
|
||||
throws OrmException, AuthException, ResourceNotFoundException {
|
||||
IdentifiedUser user = ctx.getUser().asIdentifiedUser();
|
||||
Change change = ctx.getChange();
|
||||
ChangeControl ctl = ctx.getChangeControl();
|
||||
ChangeControl ctl = ctx.getControl();
|
||||
PatchSet.Id psId = change.currentPatchSetId();
|
||||
|
||||
PatchSetApproval psa = null;
|
||||
@@ -111,8 +111,8 @@ public class DeleteVote implements RestModifyView<VoteResource, Input> {
|
||||
.append("\n");
|
||||
psa = a;
|
||||
a.setValue((short)0);
|
||||
ctx.getChangeUpdate().setPatchSetId(psId);
|
||||
ctx.getChangeUpdate().removeApprovalFor(a.getAccountId(), label);
|
||||
ctx.getUpdate().setPatchSetId(psId);
|
||||
ctx.getUpdate().removeApprovalFor(a.getAccountId(), label);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@@ -133,7 +133,7 @@ public class DeleteVote implements RestModifyView<VoteResource, Input> {
|
||||
ctx.getWhen(),
|
||||
change.currentPatchSetId());
|
||||
changeMessage.setMessage(msg.toString());
|
||||
cmUtil.addChangeMessage(ctx.getDb(), ctx.getChangeUpdate(),
|
||||
cmUtil.addChangeMessage(ctx.getDb(), ctx.getUpdate(),
|
||||
changeMessage);
|
||||
}
|
||||
}
|
||||
|
@@ -206,10 +206,10 @@ public class PatchSetInserter extends BatchUpdate.Op {
|
||||
@Override
|
||||
public void updateChange(ChangeContext ctx) throws OrmException,
|
||||
InvalidChangeOperationException, IOException {
|
||||
ChangeControl ctl = ctx.getChangeControl();
|
||||
ChangeControl ctl = ctx.getControl();
|
||||
|
||||
change = ctx.getChange();
|
||||
ChangeUpdate update = ctx.getChangeUpdate();
|
||||
ChangeUpdate update = ctx.getUpdate();
|
||||
|
||||
if (!change.getStatus().isOpen() && !allowClosed) {
|
||||
throw new InvalidChangeOperationException(String.format(
|
||||
@@ -251,7 +251,7 @@ public class PatchSetInserter extends BatchUpdate.Op {
|
||||
db.changes().update(Collections.singleton(change));
|
||||
approvalCopier.copy(db, ctl, patchSet);
|
||||
if (changeMessage != null) {
|
||||
cmUtil.addChangeMessage(db, ctx.getChangeUpdate(), changeMessage);
|
||||
cmUtil.addChangeMessage(db, ctx.getUpdate(), changeMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -358,7 +358,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
||||
change.setLastUpdatedOn(ctx.getWhen());
|
||||
}
|
||||
ps = ctx.getDb().patchSets().get(psId);
|
||||
ctx.getChangeUpdate().setPatchSetId(psId);
|
||||
ctx.getUpdate().setPatchSetId(psId);
|
||||
boolean dirty = false;
|
||||
dirty |= insertComments(ctx);
|
||||
dirty |= updateLabels(ctx);
|
||||
@@ -466,8 +466,8 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
||||
}
|
||||
break;
|
||||
}
|
||||
plcUtil.deleteComments(ctx.getDb(), ctx.getChangeUpdate(), del);
|
||||
plcUtil.upsertComments(ctx.getDb(), ctx.getChangeUpdate(), ups);
|
||||
plcUtil.deleteComments(ctx.getDb(), ctx.getUpdate(), del);
|
||||
plcUtil.upsertComments(ctx.getDb(), ctx.getUpdate(), ups);
|
||||
comments.addAll(ups);
|
||||
return !del.isEmpty() || !ups.isEmpty();
|
||||
}
|
||||
@@ -476,7 +476,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
||||
throws OrmException {
|
||||
Set<CommentSetEntry> r = new HashSet<>();
|
||||
for (PatchLineComment c : plcUtil.publishedByChange(ctx.getDb(),
|
||||
ctx.getChangeNotes())) {
|
||||
ctx.getNotes())) {
|
||||
r.add(CommentSetEntry.create(c));
|
||||
}
|
||||
return r;
|
||||
@@ -486,7 +486,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
||||
throws OrmException {
|
||||
Map<String, PatchLineComment> drafts = Maps.newHashMap();
|
||||
for (PatchLineComment c : plcUtil.draftByChangeAuthor(
|
||||
ctx.getDb(), ctx.getChangeNotes(), user.getAccountId())) {
|
||||
ctx.getDb(), ctx.getNotes(), user.getAccountId())) {
|
||||
drafts.put(c.getKey().get(), c);
|
||||
}
|
||||
return drafts;
|
||||
@@ -496,7 +496,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
||||
throws OrmException {
|
||||
Map<String, PatchLineComment> drafts = Maps.newHashMap();
|
||||
for (PatchLineComment c : plcUtil.draftByPatchSetAuthor(ctx.getDb(),
|
||||
psId, user.getAccountId(), ctx.getChangeNotes())) {
|
||||
psId, user.getAccountId(), ctx.getNotes())) {
|
||||
drafts.put(c.getKey().get(), c);
|
||||
}
|
||||
return drafts;
|
||||
@@ -513,8 +513,8 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
||||
List<PatchSetApproval> ups = Lists.newArrayList();
|
||||
Map<String, PatchSetApproval> current = scanLabels(ctx, del);
|
||||
|
||||
ChangeUpdate update = ctx.getChangeUpdate();
|
||||
LabelTypes labelTypes = ctx.getChangeControl().getLabelTypes();
|
||||
ChangeUpdate update = ctx.getUpdate();
|
||||
LabelTypes labelTypes = ctx.getControl().getLabelTypes();
|
||||
for (Map.Entry<String, Short> ent : labels.entrySet()) {
|
||||
String name = ent.getKey();
|
||||
LabelType lt = checkNotNull(labelTypes.byLabel(name), name);
|
||||
@@ -576,7 +576,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
||||
PatchSetApproval c = new PatchSetApproval(new PatchSetApproval.Key(
|
||||
psId,
|
||||
user.getAccountId(),
|
||||
ctx.getChangeControl().getLabelTypes().getLabelTypes().get(0)
|
||||
ctx.getControl().getLabelTypes().getLabelTypes().get(0)
|
||||
.getLabelId()),
|
||||
(short) 0, TimeUtil.nowTs());
|
||||
c.setGranted(ctx.getWhen());
|
||||
@@ -595,11 +595,11 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
||||
|
||||
private Map<String, PatchSetApproval> scanLabels(ChangeContext ctx,
|
||||
List<PatchSetApproval> del) throws OrmException {
|
||||
LabelTypes labelTypes = ctx.getChangeControl().getLabelTypes();
|
||||
LabelTypes labelTypes = ctx.getControl().getLabelTypes();
|
||||
Map<String, PatchSetApproval> current = Maps.newHashMap();
|
||||
|
||||
for (PatchSetApproval a : approvalsUtil.byPatchSetUser(
|
||||
ctx.getDb(), ctx.getChangeControl(), psId, user.getAccountId())) {
|
||||
ctx.getDb(), ctx.getControl(), psId, user.getAccountId())) {
|
||||
if (a.isSubmit()) {
|
||||
continue;
|
||||
}
|
||||
@@ -644,7 +644,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
||||
"Patch Set %d:%s",
|
||||
psId.get(),
|
||||
buf.toString()));
|
||||
cmUtil.addChangeMessage(ctx.getDb(), ctx.getChangeUpdate(), message);
|
||||
cmUtil.addChangeMessage(ctx.getDb(), ctx.getUpdate(), message);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -166,7 +166,7 @@ public class PublishDraftPatchSet implements RestModifyView<RevisionResource, In
|
||||
@Override
|
||||
public void updateChange(ChangeContext ctx)
|
||||
throws RestApiException, OrmException, IOException {
|
||||
if (!ctx.getChangeControl().canPublish(ctx.getDb())) {
|
||||
if (!ctx.getControl().canPublish(ctx.getDb())) {
|
||||
throw new AuthException("Cannot publish this draft patch set");
|
||||
}
|
||||
if (patchSet == null) {
|
||||
@@ -182,7 +182,7 @@ public class PublishDraftPatchSet implements RestModifyView<RevisionResource, In
|
||||
|
||||
private void saveChange(ChangeContext ctx) throws OrmException {
|
||||
change = ctx.getChange();
|
||||
ChangeUpdate update = ctx.getChangeUpdate();
|
||||
ChangeUpdate update = ctx.getUpdate();
|
||||
wasDraftChange = change.getStatus() == Change.Status.DRAFT;
|
||||
if (wasDraftChange) {
|
||||
change.setStatus(Change.Status.NEW);
|
||||
@@ -208,9 +208,9 @@ public class PublishDraftPatchSet implements RestModifyView<RevisionResource, In
|
||||
|
||||
private void addReviewers(ChangeContext ctx)
|
||||
throws OrmException, IOException {
|
||||
LabelTypes labelTypes = ctx.getChangeControl().getLabelTypes();
|
||||
LabelTypes labelTypes = ctx.getControl().getLabelTypes();
|
||||
Collection<Account.Id> oldReviewers = approvalsUtil.getReviewers(
|
||||
ctx.getDb(), ctx.getChangeNotes()).values();
|
||||
ctx.getDb(), ctx.getNotes()).values();
|
||||
RevCommit commit = ctx.getRevWalk().parseCommit(
|
||||
ObjectId.fromString(patchSet.getRevision().get()));
|
||||
patchSetInfo = patchSetInfoFactory.get(ctx.getRevWalk(), commit, psId);
|
||||
@@ -219,7 +219,7 @@ public class PublishDraftPatchSet implements RestModifyView<RevisionResource, In
|
||||
recipients =
|
||||
getRecipientsFromFooters(accountResolver, patchSet, footerLines);
|
||||
recipients.remove(ctx.getUser().getAccountId());
|
||||
approvalsUtil.addReviewers(ctx.getDb(), ctx.getChangeUpdate(), labelTypes,
|
||||
approvalsUtil.addReviewers(ctx.getDb(), ctx.getUpdate(), labelTypes,
|
||||
change, patchSet, patchSetInfo, recipients.getReviewers(),
|
||||
oldReviewers);
|
||||
}
|
||||
|
@@ -107,7 +107,7 @@ public class PutDraftComment implements RestModifyView<DraftCommentResource, Dra
|
||||
public void updateChange(ChangeContext ctx)
|
||||
throws ResourceNotFoundException, OrmException {
|
||||
Optional<PatchLineComment> maybeComment =
|
||||
plcUtil.get(ctx.getDb(), ctx.getChangeNotes(), key);
|
||||
plcUtil.get(ctx.getDb(), ctx.getNotes(), key);
|
||||
if (!maybeComment.isPresent()) {
|
||||
// Disappeared out from under us. Can't easily fall back to insert,
|
||||
// because the input might be missing required fields. Just give up.
|
||||
@@ -126,7 +126,7 @@ public class PutDraftComment implements RestModifyView<DraftCommentResource, Dra
|
||||
// Delete then recreate the comment instead of an update.
|
||||
|
||||
plcUtil.deleteComments(
|
||||
ctx.getDb(), ctx.getChangeUpdate(), Collections.singleton(comment));
|
||||
ctx.getDb(), ctx.getUpdate(), Collections.singleton(comment));
|
||||
comment = new PatchLineComment(
|
||||
new PatchLineComment.Key(
|
||||
new Patch.Key(psId, in.path),
|
||||
@@ -135,14 +135,14 @@ public class PutDraftComment implements RestModifyView<DraftCommentResource, Dra
|
||||
ctx.getUser().getAccountId(),
|
||||
comment.getParentUuid(), ctx.getWhen());
|
||||
setCommentRevId(comment, patchListCache, ctx.getChange(), ps);
|
||||
plcUtil.insertComments(ctx.getDb(), ctx.getChangeUpdate(),
|
||||
plcUtil.insertComments(ctx.getDb(), ctx.getUpdate(),
|
||||
Collections.singleton(update(comment, in)));
|
||||
} else {
|
||||
if (comment.getRevId() == null) {
|
||||
setCommentRevId(
|
||||
comment, patchListCache, ctx.getChange(), ps);
|
||||
}
|
||||
plcUtil.updateComments(ctx.getDb(), ctx.getChangeUpdate(),
|
||||
plcUtil.updateComments(ctx.getDb(), ctx.getUpdate(),
|
||||
Collections.singleton(update(comment, in)));
|
||||
}
|
||||
}
|
||||
|
@@ -116,7 +116,7 @@ public class PutTopic implements RestModifyView<ChangeResource, Input>,
|
||||
oldTopicName, newTopicName);
|
||||
}
|
||||
change.setTopic(Strings.emptyToNull(newTopicName));
|
||||
ctx.getChangeUpdate().setTopic(change.getTopic());
|
||||
ctx.getUpdate().setTopic(change.getTopic());
|
||||
ChangeUtil.updated(change);
|
||||
ctx.getDb().changes().update(Collections.singleton(change));
|
||||
|
||||
@@ -127,7 +127,7 @@ public class PutTopic implements RestModifyView<ChangeResource, Input>,
|
||||
caller.getAccountId(), ctx.getWhen(),
|
||||
change.currentPatchSetId());
|
||||
cmsg.setMessage(summary);
|
||||
cmUtil.addChangeMessage(ctx.getDb(), ctx.getChangeUpdate(), cmsg);
|
||||
cmUtil.addChangeMessage(ctx.getDb(), ctx.getUpdate(), cmsg);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -110,7 +110,7 @@ public class Restore implements RestModifyView<ChangeResource, RestoreInput>,
|
||||
ResourceConflictException {
|
||||
caller = ctx.getUser().asIdentifiedUser();
|
||||
change = ctx.getChange();
|
||||
ChangeUpdate update = ctx.getChangeUpdate();
|
||||
ChangeUpdate update = ctx.getUpdate();
|
||||
if (change == null || change.getStatus() != Status.ABANDONED) {
|
||||
throw new ResourceConflictException("change is " + status(change));
|
||||
}
|
||||
|
@@ -80,10 +80,10 @@ public class SetHashtagsOp extends BatchUpdate.Op {
|
||||
updatedHashtags = ImmutableSortedSet.of();
|
||||
return;
|
||||
}
|
||||
if (!ctx.getChangeControl().canEditHashtags()) {
|
||||
if (!ctx.getControl().canEditHashtags()) {
|
||||
throw new AuthException("Editing hashtags not permitted");
|
||||
}
|
||||
ChangeUpdate update = ctx.getChangeUpdate();
|
||||
ChangeUpdate update = ctx.getUpdate();
|
||||
ChangeNotes notes = update.getChangeNotes().load();
|
||||
|
||||
Set<String> existingHashtags = notes.getHashtags();
|
||||
|
@@ -167,15 +167,15 @@ public class BatchUpdate implements AutoCloseable {
|
||||
this.update = changeUpdateFactory.create(ctl, when);
|
||||
}
|
||||
|
||||
public ChangeUpdate getChangeUpdate() {
|
||||
public ChangeUpdate getUpdate() {
|
||||
return update;
|
||||
}
|
||||
|
||||
public ChangeNotes getChangeNotes() {
|
||||
public ChangeNotes getNotes() {
|
||||
return update.getChangeNotes();
|
||||
}
|
||||
|
||||
public ChangeControl getChangeControl() {
|
||||
public ChangeControl getControl() {
|
||||
return ctl;
|
||||
}
|
||||
|
||||
@@ -523,7 +523,7 @@ public class BatchUpdate implements AutoCloseable {
|
||||
} finally {
|
||||
db.rollback();
|
||||
}
|
||||
ctx.getChangeUpdate().commit();
|
||||
ctx.getUpdate().commit();
|
||||
if (ctx.deleted) {
|
||||
indexFutures.add(indexer.deleteAsync(id));
|
||||
} else {
|
||||
|
@@ -1807,7 +1807,7 @@ public class ReceiveCommits {
|
||||
new BatchUpdate.Op() {
|
||||
@Override
|
||||
public void updateChange(ChangeContext ctx) throws Exception {
|
||||
ctx.getChangeUpdate().setTopic(magicBranch.topic);
|
||||
ctx.getUpdate().setTopic(magicBranch.topic);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@@ -167,7 +167,7 @@ public class CherryPick extends SubmitStrategy {
|
||||
// Merge conflict; don't update change.
|
||||
return;
|
||||
}
|
||||
ctx.getChangeUpdate().setPatchSetId(psId);
|
||||
ctx.getUpdate().setPatchSetId(psId);
|
||||
PatchSet ps = new PatchSet(psId);
|
||||
ps.setCreatedOn(ctx.getWhen());
|
||||
ps.setUploader(args.caller.getAccountId());
|
||||
@@ -183,7 +183,7 @@ public class CherryPick extends SubmitStrategy {
|
||||
for (PatchSetApproval a : args.approvalsUtil.byPatchSet(
|
||||
args.db, toMerge.getControl(), toMerge.getPatchsetId())) {
|
||||
approvals.add(new PatchSetApproval(ps.getId(), a));
|
||||
ctx.getChangeUpdate().putApproval(a.getLabel(), a.getValue());
|
||||
ctx.getUpdate().putApproval(a.getLabel(), a.getValue());
|
||||
}
|
||||
args.db.patchSetApprovals().insert(approvals);
|
||||
|
||||
|
Reference in New Issue
Block a user