Merge "Add message to change created via cherry pick"

This commit is contained in:
Edwin Kempin 2015-02-05 13:06:21 +00:00 committed by Gerrit Code Review
commit 1c0ad3d74c
2 changed files with 33 additions and 4 deletions

View File

@ -169,6 +169,11 @@ public class RevisionIT extends AbstractDaemonTest {
origIt.next(); origIt.next();
assertThat(origIt.next().message).isEqualTo(expectedMessage); assertThat(origIt.next().message).isEqualTo(expectedMessage);
assertThat((Iterable<?>)cherry.get().messages).hasSize(1);
Iterator<ChangeMessageInfo> cherryIt = cherry.get().messages.iterator();
expectedMessage = "Patch Set 1: Cherry Picked from branch master.";
assertThat(cherryIt.next().message).isEqualTo(expectedMessage);
assertThat(cherry.get().subject).contains(in.message); assertThat(cherry.get().subject).contains(in.message);
assertThat(cherry.get().topic).isEqualTo("someTopic"); assertThat(cherry.get().topic).isEqualTo("someTopic");
cherry.current().review(ReviewInput.approve()); cherry.current().review(ReviewInput.approve());

View File

@ -193,14 +193,17 @@ public class CherryPickChange {
} else { } else {
// Change key not found on destination branch. We can create a new // Change key not found on destination branch. We can create a new
// change. // change.
Change.Id newChange = createNewChange(git, revWalk, changeKey, project, Change newChange = createNewChange(git, revWalk, changeKey, project,
destRef, cherryPickCommit, refControl, destRef, cherryPickCommit, refControl,
identifiedUser, change.getTopic()); identifiedUser, change.getTopic());
addMessageToSourceChange(change, patch.getId(), destinationBranch, addMessageToSourceChange(change, patch.getId(), destinationBranch,
cherryPickCommit, identifiedUser, refControl); cherryPickCommit, identifiedUser, refControl);
return newChange; addMessageToDestinationChange(newChange, change.getDest().getShortName(),
identifiedUser, refControl);
return newChange.getId();
} }
} finally { } finally {
revWalk.release(); revWalk.release();
@ -229,7 +232,7 @@ public class CherryPickChange {
return change.getId(); return change.getId();
} }
private Change.Id createNewChange(Repository git, RevWalk revWalk, private Change createNewChange(Repository git, RevWalk revWalk,
Change.Key changeKey, Project.NameKey project, Change.Key changeKey, Project.NameKey project,
Ref destRef, RevCommit cherryPickCommit, RefControl refControl, Ref destRef, RevCommit cherryPickCommit, RefControl refControl,
IdentifiedUser identifiedUser, String topic) IdentifiedUser identifiedUser, String topic)
@ -269,7 +272,7 @@ public class CherryPickChange {
ins.insert(); ins.insert();
return change.getId(); return change;
} }
private void addMessageToSourceChange(Change change, PatchSet.Id patchSetId, private void addMessageToSourceChange(Change change, PatchSet.Id patchSetId,
@ -293,4 +296,25 @@ public class CherryPickChange {
ChangeUpdate update = updateFactory.create(ctl, change.getCreatedOn()); ChangeUpdate update = updateFactory.create(ctl, change.getCreatedOn());
changeMessagesUtil.addChangeMessage(db.get(), update, changeMessage); changeMessagesUtil.addChangeMessage(db.get(), update, changeMessage);
} }
private void addMessageToDestinationChange(Change change, String sourceBranch,
IdentifiedUser identifiedUser, RefControl refControl) throws OrmException {
PatchSet.Id patchSetId =
db.get().patchSets().get(change.currentPatchSetId()).getId();
ChangeMessage changeMessage = new ChangeMessage(
new ChangeMessage.Key(
patchSetId.getParentKey(), ChangeUtil.messageUUID(db.get())),
identifiedUser.getAccountId(), TimeUtil.nowTs(), patchSetId);
StringBuilder sb = new StringBuilder("Patch Set ")
.append(patchSetId.get())
.append(": Cherry Picked from branch ")
.append(sourceBranch)
.append(".");
changeMessage.setMessage(sb.toString());
ChangeControl ctl = refControl.getProjectControl().controlFor(change);
ChangeUpdate update = updateFactory.create(ctl, change.getCreatedOn());
changeMessagesUtil.addChangeMessage(db.get(), update, changeMessage);
}
} }