Correct review message when a change is rebased

When a change is rebased from the Web UI, a comment is added:

  Patch Set 1: Patch Set 1 was rebased

But the message should refer to the patch set that was created by the
rebase, i.e.:

 Patch Set 2: Patch Set 1 was rebased

The wrong patch set number is used because the message is constructed
using `currentPatchSetId`, but this does not work as expected because
it is called before the new patch set is inserted and returns the ID of
the current patch set before the rebase.

Add a new method on the PatchSetInserter to get the ID of the patch set
that will be added.  Use this to construct the review message.

Change-Id: I589acf072768e78d1520d8692e011df5f211069c
This commit is contained in:
David Pursehouse
2013-08-13 15:57:24 +09:00
parent 7387f74496
commit 8b4f28671b
2 changed files with 10 additions and 3 deletions

View File

@@ -151,6 +151,11 @@ public class PatchSetInserter {
return this;
}
public PatchSet.Id getPatchSetId() {
init();
return patchSet.getId();
}
public PatchSetInserter setMessage(String message) throws OrmException {
changeMessage = new ChangeMessage(new ChangeMessage.Key(change.getId(),
ChangeUtil.messageUUID(db)), user.getAccountId(), patchSet.getId());

View File

@@ -293,7 +293,7 @@ public class RebaseChange {
final ChangeControl changeControl =
changeControlFactory.validateFor(change.getId(), uploader);
PatchSetInserter patchSetinserter = patchSetInserterFactory
PatchSetInserter patchSetInserter = patchSetInserterFactory
.create(git, revWalk, changeControl.getRefControl(), uploader, change, rebasedCommit)
.setCopyLabels(true)
.setValidatePolicy(validate)
@@ -301,13 +301,15 @@ public class RebaseChange {
.setSendMail(sendMail)
.setRunHooks(runHooks);
final PatchSet.Id newPatchSetId = patchSetInserter.getPatchSetId();
final ChangeMessage cmsg =
new ChangeMessage(new ChangeMessage.Key(change.getId(),
ChangeUtil.messageUUID(db)), uploader.getAccountId(), patchSetId);
cmsg.setMessage("Patch Set " + change.currentPatchSetId().get()
cmsg.setMessage("Patch Set " + newPatchSetId.get()
+ ": Patch Set " + patchSetId.get() + " was rebased");
Change newChange = patchSetinserter
Change newChange = patchSetInserter
.setMessage(cmsg)
.insert();