Remove getChangeControl() from ChangeContext

Change-Id: I07da7337d35bf6e05766fcbf1e328c260255381c
This commit is contained in:
Patrick Hiesel
2017-09-14 08:52:18 +02:00
parent 1fd4b638c8
commit 01415a349d
7 changed files with 28 additions and 38 deletions

View File

@@ -56,8 +56,8 @@ import com.google.gerrit.server.patch.PatchSetInfoFactory;
import com.google.gerrit.server.permissions.ChangePermission;
import com.google.gerrit.server.permissions.PermissionBackend;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectState;
import com.google.gerrit.server.ssh.NoSshInfo;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.Context;
@@ -137,6 +137,7 @@ public class ChangeInserter implements InsertChangeOp {
private PatchSetInfo patchSetInfo;
private PatchSet patchSet;
private String pushCert;
private ProjectState projectState;
@Inject
ChangeInserter(
@@ -369,6 +370,7 @@ public class ChangeInserter implements InsertChangeOp {
@Override
public void updateRepo(RepoContext ctx) throws ResourceConflictException, IOException {
cmd = new ReceiveCommand(ObjectId.zeroId(), commitId, psId.toRefName());
projectState = projectCache.checkedGet(ctx.getProject());
validate(ctx);
if (!updateRef) {
return;
@@ -381,7 +383,6 @@ public class ChangeInserter implements InsertChangeOp {
throws RestApiException, OrmException, IOException, PermissionBackendException {
change = ctx.getChange(); // Use defensive copy created by ChangeControl.
ReviewDb db = ctx.getDb();
ChangeControl ctl = ctx.getControl();
patchSetInfo =
patchSetInfoFactory.get(ctx.getRevWalk(), ctx.getRevWalk().parseCommit(commitId), psId);
ctx.getChange().setCurrentPatchSet(patchSetInfo);
@@ -433,7 +434,7 @@ public class ChangeInserter implements InsertChangeOp {
reviewersToAdd.addAll(extraCC);
}
LabelTypes labelTypes = ctl.getProjectControl().getProjectState().getLabelTypes();
LabelTypes labelTypes = projectState.getLabelTypes();
approvalsUtil.addReviewers(
db,
update,
@@ -534,10 +535,7 @@ public class ChangeInserter implements InsertChangeOp {
revisionCreated.fire(change, patchSet, ctx.getAccount(), ctx.getWhen(), notify);
if (approvals != null && !approvals.isEmpty()) {
List<LabelType> labels =
projectCache
.checkedGet(ctx.getProject())
.getLabelTypes(change.getDest(), ctx.getUser())
.getLabelTypes();
projectState.getLabelTypes(change.getDest(), ctx.getUser()).getLabelTypes();
Map<String, Short> allApprovals = new HashMap<>();
Map<String, Short> oldApprovals = new HashMap<>();
for (LabelType lt : labels) {
@@ -567,7 +565,7 @@ public class ChangeInserter implements InsertChangeOp {
try (CommitReceivedEvent event =
new CommitReceivedEvent(
cmd,
projectCache.checkedGet(ctx.getProject()).getProject(),
projectState.getProject(),
change.getDest().get(),
ctx.getRevWalk().getObjectReader(),
commitId,

View File

@@ -139,7 +139,9 @@ public class DeleteDraftPatchSet
if (!allowDrafts) {
throw new MethodNotAllowedException("Draft workflow is disabled");
}
if (!ctx.getControl().canDeleteDraft(ctx.getDb())) {
if (!changeControlFactory
.controlFor(ctx.getNotes(), ctx.getUser())
.canDeleteDraft(ctx.getDb())) {
throw new AuthException("Not permitted to delete this draft patch set");
}

View File

@@ -193,7 +193,7 @@ public class PublishDraftPatchSet
@Override
public boolean updateChange(ChangeContext ctx)
throws RestApiException, OrmException, IOException {
if (!ctx.getControl().canPublish(ctx.getDb())) {
if (!changeControlFactory.controlFor(ctx.getNotes(), ctx.getUser()).canPublish(ctx.getDb())) {
throw new AuthException("Cannot publish this draft patch set");
}
if (patchSet == null) {

View File

@@ -42,8 +42,8 @@ import com.google.gerrit.server.change.EmailReviewComments;
import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.extensions.events.CommentAdded;
import com.google.gerrit.server.mail.MailFilter;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.patch.PatchListCache;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.query.change.InternalChangeQuery;
import com.google.gerrit.server.update.BatchUpdate;
@@ -231,7 +231,7 @@ public class MailProcessor {
private ChangeMessage changeMessage;
private List<Comment> comments;
private PatchSet patchSet;
private ChangeControl changeControl;
private ChangeNotes notes;
private Op(PatchSet.Id psId, List<MailComment> parsedComments, String messageId) {
this.psId = psId;
@@ -242,8 +242,8 @@ public class MailProcessor {
@Override
public boolean updateChange(ChangeContext ctx)
throws OrmException, UnprocessableEntityException {
changeControl = ctx.getControl();
patchSet = psUtil.get(ctx.getDb(), ctx.getNotes(), psId);
notes = ctx.getNotes();
if (patchSet == null) {
throw new OrmException("patch set not found: " + psId);
}
@@ -279,7 +279,7 @@ public class MailProcessor {
.create(
NotifyHandling.ALL,
ArrayListMultimap.create(),
changeControl.getNotes(),
notes,
patchSet,
ctx.getUser().asIdentifiedUser(),
changeMessage,
@@ -292,8 +292,8 @@ public class MailProcessor {
approvalsUtil
.byPatchSetUser(
ctx.getDb(),
changeControl.getNotes(),
changeControl.getUser(),
notes,
ctx.getUser(),
psId,
ctx.getAccountId(),
ctx.getRevWalk(),
@@ -302,7 +302,7 @@ public class MailProcessor {
// Fire Gerrit event. Note that approvals can't be granted via email, so old and new approvals
// are always the same here.
commentAdded.fire(
changeControl.getChange(),
notes.getChange(),
patchSet,
ctx.getAccount(),
changeMessage.getMessage(),

View File

@@ -20,7 +20,6 @@ import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.project.ChangeControl;
/**
* Context for performing the {@link BatchUpdateOp#updateChange} phase.
@@ -44,14 +43,14 @@ public interface ChangeContext extends Context {
ChangeUpdate getUpdate(PatchSet.Id psId);
/**
* Get the control for this change, encapsulating the user and up-to-date change data.
* Get the up-to-date notes for this change.
*
* <p>The user will be the same as {@link #getUser()}, and the change data is read within the same
* transaction that {@link BatchUpdateOp#updateChange(ChangeContext)} is executing.
* <p>The change data is read within the same transaction that {@link
* BatchUpdateOp#updateChange(ChangeContext)} is executing.
*
* @return control for this change.
* @return notes for this change.
*/
ChangeControl getControl();
ChangeNotes getNotes();
/**
* Don't bump the value of {@link Change#getLastUpdatedOn()}.
@@ -70,17 +69,8 @@ public interface ChangeContext extends Context {
*/
void deleteChange();
/**
* Get notes corresponding to {@link #getControl()}.
*
* @return loaded notes instance.
*/
default ChangeNotes getNotes() {
return checkNotNull(getControl().getNotes());
}
/** @return change corresponding to {@link #getControl()}. */
/** @return change corresponding to {@link #getNotes()}. */
default Change getChange() {
return checkNotNull(getControl().getChange());
return checkNotNull(getNotes().getChange());
}
}

View File

@@ -240,8 +240,8 @@ class NoteDbBatchUpdate extends BatchUpdate {
}
@Override
public ChangeControl getControl() {
return ctl;
public ChangeNotes getNotes() {
return ctl.getNotes();
}
@Override

View File

@@ -209,9 +209,9 @@ class ReviewDbBatchUpdate extends BatchUpdate {
}
@Override
public ChangeControl getControl() {
public ChangeNotes getNotes() {
checkNotNull(ctl);
return ctl;
return ctl.getNotes();
}
@Override