Tweak PatchSetInserter to look more like ChangeInserter
Don't pass in the repo and RevWalk, since those should come from the RepoContext. Change callers to use the same Repository/RevWalk/ ObjectInserter instances and call setRepository on the enclosing BatchUpdate. Don't lazily compute patch set ID; have callers compute it themselves and pass it in at construction time, since we no longer have a Repository instance in the PatchSetInserter. Change-Id: I845b887ae7ffc2c1a14bad13c62c41ff1ff6fc34
This commit is contained in:
@@ -176,7 +176,7 @@ public class CherryPickChange {
|
||||
} else if (destChanges.size() == 1) {
|
||||
// The change key exists on the destination branch. The cherry pick
|
||||
// will be added as a new patch set.
|
||||
return insertPatchSet(git, revWalk, destChanges.get(0).change(),
|
||||
return insertPatchSet(git, revWalk, oi, destChanges.get(0).change(),
|
||||
cherryPickCommit, refControl, identifiedUser);
|
||||
} else {
|
||||
// Change key not found on destination branch. We can create a new
|
||||
@@ -203,19 +203,20 @@ public class CherryPickChange {
|
||||
}
|
||||
|
||||
private Change.Id insertPatchSet(Repository git, RevWalk revWalk,
|
||||
Change change, CodeReviewCommit cherryPickCommit, RefControl refControl,
|
||||
IdentifiedUser identifiedUser)
|
||||
ObjectInserter oi, Change change, CodeReviewCommit cherryPickCommit,
|
||||
RefControl refControl, IdentifiedUser identifiedUser)
|
||||
throws IOException, OrmException, UpdateException, RestApiException {
|
||||
final ChangeControl changeControl =
|
||||
refControl.getProjectControl().controlFor(change);
|
||||
final PatchSetInserter inserter = patchSetInserterFactory
|
||||
.create(git, revWalk, changeControl, cherryPickCommit);
|
||||
final PatchSet.Id newPatchSetId = inserter.getPatchSetId();
|
||||
PatchSet.Id psId =
|
||||
ChangeUtil.nextPatchSetId(git, change.currentPatchSetId());
|
||||
PatchSetInserter inserter = patchSetInserterFactory
|
||||
.create(refControl, psId, cherryPickCommit);
|
||||
PatchSet.Id newPatchSetId = inserter.getPatchSetId();
|
||||
PatchSet current = db.get().patchSets().get(change.currentPatchSetId());
|
||||
|
||||
try (BatchUpdate bu = batchUpdateFactory.create(
|
||||
db.get(), change.getDest().getParentKey(), identifiedUser,
|
||||
TimeUtil.nowTs())) {
|
||||
bu.setRepository(git, revWalk, oi);
|
||||
bu.addOp(change.getId(), inserter
|
||||
.setMessage("Uploaded patch set " + newPatchSetId.get() + ".")
|
||||
.setDraft(current.isDraft())
|
||||
|
@@ -47,8 +47,9 @@ import com.google.gerrit.server.git.UpdateException;
|
||||
import com.google.gerrit.server.git.validators.CommitValidators;
|
||||
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;
|
||||
@@ -59,6 +60,7 @@ import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||
import org.eclipse.jgit.errors.MissingObjectException;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.ObjectInserter;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.RefUpdate;
|
||||
@@ -108,7 +110,7 @@ public class ConsistencyChecker {
|
||||
private final GitRepositoryManager repoManager;
|
||||
private final Provider<CurrentUser> user;
|
||||
private final Provider<PersonIdent> serverIdent;
|
||||
private final ChangeControl.GenericFactory changeControlFactory;
|
||||
private final ProjectControl.GenericFactory projectControlFactory;
|
||||
private final PatchSetInfoFactory patchSetInfoFactory;
|
||||
private final PatchSetInserter.Factory patchSetInserterFactory;
|
||||
private final BatchUpdate.Factory updateFactory;
|
||||
@@ -130,7 +132,7 @@ public class ConsistencyChecker {
|
||||
GitRepositoryManager repoManager,
|
||||
Provider<CurrentUser> user,
|
||||
@GerritPersonIdent Provider<PersonIdent> serverIdent,
|
||||
ChangeControl.GenericFactory changeControlFactory,
|
||||
ProjectControl.GenericFactory projectControlFactory,
|
||||
PatchSetInfoFactory patchSetInfoFactory,
|
||||
PatchSetInserter.Factory patchSetInserterFactory,
|
||||
BatchUpdate.Factory updateFactory) {
|
||||
@@ -138,7 +140,7 @@ public class ConsistencyChecker {
|
||||
this.repoManager = repoManager;
|
||||
this.user = user;
|
||||
this.serverIdent = serverIdent;
|
||||
this.changeControlFactory = changeControlFactory;
|
||||
this.projectControlFactory = projectControlFactory;
|
||||
this.patchSetInfoFactory = patchSetInfoFactory;
|
||||
this.patchSetInserterFactory = patchSetInserterFactory;
|
||||
this.updateFactory = updateFactory;
|
||||
@@ -461,29 +463,33 @@ public class ConsistencyChecker {
|
||||
}
|
||||
|
||||
try {
|
||||
ChangeControl ctl = changeControlFactory.controlFor(change, user.get());
|
||||
RefControl ctl = projectControlFactory
|
||||
.controlFor(change.getProject(), user.get())
|
||||
.controlForRef(change.getDest());
|
||||
PatchSet.Id psId =
|
||||
ChangeUtil.nextPatchSetId(repo, change.currentPatchSetId());
|
||||
PatchSetInserter inserter =
|
||||
patchSetInserterFactory.create(repo, rw, ctl, commit);
|
||||
patchSetInserterFactory.create(ctl, psId, commit);
|
||||
try (BatchUpdate bu = updateFactory.create(
|
||||
db.get(), change.getDest().getParentKey(), user.get(),
|
||||
TimeUtil.nowTs())) {
|
||||
db.get(), change.getProject(), ctl.getUser(), TimeUtil.nowTs());
|
||||
ObjectInserter oi = repo.newObjectInserter()) {
|
||||
bu.setRepository(repo, rw, oi);
|
||||
bu.addOp(change.getId(), inserter
|
||||
.setValidatePolicy(CommitValidators.Policy.NONE)
|
||||
.setRunHooks(false)
|
||||
.setSendMail(false)
|
||||
.setAllowClosed(true)
|
||||
.setUploader(user.get().getAccountId())
|
||||
// TODO: fix setMessage to work without init()
|
||||
.setMessage(
|
||||
"Patch set for merged commit inserted by consistency checker"));
|
||||
bu.execute();
|
||||
}
|
||||
change = inserter.getChange();
|
||||
PatchSet.Id psId = change.currentPatchSetId();
|
||||
p.status = Status.FIXED;
|
||||
p.outcome = "Inserted as patch set " + psId.get();
|
||||
return psId;
|
||||
} catch (NoSuchChangeException | UpdateException | RestApiException e) {
|
||||
} catch (IOException | NoSuchProjectException | UpdateException
|
||||
| RestApiException e) {
|
||||
warn(e);
|
||||
p.status = Status.FIX_FAILED;
|
||||
p.outcome = "Error inserting new patch set";
|
||||
|
@@ -31,7 +31,6 @@ import com.google.gerrit.server.ApprovalCopier;
|
||||
import com.google.gerrit.server.ApprovalsUtil;
|
||||
import com.google.gerrit.server.ChangeMessagesUtil;
|
||||
import com.google.gerrit.server.ChangeUtil;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.events.CommitReceivedEvent;
|
||||
import com.google.gerrit.server.git.BanCommit;
|
||||
import com.google.gerrit.server.git.BatchUpdate;
|
||||
@@ -47,6 +46,7 @@ import com.google.gerrit.server.patch.PatchSetInfoFactory;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.ChangeModifiedException;
|
||||
import com.google.gerrit.server.project.InvalidChangeOperationException;
|
||||
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.AtomicUpdate;
|
||||
@@ -55,10 +55,8 @@ import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.assistedinject.AssistedInject;
|
||||
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.notes.NoteMap;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.eclipse.jgit.transport.ReceiveCommand;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -71,7 +69,7 @@ public class PatchSetInserter extends BatchUpdate.Op {
|
||||
LoggerFactory.getLogger(PatchSetInserter.class);
|
||||
|
||||
public static interface Factory {
|
||||
PatchSetInserter create(Repository git, RevWalk revWalk, ChangeControl ctl,
|
||||
PatchSetInserter create(RefControl refControl, PatchSet.Id psId,
|
||||
RevCommit commit);
|
||||
}
|
||||
|
||||
@@ -86,14 +84,9 @@ public class PatchSetInserter extends BatchUpdate.Op {
|
||||
private final ChangeMessagesUtil cmUtil;
|
||||
|
||||
// Assisted-injected fields.
|
||||
private final PatchSet.Id psId;
|
||||
private final RevCommit commit;
|
||||
private final ChangeControl ctl;
|
||||
private final IdentifiedUser user;
|
||||
private final Repository git;
|
||||
private final RevWalk revWalk;
|
||||
|
||||
// Lazily initialized fields.
|
||||
private PatchSet.Id psId;
|
||||
private final RefControl refControl;
|
||||
|
||||
// Fields exposed as setters.
|
||||
private SshInfo sshInfo;
|
||||
@@ -123,9 +116,8 @@ public class PatchSetInserter extends BatchUpdate.Op {
|
||||
PatchSetInfoFactory patchSetInfoFactory,
|
||||
CommitValidators.Factory commitValidatorsFactory,
|
||||
ReplacePatchSetSender.Factory replacePatchSetFactory,
|
||||
@Assisted Repository git,
|
||||
@Assisted RevWalk revWalk,
|
||||
@Assisted ChangeControl ctl,
|
||||
@Assisted RefControl refControl,
|
||||
@Assisted PatchSet.Id psId,
|
||||
@Assisted RevCommit commit) {
|
||||
this.hooks = hooks;
|
||||
this.db = db;
|
||||
@@ -136,18 +128,12 @@ public class PatchSetInserter extends BatchUpdate.Op {
|
||||
this.commitValidatorsFactory = commitValidatorsFactory;
|
||||
this.replacePatchSetFactory = replacePatchSetFactory;
|
||||
|
||||
this.git = git;
|
||||
this.revWalk = revWalk;
|
||||
this.refControl = refControl;
|
||||
this.psId = psId;
|
||||
this.commit = commit;
|
||||
this.ctl = ctl;
|
||||
this.user = ctl.getUser().asIdentifiedUser();
|
||||
}
|
||||
|
||||
public PatchSet.Id getPatchSetId() throws IOException {
|
||||
if (psId == null) {
|
||||
psId =
|
||||
ChangeUtil.nextPatchSetId(git, ctl.getChange().currentPatchSetId());
|
||||
}
|
||||
public PatchSet.Id getPatchSetId() {
|
||||
return psId;
|
||||
}
|
||||
|
||||
@@ -205,7 +191,7 @@ public class PatchSetInserter extends BatchUpdate.Op {
|
||||
public void updateRepo(RepoContext ctx)
|
||||
throws InvalidChangeOperationException, IOException {
|
||||
init();
|
||||
validate();
|
||||
validate(ctx);
|
||||
patchSetInfo = patchSetInfoFactory.get(ctx.getRevWalk(), commit, psId);
|
||||
ctx.addRefUpdate(new ReceiveCommand(ObjectId.zeroId(),
|
||||
commit, getPatchSetId().toRefName(), ReceiveCommand.Type.CREATE));
|
||||
@@ -214,6 +200,8 @@ public class PatchSetInserter extends BatchUpdate.Op {
|
||||
@Override
|
||||
public void updateChange(ChangeContext ctx) throws OrmException,
|
||||
InvalidChangeOperationException {
|
||||
ChangeControl ctl = ctx.getChangeControl();
|
||||
|
||||
change = ctx.getChange();
|
||||
Change.Id id = change.getId();
|
||||
final PatchSet.Id currentPatchSetId = change.currentPatchSetId();
|
||||
@@ -244,7 +232,7 @@ public class PatchSetInserter extends BatchUpdate.Op {
|
||||
changeMessage = new ChangeMessage(
|
||||
new ChangeMessage.Key(
|
||||
ctl.getChange().getId(), ChangeUtil.messageUUID(db)),
|
||||
user.getAccountId(), ctx.getWhen(), patchSet.getId());
|
||||
ctx.getUser().getAccountId(), ctx.getWhen(), patchSet.getId());
|
||||
changeMessage.setMessage(message);
|
||||
}
|
||||
|
||||
@@ -284,7 +272,7 @@ public class PatchSetInserter extends BatchUpdate.Op {
|
||||
try {
|
||||
ReplacePatchSetSender cm = replacePatchSetFactory.create(
|
||||
change.getId());
|
||||
cm.setFrom(user.getAccountId());
|
||||
cm.setFrom(ctx.getUser().getAccountId());
|
||||
cm.setPatchSet(patchSet, patchSetInfo);
|
||||
cm.setChangeMessage(changeMessage);
|
||||
cm.addReviewers(oldReviewers.get(ReviewerState.REVIEWER));
|
||||
@@ -307,9 +295,10 @@ public class PatchSetInserter extends BatchUpdate.Op {
|
||||
}
|
||||
}
|
||||
|
||||
private void validate() throws InvalidChangeOperationException, IOException {
|
||||
CommitValidators cv =
|
||||
commitValidatorsFactory.create(ctl.getRefControl(), sshInfo, git);
|
||||
private void validate(RepoContext ctx)
|
||||
throws InvalidChangeOperationException, IOException {
|
||||
CommitValidators cv = commitValidatorsFactory.create(
|
||||
refControl, sshInfo, ctx.getRepository());
|
||||
|
||||
String refName = getPatchSetId().toRefName();
|
||||
CommitReceivedEvent event = new CommitReceivedEvent(
|
||||
@@ -317,13 +306,14 @@ public class PatchSetInserter extends BatchUpdate.Op {
|
||||
ObjectId.zeroId(),
|
||||
commit.getId(),
|
||||
refName.substring(0, refName.lastIndexOf('/') + 1) + "new"),
|
||||
ctl.getProjectControl().getProject(), ctl.getRefControl().getRefName(),
|
||||
commit, user);
|
||||
refControl.getProjectControl().getProject(), refControl.getRefName(),
|
||||
commit, ctx.getUser().asIdentifiedUser());
|
||||
|
||||
try {
|
||||
switch (validatePolicy) {
|
||||
case RECEIVE_COMMITS:
|
||||
NoteMap rejectCommits = BanCommit.loadRejectCommitsMap(git, revWalk);
|
||||
NoteMap rejectCommits = BanCommit.loadRejectCommitsMap(
|
||||
ctx.getRepository(), ctx.getRevWalk());
|
||||
cv.validateForReceiveCommits(event, rejectCommits);
|
||||
break;
|
||||
case GERRIT:
|
||||
|
@@ -31,7 +31,7 @@ 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.InvalidChangeOperationException;
|
||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -85,7 +85,7 @@ public class PublishChangeEdit implements
|
||||
|
||||
@Override
|
||||
public Response<?> apply(ChangeResource rsrc, Publish.Input in)
|
||||
throws NoSuchChangeException,
|
||||
throws NoSuchProjectException,
|
||||
IOException, InvalidChangeOperationException, OrmException,
|
||||
RestApiException, UpdateException {
|
||||
Capable r =
|
||||
|
@@ -36,6 +36,7 @@ import com.google.gerrit.server.git.UpdateException;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.InvalidChangeOperationException;
|
||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
@@ -95,7 +96,7 @@ public class Rebase implements RestModifyView<RevisionResource, RebaseInput>,
|
||||
rebaseChange.get().rebase(repo, rw, rsrc, findBaseRev(rw, rsrc, input));
|
||||
} catch (InvalidChangeOperationException e) {
|
||||
throw new ResourceConflictException(e.getMessage());
|
||||
} catch (NoSuchChangeException e) {
|
||||
} catch (NoSuchChangeException | NoSuchProjectException e) {
|
||||
throw new ResourceNotFoundException(change.getId().toString());
|
||||
}
|
||||
|
||||
|
@@ -24,6 +24,7 @@ import com.google.gerrit.reviewdb.client.Change.Status;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.RevId;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.ChangeUtil;
|
||||
import com.google.gerrit.server.GerritPersonIdent;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.git.BatchUpdate;
|
||||
@@ -32,9 +33,11 @@ import com.google.gerrit.server.git.MergeConflictException;
|
||||
import com.google.gerrit.server.git.MergeUtil;
|
||||
import com.google.gerrit.server.git.UpdateException;
|
||||
import com.google.gerrit.server.git.validators.CommitValidators;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.InvalidChangeOperationException;
|
||||
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.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
@@ -59,7 +62,7 @@ import java.util.TimeZone;
|
||||
public class RebaseChange {
|
||||
private static final Logger log = LoggerFactory.getLogger(RebaseChange.class);
|
||||
|
||||
private final ChangeControl.GenericFactory changeControlFactory;
|
||||
private final ProjectControl.GenericFactory projectControlFactory;
|
||||
private final Provider<ReviewDb> db;
|
||||
private final GitRepositoryManager gitManager;
|
||||
private final TimeZone serverTimeZone;
|
||||
@@ -68,14 +71,14 @@ public class RebaseChange {
|
||||
private final BatchUpdate.Factory updateFactory;
|
||||
|
||||
@Inject
|
||||
RebaseChange(ChangeControl.GenericFactory changeControlFactory,
|
||||
RebaseChange(ProjectControl.GenericFactory projectControlFactory,
|
||||
Provider<ReviewDb> db,
|
||||
@GerritPersonIdent PersonIdent myIdent,
|
||||
GitRepositoryManager gitManager,
|
||||
MergeUtil.Factory mergeUtilFactory,
|
||||
PatchSetInserter.Factory patchSetInserterFactory,
|
||||
BatchUpdate.Factory updateFactory) {
|
||||
this.changeControlFactory = changeControlFactory;
|
||||
this.projectControlFactory = projectControlFactory;
|
||||
this.db = db;
|
||||
this.gitManager = gitManager;
|
||||
this.serverTimeZone = myIdent.getTimeZone();
|
||||
@@ -104,6 +107,8 @@ public class RebaseChange {
|
||||
* @param newBaseRev the commit that should be the new base.
|
||||
* @throws NoSuchChangeException if the change to which the patch set belongs
|
||||
* does not exist or is not visible to the user.
|
||||
* @throws NoSuchProjectException if the project to which the patch set
|
||||
* belongs does not exist or is not visible to the user.
|
||||
* @throws EmailException if sending the e-mail to notify about the new patch
|
||||
* set fails.
|
||||
* @throws OrmException if accessing the database fails.
|
||||
@@ -115,8 +120,8 @@ public class RebaseChange {
|
||||
* @throws UpdateException if updating the change fails.
|
||||
*/
|
||||
public void rebase(Repository git, RevWalk rw, RevisionResource rsrc,
|
||||
String newBaseRev) throws NoSuchChangeException, EmailException,
|
||||
OrmException, IOException, InvalidChangeOperationException,
|
||||
String newBaseRev) throws NoSuchChangeException, NoSuchProjectException,
|
||||
EmailException, OrmException, IOException, InvalidChangeOperationException,
|
||||
UpdateException, RestApiException {
|
||||
Change change = rsrc.getChange();
|
||||
PatchSet patchSet = rsrc.getPatchSet();
|
||||
@@ -246,8 +251,8 @@ public class RebaseChange {
|
||||
* @param validate if commit validation should be run for the new patch set.
|
||||
* @param rw the RevWalk.
|
||||
* @return the new patch set, which is based on the given base commit.
|
||||
* @throws NoSuchChangeException if the change to which the patch set belongs
|
||||
* does not exist or is not visible to the user.
|
||||
* @throws NoSuchProjectException if the project to which the patch set
|
||||
* belongs does not exist or is not visible to the user.
|
||||
* @throws OrmException if accessing the database fails.
|
||||
* @throws IOException if rebase is not possible.
|
||||
* @throws InvalidChangeOperationException if rebase is not possible or not
|
||||
@@ -261,7 +266,7 @@ public class RebaseChange {
|
||||
IdentifiedUser uploader, RevCommit baseCommit, MergeUtil mergeUtil,
|
||||
PersonIdent committerIdent, boolean runHooks,
|
||||
CommitValidators.Policy validate)
|
||||
throws NoSuchChangeException, OrmException, IOException,
|
||||
throws NoSuchProjectException, OrmException, IOException,
|
||||
InvalidChangeOperationException, MergeConflictException, UpdateException,
|
||||
RestApiException {
|
||||
if (!change.currentPatchSetId().equals(patchSetId)) {
|
||||
@@ -278,11 +283,14 @@ public class RebaseChange {
|
||||
|
||||
rebasedCommit = rw.parseCommit(newId);
|
||||
|
||||
ChangeControl changeControl =
|
||||
changeControlFactory.validateFor(change, uploader);
|
||||
RefControl ctl = projectControlFactory
|
||||
.controlFor(change.getProject(), uploader)
|
||||
.controlForRef(change.getDest());
|
||||
|
||||
PatchSet.Id psId =
|
||||
ChangeUtil.nextPatchSetId(git, change.currentPatchSetId());
|
||||
PatchSetInserter patchSetInserter = patchSetInserterFactory
|
||||
.create(git, rw, changeControl, rebasedCommit)
|
||||
.create(ctl, psId, rebasedCommit)
|
||||
.setValidatePolicy(validate)
|
||||
.setDraft(originalPatchSet.isDraft())
|
||||
.setUploader(uploader.getAccountId())
|
||||
|
@@ -26,6 +26,7 @@ import com.google.gerrit.reviewdb.client.Change.Status;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.ChangeUtil;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.change.ChangeKind;
|
||||
@@ -35,10 +36,11 @@ import com.google.gerrit.server.git.BatchUpdate;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.UpdateException;
|
||||
import com.google.gerrit.server.index.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;
|
||||
@@ -65,7 +67,7 @@ import java.io.IOException;
|
||||
public class ChangeEditUtil {
|
||||
private final GitRepositoryManager gitManager;
|
||||
private final PatchSetInserter.Factory patchSetInserterFactory;
|
||||
private final ChangeControl.GenericFactory changeControlFactory;
|
||||
private final ProjectControl.GenericFactory projectControlFactory;
|
||||
private final ChangeIndexer indexer;
|
||||
private final ProjectCache projectCache;
|
||||
private final Provider<ReviewDb> db;
|
||||
@@ -76,7 +78,7 @@ public class ChangeEditUtil {
|
||||
@Inject
|
||||
ChangeEditUtil(GitRepositoryManager gitManager,
|
||||
PatchSetInserter.Factory patchSetInserterFactory,
|
||||
ChangeControl.GenericFactory changeControlFactory,
|
||||
ProjectControl.GenericFactory projectControlFactory,
|
||||
ChangeIndexer indexer,
|
||||
ProjectCache projectCache,
|
||||
Provider<ReviewDb> db,
|
||||
@@ -85,7 +87,7 @@ public class ChangeEditUtil {
|
||||
BatchUpdate.Factory updateFactory) {
|
||||
this.gitManager = gitManager;
|
||||
this.patchSetInserterFactory = patchSetInserterFactory;
|
||||
this.changeControlFactory = changeControlFactory;
|
||||
this.projectControlFactory = projectControlFactory;
|
||||
this.indexer = indexer;
|
||||
this.projectCache = projectCache;
|
||||
this.db = db;
|
||||
@@ -147,13 +149,13 @@ public class ChangeEditUtil {
|
||||
* its parent.
|
||||
*
|
||||
* @param edit change edit to publish
|
||||
* @throws NoSuchChangeException
|
||||
* @throws NoSuchProjectException
|
||||
* @throws IOException
|
||||
* @throws OrmException
|
||||
* @throws UpdateException
|
||||
* @throws RestApiException
|
||||
*/
|
||||
public void publish(ChangeEdit edit) throws NoSuchChangeException,
|
||||
public void publish(ChangeEdit edit) throws NoSuchProjectException,
|
||||
IOException, OrmException, RestApiException, UpdateException {
|
||||
Change change = edit.getChange();
|
||||
try (Repository repo = gitManager.openRepository(change.getProject());
|
||||
@@ -166,7 +168,7 @@ public class ChangeEditUtil {
|
||||
}
|
||||
|
||||
Change updatedChange =
|
||||
insertPatchSet(edit, change, repo, rw, basePatchSet,
|
||||
insertPatchSet(edit, change, repo, rw, inserter, basePatchSet,
|
||||
squashEdit(rw, inserter, edit.getEditCommit(), basePatchSet));
|
||||
// TODO(davido): This should happen in the same BatchRefUpdate.
|
||||
deleteRef(repo, edit);
|
||||
@@ -215,12 +217,16 @@ public class ChangeEditUtil {
|
||||
}
|
||||
|
||||
private Change insertPatchSet(ChangeEdit edit, Change change,
|
||||
Repository repo, RevWalk rw, PatchSet basePatchSet, RevCommit squashed)
|
||||
throws NoSuchChangeException, RestApiException, UpdateException,
|
||||
IOException {
|
||||
ChangeControl ctl = changeControlFactory.controlFor(change, edit.getUser());
|
||||
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());
|
||||
PatchSet.Id psId =
|
||||
ChangeUtil.nextPatchSetId(repo, change.currentPatchSetId());
|
||||
PatchSetInserter inserter =
|
||||
patchSetInserterFactory.create(repo, rw, ctl, squashed);
|
||||
patchSetInserterFactory.create(ctl, psId, squashed);
|
||||
|
||||
StringBuilder message = new StringBuilder("Patch set ")
|
||||
.append(inserter.getPatchSetId().get())
|
||||
@@ -241,6 +247,7 @@ public class ChangeEditUtil {
|
||||
try (BatchUpdate bu = updateFactory.create(
|
||||
db.get(), change.getProject(), ctl.getUser(),
|
||||
TimeUtil.nowTs())) {
|
||||
bu.setRepository(repo, rw, oi);
|
||||
bu.addOp(change.getId(), inserter
|
||||
.setDraft(change.getStatus() == Status.DRAFT ||
|
||||
basePatchSet.isDraft())
|
||||
|
@@ -79,6 +79,10 @@ public class BatchUpdate implements AutoCloseable {
|
||||
}
|
||||
|
||||
public class Context {
|
||||
public Project.NameKey getProject() {
|
||||
return project;
|
||||
}
|
||||
|
||||
public Timestamp getWhen() {
|
||||
return when;
|
||||
}
|
||||
@@ -237,6 +241,10 @@ public class BatchUpdate implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
public CurrentUser getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public Repository getRepository() throws IOException {
|
||||
initRepository();
|
||||
return repo;
|
||||
|
@@ -31,6 +31,7 @@ import com.google.gerrit.server.git.validators.CommitValidators;
|
||||
import com.google.gerrit.server.patch.PatchSetInfoFactory;
|
||||
import com.google.gerrit.server.project.InvalidChangeOperationException;
|
||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
@@ -117,9 +118,9 @@ public class RebaseIfNecessary extends SubmitStrategy {
|
||||
setRefLogIdent();
|
||||
} catch (MergeConflictException e) {
|
||||
n.setStatusCode(CommitMergeStatus.REBASE_MERGE_CONFLICT);
|
||||
} catch (NoSuchChangeException | OrmException | IOException
|
||||
| InvalidChangeOperationException | UpdateException
|
||||
| RestApiException e) {
|
||||
} catch (NoSuchChangeException | NoSuchProjectException
|
||||
| OrmException | IOException | InvalidChangeOperationException
|
||||
| UpdateException | RestApiException e) {
|
||||
// TODO(dborowitz): Allow Submit to unwrap ResourceConflictException
|
||||
// so it can turn into a 409.
|
||||
throw new MergeException("Cannot rebase " + n.name(), e);
|
||||
|
@@ -17,6 +17,7 @@ package com.google.gerrit.server.query.change;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.TruthJUnit.assume;
|
||||
import static com.google.gerrit.extensions.client.ListChangesOption.REVIEWED;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.util.concurrent.TimeUnit.HOURS;
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
@@ -75,6 +76,7 @@ import com.google.inject.util.Providers;
|
||||
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.ObjectInserter;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeUtils;
|
||||
@@ -1338,15 +1340,18 @@ public abstract class AbstractQueryChangesTest {
|
||||
.message("message")
|
||||
.add("file" + n, "contents " + n)
|
||||
.create());
|
||||
ChangeControl ctl = changeControlFactory.controlFor(c.getId(), user);
|
||||
RefControl ctl = projectControlFactory.controlFor(c.getProject(), user)
|
||||
.controlForRef(c.getDest());
|
||||
|
||||
PatchSetInserter inserter = patchSetFactory.create(
|
||||
repo.getRepository(), repo.getRevWalk(), ctl, commit)
|
||||
ctl, new PatchSet.Id(c.getId(), n), commit)
|
||||
.setSendMail(false)
|
||||
.setRunHooks(false)
|
||||
.setValidatePolicy(CommitValidators.Policy.NONE);
|
||||
try (BatchUpdate bu = updateFactory.create(
|
||||
db, c.getDest().getParentKey(), user, TimeUtil.nowTs())) {
|
||||
db, c.getProject(), user, TimeUtil.nowTs());
|
||||
ObjectInserter oi = repo.getRepository().newObjectInserter()) {
|
||||
bu.setRepository(repo.getRepository(), repo.getRevWalk(), oi);
|
||||
bu.addOp(c.getId(), inserter);
|
||||
bu.execute();
|
||||
}
|
||||
|
Reference in New Issue
Block a user