PatchSetInserter: Use ChangeNotes instead of ChangeControl
Change-Id: I2a5b1cd023c14e74f586dc52e86e3aee3dd17302
This commit is contained in:
@@ -834,7 +834,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
|
||||
try (BatchUpdate bu = newUpdate(ctl.getChange().getOwner())) {
|
||||
ins =
|
||||
patchSetInserterFactory
|
||||
.create(ctl, nextPatchSetId(ctl), commit)
|
||||
.create(ctl.getNotes(), nextPatchSetId(ctl), commit)
|
||||
.setValidate(false)
|
||||
.setFireRevisionCreated(false)
|
||||
.setNotify(NotifyHandling.NONE);
|
||||
|
||||
@@ -48,7 +48,6 @@ import com.google.gerrit.server.git.MergeIdenticalTreeException;
|
||||
import com.google.gerrit.server.git.MergeUtil;
|
||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||
import com.google.gerrit.server.notedb.ReviewerStateInternal;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.InvalidChangeOperationException;
|
||||
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||
import com.google.gerrit.server.project.ProjectControl;
|
||||
@@ -246,8 +245,7 @@ public class CherryPickChange {
|
||||
if (destChanges.size() == 1) {
|
||||
// The change key exists on the destination branch. The cherry pick
|
||||
// will be added as a new patch set.
|
||||
ChangeControl destCtl = projectControl.controlFor(destChanges.get(0).notes());
|
||||
result = insertPatchSet(bu, git, destCtl, cherryPickCommit, input);
|
||||
result = insertPatchSet(bu, git, destChanges.get(0).notes(), cherryPickCommit, input);
|
||||
} else {
|
||||
// Change key not found on destination branch. We can create a new
|
||||
// change.
|
||||
@@ -321,15 +319,15 @@ public class CherryPickChange {
|
||||
private Change.Id insertPatchSet(
|
||||
BatchUpdate bu,
|
||||
Repository git,
|
||||
ChangeControl destCtl,
|
||||
ChangeNotes destNotes,
|
||||
CodeReviewCommit cherryPickCommit,
|
||||
CherryPickInput input)
|
||||
throws IOException, OrmException, BadRequestException, ConfigInvalidException {
|
||||
Change destChange = destCtl.getChange();
|
||||
Change destChange = destNotes.getChange();
|
||||
PatchSet.Id psId = ChangeUtil.nextPatchSetId(git, destChange.currentPatchSetId());
|
||||
PatchSet current = psUtil.current(dbProvider.get(), destCtl.getNotes());
|
||||
PatchSet current = psUtil.current(dbProvider.get(), destNotes);
|
||||
|
||||
PatchSetInserter inserter = patchSetInserterFactory.create(destCtl, psId, cherryPickCommit);
|
||||
PatchSetInserter inserter = patchSetInserterFactory.create(destNotes, psId, cherryPickCommit);
|
||||
inserter
|
||||
.setMessage("Uploaded patch set " + inserter.getPatchSetId().get() + ".")
|
||||
.setDraft(current.isDraft())
|
||||
|
||||
@@ -515,7 +515,7 @@ public class ConsistencyChecker {
|
||||
(psIdToDelete != null && reuseOldPsId)
|
||||
? psIdToDelete
|
||||
: ChangeUtil.nextPatchSetId(repo, change().currentPatchSetId());
|
||||
PatchSetInserter inserter = patchSetInserterFactory.create(ctl, psId, commit);
|
||||
PatchSetInserter inserter = patchSetInserterFactory.create(ctl.getNotes(), psId, commit);
|
||||
try (BatchUpdate bu = newBatchUpdate()) {
|
||||
bu.setRepository(repo, rw, oi);
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ public class CreateMergePatchSet
|
||||
|
||||
PatchSet.Id nextPsId = ChangeUtil.nextPatchSetId(ps.getId());
|
||||
PatchSetInserter psInserter =
|
||||
patchSetInserterFactory.create(rsrc.getControl(), nextPsId, newCommit);
|
||||
patchSetInserterFactory.create(rsrc.getNotes(), nextPsId, newCommit);
|
||||
try (BatchUpdate bu = updateFactory.create(db.get(), project, me, now)) {
|
||||
bu.setRepository(git, rw, oi);
|
||||
bu.addOp(
|
||||
|
||||
@@ -27,7 +27,6 @@ import com.google.gerrit.extensions.api.changes.RecipientType;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
@@ -44,12 +43,14 @@ import com.google.gerrit.server.extensions.events.RevisionCreated;
|
||||
import com.google.gerrit.server.git.validators.CommitValidationException;
|
||||
import com.google.gerrit.server.git.validators.CommitValidators;
|
||||
import com.google.gerrit.server.mail.send.ReplacePatchSetSender;
|
||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||
import com.google.gerrit.server.notedb.ChangeUpdate;
|
||||
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.ssh.NoSshInfo;
|
||||
import com.google.gerrit.server.update.BatchUpdateOp;
|
||||
import com.google.gerrit.server.update.ChangeContext;
|
||||
@@ -70,7 +71,7 @@ public class PatchSetInserter implements BatchUpdateOp {
|
||||
private static final Logger log = LoggerFactory.getLogger(PatchSetInserter.class);
|
||||
|
||||
public interface Factory {
|
||||
PatchSetInserter create(ChangeControl ctl, PatchSet.Id psId, ObjectId commitId);
|
||||
PatchSetInserter create(ChangeNotes notes, PatchSet.Id psId, ObjectId commitId);
|
||||
}
|
||||
|
||||
// Injected fields.
|
||||
@@ -78,6 +79,7 @@ public class PatchSetInserter implements BatchUpdateOp {
|
||||
private final PatchSetInfoFactory patchSetInfoFactory;
|
||||
private final CommitValidators.Factory commitValidatorsFactory;
|
||||
private final ReplacePatchSetSender.Factory replacePatchSetFactory;
|
||||
private final ProjectCache projectCache;
|
||||
private final RevisionCreated revisionCreated;
|
||||
private final ApprovalsUtil approvalsUtil;
|
||||
private final ApprovalCopier approvalCopier;
|
||||
@@ -88,9 +90,9 @@ public class PatchSetInserter implements BatchUpdateOp {
|
||||
private final PatchSet.Id psId;
|
||||
private final ObjectId commitId;
|
||||
// Read prior to running the batch update, so must only be used during
|
||||
// updateRepo; updateChange and later must use the control from the
|
||||
// updateRepo; updateChange and later must use the notes from the
|
||||
// ChangeContext.
|
||||
private final ChangeControl origCtl;
|
||||
private final ChangeNotes origNotes;
|
||||
|
||||
// Fields exposed as setters.
|
||||
private String message;
|
||||
@@ -123,7 +125,8 @@ public class PatchSetInserter implements BatchUpdateOp {
|
||||
ReplacePatchSetSender.Factory replacePatchSetFactory,
|
||||
PatchSetUtil psUtil,
|
||||
RevisionCreated revisionCreated,
|
||||
@Assisted ChangeControl ctl,
|
||||
ProjectCache projectCache,
|
||||
@Assisted ChangeNotes notes,
|
||||
@Assisted PatchSet.Id psId,
|
||||
@Assisted ObjectId commitId) {
|
||||
this.permissionBackend = permissionBackend;
|
||||
@@ -135,8 +138,9 @@ public class PatchSetInserter implements BatchUpdateOp {
|
||||
this.replacePatchSetFactory = replacePatchSetFactory;
|
||||
this.psUtil = psUtil;
|
||||
this.revisionCreated = revisionCreated;
|
||||
this.projectCache = projectCache;
|
||||
|
||||
this.origCtl = ctl;
|
||||
this.origNotes = notes;
|
||||
this.psId = psId;
|
||||
this.commitId = commitId.copy();
|
||||
}
|
||||
@@ -316,7 +320,7 @@ public class PatchSetInserter implements BatchUpdateOp {
|
||||
permissionBackend
|
||||
.user(ctx.getUser())
|
||||
.database(ctx.getDb())
|
||||
.change(origCtl.getNotes())
|
||||
.change(origNotes)
|
||||
.check(ChangePermission.ADD_PATCH_SET);
|
||||
}
|
||||
if (!validate) {
|
||||
@@ -324,7 +328,7 @@ public class PatchSetInserter implements BatchUpdateOp {
|
||||
}
|
||||
|
||||
PermissionBackend.ForRef perm =
|
||||
permissionBackend.user(ctx.getUser()).ref(origCtl.getChange().getDest());
|
||||
permissionBackend.user(ctx.getUser()).ref(origNotes.getChange().getDest());
|
||||
|
||||
String refName = getPatchSetId().toRefName();
|
||||
try (CommitReceivedEvent event =
|
||||
@@ -333,16 +337,15 @@ public class PatchSetInserter implements BatchUpdateOp {
|
||||
ObjectId.zeroId(),
|
||||
commitId,
|
||||
refName.substring(0, refName.lastIndexOf('/') + 1) + "new"),
|
||||
origCtl.getProjectControl().getProject(),
|
||||
origCtl.getRefControl().getRefName(),
|
||||
projectCache.checkedGet(origNotes.getProjectName()).getProject(),
|
||||
origNotes.getChange().getDest().get(),
|
||||
ctx.getRevWalk().getObjectReader(),
|
||||
commitId,
|
||||
ctx.getIdentifiedUser())) {
|
||||
commitValidatorsFactory
|
||||
.forGerritCommits(
|
||||
perm,
|
||||
new Branch.NameKey(
|
||||
origCtl.getProject().getNameKey(), origCtl.getRefControl().getRefName()),
|
||||
origNotes.getChange().getDest(),
|
||||
ctx.getIdentifiedUser(),
|
||||
new NoSshInfo(),
|
||||
ctx.getRevWalk())
|
||||
|
||||
@@ -141,8 +141,7 @@ public class PutMessage
|
||||
PatchSet.Id psId = ChangeUtil.nextPatchSetId(repository, ps.getId());
|
||||
ObjectId newCommit =
|
||||
createCommit(objectInserter, patchSetCommit, sanitizedCommitMessage, ts);
|
||||
PatchSetInserter inserter =
|
||||
psInserterFactory.create(resource.getControl(), psId, newCommit);
|
||||
PatchSetInserter inserter = psInserterFactory.create(resource.getNotes(), psId, newCommit);
|
||||
inserter.setMessage(
|
||||
String.format("Patch Set %s: Commit message was updated.", psId.getId()));
|
||||
inserter.setDescription("Edit commit message");
|
||||
|
||||
@@ -172,7 +172,7 @@ public class RebaseChangeOp implements BatchUpdateOp {
|
||||
ctl.getChange().currentPatchSetId());
|
||||
patchSetInserter =
|
||||
patchSetInserterFactory
|
||||
.create(ctl, rebasedPatchSetId, rebasedCommit)
|
||||
.create(ctl.getNotes(), rebasedPatchSetId, rebasedCommit)
|
||||
.setDescription("Rebase")
|
||||
.setDraft(originalPatchSet.isDraft())
|
||||
.setNotify(NotifyHandling.NONE)
|
||||
|
||||
@@ -180,7 +180,7 @@ public class ChangeEditUtil {
|
||||
PatchSet.Id psId = ChangeUtil.nextPatchSetId(repo, change.currentPatchSetId());
|
||||
PatchSetInserter inserter =
|
||||
patchSetInserterFactory
|
||||
.create(ctl, psId, squashed)
|
||||
.create(ctl.getNotes(), psId, squashed)
|
||||
.setNotify(notify)
|
||||
.setAccountsToNotify(accountsToNotify);
|
||||
|
||||
|
||||
@@ -391,7 +391,7 @@ public class CommitValidators {
|
||||
+ " tried to push an invalid project configuration "
|
||||
+ receiveEvent.command.getNewId().name()
|
||||
+ " for project "
|
||||
+ receiveEvent.project.getName(),
|
||||
+ receiveEvent.project,
|
||||
e);
|
||||
throw new CommitValidationException("invalid project configuration", messages);
|
||||
}
|
||||
|
||||
@@ -2330,7 +2330,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
||||
|
||||
PatchSetInserter inserter =
|
||||
patchSetFactory
|
||||
.create(ctl, new PatchSet.Id(c.getId(), n), commit)
|
||||
.create(ctl.getNotes(), new PatchSet.Id(c.getId(), n), commit)
|
||||
.setNotify(NotifyHandling.NONE)
|
||||
.setFireRevisionCreated(false)
|
||||
.setValidate(false);
|
||||
|
||||
Reference in New Issue
Block a user