Merge "PatchSetInserter: Take ChangeControl instead of RefControl"

This commit is contained in:
Edwin Kempin
2016-06-22 08:36:19 +00:00
committed by Gerrit Code Review
7 changed files with 35 additions and 48 deletions

View File

@@ -194,7 +194,7 @@ public class CherryPickChange {
ChangeControl destCtl = refControl.getProjectControl()
.controlFor(destChanges.get(0).notes());
result = insertPatchSet(
bu, git, destCtl, cherryPickCommit, refControl);
bu, git, destCtl, cherryPickCommit);
} else {
// Change key not found on destination branch. We can create a new
// change.
@@ -223,21 +223,21 @@ public class CherryPickChange {
}
private Change.Id insertPatchSet(BatchUpdate bu, Repository git,
ChangeControl ctl, CodeReviewCommit cherryPickCommit,
RefControl refControl) throws IOException, OrmException {
Change change = ctl.getChange();
ChangeControl destCtl, CodeReviewCommit cherryPickCommit)
throws IOException, OrmException {
Change destChange = destCtl.getChange();
PatchSet.Id psId =
ChangeUtil.nextPatchSetId(git, change.currentPatchSetId());
ChangeUtil.nextPatchSetId(git, destChange.currentPatchSetId());
PatchSetInserter inserter = patchSetInserterFactory
.create(refControl, psId, cherryPickCommit);
.create(destCtl, psId, cherryPickCommit);
PatchSet.Id newPatchSetId = inserter.getPatchSetId();
PatchSet current = psUtil.current(db.get(), ctl.getNotes());
PatchSet current = psUtil.current(db.get(), destCtl.getNotes());
bu.addOp(change.getId(), inserter
bu.addOp(destChange.getId(), inserter
.setMessage("Uploaded patch set " + newPatchSetId.get() + ".")
.setDraft(current.isDraft())
.setSendMail(false));
return change.getId();
return destChange.getId();
}
private Change.Id createNewChange(BatchUpdate bu,

View File

@@ -54,9 +54,6 @@ import com.google.gerrit.server.patch.PatchSetInfoFactory;
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.project.ProjectControl;
import com.google.gerrit.server.project.RefControl;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gwtorm.server.AtomicUpdate;
import com.google.gwtorm.server.OrmException;
@@ -118,7 +115,6 @@ public class ConsistencyChecker {
private final NotesMigration notesMigration;
private final Provider<CurrentUser> user;
private final Provider<PersonIdent> serverIdent;
private final ProjectControl.GenericFactory projectControlFactory;
private final PatchSetInfoFactory patchSetInfoFactory;
private final PatchSetInserter.Factory patchSetInserterFactory;
private final BatchUpdate.Factory updateFactory;
@@ -146,7 +142,6 @@ public class ConsistencyChecker {
NotesMigration notesMigration,
Provider<CurrentUser> user,
@GerritPersonIdent Provider<PersonIdent> serverIdent,
ProjectControl.GenericFactory projectControlFactory,
PatchSetInfoFactory patchSetInfoFactory,
PatchSetInserter.Factory patchSetInserterFactory,
BatchUpdate.Factory updateFactory,
@@ -160,7 +155,6 @@ public class ConsistencyChecker {
this.repoManager = repoManager;
this.user = user;
this.serverIdent = serverIdent;
this.projectControlFactory = projectControlFactory;
this.patchSetInfoFactory = patchSetInfoFactory;
this.patchSetInserterFactory = patchSetInserterFactory;
this.updateFactory = updateFactory;
@@ -496,9 +490,8 @@ public class ConsistencyChecker {
}
try {
RefControl ctl = projectControlFactory
.controlFor(change.getProject(), user.get())
.controlForRef(change.getDest());
ChangeControl ctl = changeControlFactory
.controlFor(db.get(), change, user.get());
PatchSet.Id psId =
ChangeUtil.nextPatchSetId(repo, change.currentPatchSetId());
PatchSetInserter inserter =
@@ -520,8 +513,8 @@ public class ConsistencyChecker {
p.status = Status.FIXED;
p.outcome = "Inserted as patch set " + psId.get();
return psId;
} catch (IOException | NoSuchProjectException | UpdateException
| RestApiException e) {
} catch (OrmException | IOException | NoSuchChangeException
| UpdateException | RestApiException e) {
warn(e);
p.status = Status.FIX_FAILED;
p.outcome = "Error inserting new patch set";

View File

@@ -44,7 +44,6 @@ import com.google.gerrit.server.mail.ReplacePatchSetSender;
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.patch.PatchSetInfoFactory;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.RefControl;
import com.google.gerrit.server.ssh.NoSshInfo;
import com.google.gerrit.server.ssh.SshInfo;
import com.google.gwtorm.server.OrmException;
@@ -67,7 +66,7 @@ public class PatchSetInserter extends BatchUpdate.Op {
LoggerFactory.getLogger(PatchSetInserter.class);
public interface Factory {
PatchSetInserter create(RefControl refControl, PatchSet.Id psId,
PatchSetInserter create(ChangeControl ctl, PatchSet.Id psId,
RevCommit commit);
}
@@ -85,7 +84,10 @@ public class PatchSetInserter extends BatchUpdate.Op {
// Assisted-injected fields.
private final PatchSet.Id psId;
private final RevCommit commit;
private final RefControl refControl;
// Read prior to running the batch update, so must only be used during
// updateRepo; updateChange and later must use the control from the
// ChangeContext.
private final ChangeControl origCtl;
// Fields exposed as setters.
private SshInfo sshInfo;
@@ -116,7 +118,7 @@ public class PatchSetInserter extends BatchUpdate.Op {
CommitValidators.Factory commitValidatorsFactory,
ReplacePatchSetSender.Factory replacePatchSetFactory,
PatchSetUtil psUtil,
@Assisted RefControl refControl,
@Assisted ChangeControl ctl,
@Assisted PatchSet.Id psId,
@Assisted RevCommit commit) {
this.hooks = hooks;
@@ -129,7 +131,7 @@ public class PatchSetInserter extends BatchUpdate.Op {
this.replacePatchSetFactory = replacePatchSetFactory;
this.psUtil = psUtil;
this.refControl = refControl;
this.origCtl = ctl;
this.psId = psId;
this.commit = commit;
}
@@ -285,7 +287,7 @@ public class PatchSetInserter extends BatchUpdate.Op {
private void validate(RepoContext ctx)
throws ResourceConflictException, IOException {
CommitValidators cv = commitValidatorsFactory.create(
refControl, sshInfo, ctx.getRepository());
origCtl.getRefControl(), sshInfo, ctx.getRepository());
String refName = getPatchSetId().toRefName();
CommitReceivedEvent event = new CommitReceivedEvent(
@@ -293,7 +295,8 @@ public class PatchSetInserter extends BatchUpdate.Op {
ObjectId.zeroId(),
commit.getId(),
refName.substring(0, refName.lastIndexOf('/') + 1) + "new"),
refControl.getProjectControl().getProject(), refControl.getRefName(),
origCtl.getProjectControl().getProject(),
origCtl.getRefControl().getRefName(),
commit, ctx.getUser().asIdentifiedUser());
try {

View File

@@ -30,7 +30,7 @@ import com.google.gerrit.extensions.restapi.RestView;
import com.google.gerrit.server.edit.ChangeEdit;
import com.google.gerrit.server.edit.ChangeEditUtil;
import com.google.gerrit.server.git.UpdateException;
import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -84,7 +84,7 @@ public class PublishChangeEdit implements
@Override
public Response<?> apply(ChangeResource rsrc, Publish.Input in)
throws NoSuchProjectException, IOException, OrmException,
throws NoSuchChangeException, IOException, OrmException,
RestApiException, UpdateException {
Capable r =
rsrc.getControl().getProjectControl().canPushToAtLeastOneRef();

View File

@@ -148,7 +148,7 @@ public class RebaseChangeOp extends BatchUpdate.Op {
rebasedPatchSetId = ChangeUtil.nextPatchSetId(
ctx.getRepository(), ctl.getChange().currentPatchSetId());
patchSetInserter = patchSetInserterFactory
.create(ctl.getRefControl(), rebasedPatchSetId, rebasedCommit)
.create(ctl, rebasedPatchSetId, rebasedCommit)
.setDraft(originalPatchSet.isDraft())
.setSendMail(false)
.setRunHooks(runHooks)

View File

@@ -39,11 +39,8 @@ import com.google.gerrit.server.git.UpdateException;
import com.google.gerrit.server.index.change.ChangeIndexer;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectControl;
import com.google.gerrit.server.project.ProjectState;
import com.google.gerrit.server.project.RefControl;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
@@ -70,7 +67,6 @@ import java.io.IOException;
public class ChangeEditUtil {
private final GitRepositoryManager gitManager;
private final PatchSetInserter.Factory patchSetInserterFactory;
private final ProjectControl.GenericFactory projectControlFactory;
private final ChangeControl.GenericFactory changeControlFactory;
private final ChangeIndexer indexer;
private final ProjectCache projectCache;
@@ -83,7 +79,6 @@ public class ChangeEditUtil {
@Inject
ChangeEditUtil(GitRepositoryManager gitManager,
PatchSetInserter.Factory patchSetInserterFactory,
ProjectControl.GenericFactory projectControlFactory,
ChangeControl.GenericFactory changeControlFactory,
ChangeIndexer indexer,
ProjectCache projectCache,
@@ -94,7 +89,6 @@ public class ChangeEditUtil {
PatchSetUtil psUtil) {
this.gitManager = gitManager;
this.patchSetInserterFactory = patchSetInserterFactory;
this.projectControlFactory = projectControlFactory;
this.changeControlFactory = changeControlFactory;
this.indexer = indexer;
this.projectCache = projectCache;
@@ -168,13 +162,13 @@ public class ChangeEditUtil {
* its parent.
*
* @param edit change edit to publish
* @throws NoSuchProjectException
* @throws NoSuchChangeException
* @throws IOException
* @throws OrmException
* @throws UpdateException
* @throws RestApiException
*/
public void publish(ChangeEdit edit) throws NoSuchProjectException,
public void publish(ChangeEdit edit) throws NoSuchChangeException,
IOException, OrmException, RestApiException, UpdateException {
Change change = edit.getChange();
try (Repository repo = gitManager.openRepository(change.getProject());
@@ -238,11 +232,10 @@ public class ChangeEditUtil {
private Change insertPatchSet(ChangeEdit edit, Change change,
Repository repo, RevWalk rw, ObjectInserter oi, PatchSet basePatchSet,
RevCommit squashed) throws NoSuchProjectException, RestApiException,
UpdateException, IOException {
RefControl ctl = projectControlFactory
.controlFor(change.getProject(), edit.getUser())
.controlForRef(change.getDest());
RevCommit squashed) throws NoSuchChangeException, RestApiException,
UpdateException, OrmException, IOException {
ChangeControl ctl =
changeControlFactory.controlFor(db.get(), change, edit.getUser());
PatchSet.Id psId =
ChangeUtil.nextPatchSetId(repo, change.currentPatchSetId());
PatchSetInserter inserter =