Refactor ReplaceOp for updating change rest api
Similar to ChangeInserter which is used by both ReceiveCommits and CreateChange, make RequestScopePropagator optional and add update ref option. Change-Id: I436bc97a2da223cda79374a6815fa97c71753b51
This commit is contained in:
@@ -2400,10 +2400,12 @@ public class ReceiveCommits {
|
|||||||
rw.parseBody(newCommit);
|
rw.parseBody(newCommit);
|
||||||
|
|
||||||
RevCommit priorCommit = revisions.inverse().get(priorPatchSet);
|
RevCommit priorCommit = revisions.inverse().get(priorPatchSet);
|
||||||
replaceOp = replaceOpFactory.create(requestScopePropagator,
|
replaceOp = replaceOpFactory
|
||||||
projectControl, notes.getChange().getDest(), checkMergedInto,
|
.create(projectControl, notes.getChange().getDest(), checkMergedInto,
|
||||||
priorPatchSet, priorCommit, psId, newCommit, info, groups,
|
priorPatchSet, priorCommit, psId, newCommit, info, groups,
|
||||||
magicBranch, rp.getPushCertificate());
|
magicBranch, rp.getPushCertificate())
|
||||||
|
.setRequestScopePropagator(requestScopePropagator)
|
||||||
|
.setUpdateRef(false);
|
||||||
bu.addOp(notes.getChangeId(), replaceOp);
|
bu.addOp(notes.getChangeId(), replaceOp);
|
||||||
if (progress != null) {
|
if (progress != null) {
|
||||||
bu.addOp(notes.getChangeId(), new ChangeProgressOp(progress));
|
bu.addOp(notes.getChangeId(), new ChangeProgressOp(progress));
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ import org.eclipse.jgit.lib.RefDatabase;
|
|||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
import org.eclipse.jgit.revwalk.RevWalk;
|
import org.eclipse.jgit.revwalk.RevWalk;
|
||||||
import org.eclipse.jgit.transport.PushCertificate;
|
import org.eclipse.jgit.transport.PushCertificate;
|
||||||
|
import org.eclipse.jgit.transport.ReceiveCommand;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -78,7 +79,6 @@ import java.util.concurrent.ExecutorService;
|
|||||||
public class ReplaceOp extends BatchUpdate.Op {
|
public class ReplaceOp extends BatchUpdate.Op {
|
||||||
public interface Factory {
|
public interface Factory {
|
||||||
ReplaceOp create(
|
ReplaceOp create(
|
||||||
RequestScopePropagator requestScopePropagator,
|
|
||||||
ProjectControl projectControl,
|
ProjectControl projectControl,
|
||||||
Branch.NameKey dest,
|
Branch.NameKey dest,
|
||||||
boolean checkMergedInto,
|
boolean checkMergedInto,
|
||||||
@@ -112,7 +112,6 @@ public class ReplaceOp extends BatchUpdate.Op {
|
|||||||
private final PatchSetUtil psUtil;
|
private final PatchSetUtil psUtil;
|
||||||
private final ReplacePatchSetSender.Factory replacePatchSetFactory;
|
private final ReplacePatchSetSender.Factory replacePatchSetFactory;
|
||||||
|
|
||||||
private final RequestScopePropagator requestScopePropagator;
|
|
||||||
private final ProjectControl projectControl;
|
private final ProjectControl projectControl;
|
||||||
private final Branch.NameKey dest;
|
private final Branch.NameKey dest;
|
||||||
private final boolean checkMergedInto;
|
private final boolean checkMergedInto;
|
||||||
@@ -133,6 +132,8 @@ public class ReplaceOp extends BatchUpdate.Op {
|
|||||||
private ChangeMessage msg;
|
private ChangeMessage msg;
|
||||||
private String rejectMessage;
|
private String rejectMessage;
|
||||||
private MergedByPushOp mergedByPushOp;
|
private MergedByPushOp mergedByPushOp;
|
||||||
|
private RequestScopePropagator requestScopePropagator;
|
||||||
|
private boolean updateRef;
|
||||||
|
|
||||||
@AssistedInject
|
@AssistedInject
|
||||||
ReplaceOp(AccountResolver accountResolver,
|
ReplaceOp(AccountResolver accountResolver,
|
||||||
@@ -149,7 +150,6 @@ public class ReplaceOp extends BatchUpdate.Op {
|
|||||||
PatchSetUtil psUtil,
|
PatchSetUtil psUtil,
|
||||||
ReplacePatchSetSender.Factory replacePatchSetFactory,
|
ReplacePatchSetSender.Factory replacePatchSetFactory,
|
||||||
@SendEmailExecutor ExecutorService sendEmailExecutor,
|
@SendEmailExecutor ExecutorService sendEmailExecutor,
|
||||||
@Assisted RequestScopePropagator requestScopePropagator,
|
|
||||||
@Assisted ProjectControl projectControl,
|
@Assisted ProjectControl projectControl,
|
||||||
@Assisted Branch.NameKey dest,
|
@Assisted Branch.NameKey dest,
|
||||||
@Assisted boolean checkMergedInto,
|
@Assisted boolean checkMergedInto,
|
||||||
@@ -176,7 +176,6 @@ public class ReplaceOp extends BatchUpdate.Op {
|
|||||||
this.replacePatchSetFactory = replacePatchSetFactory;
|
this.replacePatchSetFactory = replacePatchSetFactory;
|
||||||
this.sendEmailExecutor = sendEmailExecutor;
|
this.sendEmailExecutor = sendEmailExecutor;
|
||||||
|
|
||||||
this.requestScopePropagator = requestScopePropagator;
|
|
||||||
this.projectControl = projectControl;
|
this.projectControl = projectControl;
|
||||||
this.dest = dest;
|
this.dest = dest;
|
||||||
this.checkMergedInto = checkMergedInto;
|
this.checkMergedInto = checkMergedInto;
|
||||||
@@ -188,6 +187,7 @@ public class ReplaceOp extends BatchUpdate.Op {
|
|||||||
this.groups = groups;
|
this.groups = groups;
|
||||||
this.magicBranch = magicBranch;
|
this.magicBranch = magicBranch;
|
||||||
this.pushCertificate = pushCertificate;
|
this.pushCertificate = pushCertificate;
|
||||||
|
this.updateRef = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -203,6 +203,12 @@ public class ReplaceOp extends BatchUpdate.Op {
|
|||||||
requestScopePropagator, patchSetId, mergedInto.getName());
|
requestScopePropagator, patchSetId, mergedInto.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (updateRef) {
|
||||||
|
ctx.addRefUpdate(
|
||||||
|
new ReceiveCommand(ObjectId.zeroId(), commit,
|
||||||
|
patchSetId.toRefName()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -366,8 +372,10 @@ public class ReplaceOp extends BatchUpdate.Op {
|
|||||||
// BatchUpdate's perspective there is no ref update. Thus we have to fire it
|
// BatchUpdate's perspective there is no ref update. Thus we have to fire it
|
||||||
// manually.
|
// manually.
|
||||||
final Account account = ctx.getAccount();
|
final Account account = ctx.getAccount();
|
||||||
gitRefUpdated.fire(ctx.getProject(), newPatchSet.getRefName(),
|
if (!updateRef) {
|
||||||
ObjectId.zeroId(), commit, account);
|
gitRefUpdated.fire(ctx.getProject(), newPatchSet.getRefName(),
|
||||||
|
ObjectId.zeroId(), commit, account);
|
||||||
|
}
|
||||||
|
|
||||||
if (changeKind != ChangeKind.TRIVIAL_REBASE) {
|
if (changeKind != ChangeKind.TRIVIAL_REBASE) {
|
||||||
Runnable sender = new Runnable() {
|
Runnable sender = new Runnable() {
|
||||||
@@ -454,10 +462,25 @@ public class ReplaceOp extends BatchUpdate.Op {
|
|||||||
return newPatchSet;
|
return newPatchSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Change getChange() {
|
||||||
|
return change;
|
||||||
|
}
|
||||||
|
|
||||||
public String getRejectMessage() {
|
public String getRejectMessage() {
|
||||||
return rejectMessage;
|
return rejectMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ReplaceOp setUpdateRef(boolean updateRef) {
|
||||||
|
this.updateRef = updateRef;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReplaceOp setRequestScopePropagator(
|
||||||
|
RequestScopePropagator requestScopePropagator) {
|
||||||
|
this.requestScopePropagator = requestScopePropagator;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
private Ref findMergedInto(Context ctx, String first, RevCommit commit) {
|
private Ref findMergedInto(Context ctx, String first, RevCommit commit) {
|
||||||
try {
|
try {
|
||||||
RefDatabase refDatabase = ctx.getRepository().getRefDatabase();
|
RefDatabase refDatabase = ctx.getRepository().getRefDatabase();
|
||||||
|
|||||||
Reference in New Issue
Block a user