Merge branch 'stable-2.8' into stable-2.9

* stable-2.8:
  Only permit current patch set to edit the commit message
  Use Provider for IdentifiedUser in CreateBranch constructor
  Split PGPEncryptedDataGenerator creation out into a utility method
  ChangeScreen2: Only reset the commit message text on cancel
  Fix log spew caused by DeleteBranch constructor

Change-Id: I21d682ba394b57d245e4f9f1f0ba187c20c14948
This commit is contained in:
David Pursehouse 2014-04-25 21:05:42 +09:00
commit 5b6ef4637b
4 changed files with 22 additions and 11 deletions

View File

@ -55,6 +55,7 @@ class EditMessageBox extends Composite {
this.revision = revision;
this.originalMessage = msg.trim();
initWidget(uiBinder.createAndBindUi(this));
message.setText("");
new TextBoxChangeListener(message) {
public void onTextChanged(String newText) {
save.setEnabled(!newText.trim()
@ -65,8 +66,10 @@ class EditMessageBox extends Composite {
@Override
protected void onLoad() {
message.setText(originalMessage);
save.setEnabled(false);
if (message.getText().isEmpty()) {
message.setText(originalMessage);
save.setEnabled(false);
}
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
@ -89,6 +92,7 @@ class EditMessageBox extends Composite {
@UiHandler("cancel")
void onCancel(ClickEvent e) {
message.setText("");
hide();
}

View File

@ -65,6 +65,11 @@ class EditMessage implements RestModifyView<RevisionResource, Input>,
ResourceNotFoundException, EmailException, OrmException, IOException {
if (Strings.isNullOrEmpty(input.message)) {
throw new BadRequestException("message must be non-empty");
} else if (!rsrc.getPatchSet().getId()
.equals(rsrc.getChange().currentPatchSetId())) {
throw new ResourceConflictException(String.format(
"revision %s is not current revision",
rsrc.getPatchSet().getRevision().get()));
}
try {
return json.format(changeUtil.editCommitMessage(

View File

@ -32,6 +32,7 @@ import com.google.gerrit.server.project.CreateBranch.Input;
import com.google.gerrit.server.project.ListBranches.BranchInfo;
import com.google.gerrit.server.util.MagicBranch;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
@ -64,14 +65,15 @@ public class CreateBranch implements RestModifyView<ProjectResource, Input> {
CreateBranch create(String ref);
}
private final IdentifiedUser identifiedUser;
private final Provider<IdentifiedUser> identifiedUser;
private final GitRepositoryManager repoManager;
private final GitReferenceUpdated referenceUpdated;
private final ChangeHooks hooks;
private String ref;
@Inject
CreateBranch(IdentifiedUser identifiedUser, GitRepositoryManager repoManager,
CreateBranch(Provider<IdentifiedUser> identifiedUser,
GitRepositoryManager repoManager,
GitReferenceUpdated referenceUpdated, ChangeHooks hooks,
@Assisted String ref) {
this.identifiedUser = identifiedUser;
@ -135,7 +137,7 @@ public class CreateBranch implements RestModifyView<ProjectResource, Input> {
final RefUpdate u = repo.updateRef(ref);
u.setExpectedOldObjectId(ObjectId.zeroId());
u.setNewObjectId(object.copy());
u.setRefLogIdent(identifiedUser.newRefLogIdent());
u.setRefLogIdent(identifiedUser.get().newRefLogIdent());
u.setRefLogMessage("created via REST from " + input.revision, false);
final RefUpdate.Result result = u.update(rw);
switch (result) {
@ -143,7 +145,7 @@ public class CreateBranch implements RestModifyView<ProjectResource, Input> {
case NEW:
case NO_CHANGE:
referenceUpdated.fire(name.getParentKey(), u);
hooks.doRefUpdatedHook(name, u, identifiedUser.getAccount());
hooks.doRefUpdatedHook(name, u, identifiedUser.get().getAccount());
break;
case LOCK_FAILURE:
if (repo.getRef(ref) != null) {

View File

@ -41,16 +41,16 @@ public class DeleteBranch implements RestModifyView<BranchResource, Input>{
static class Input {
}
private final IdentifiedUser identifiedUser;
private final Provider<IdentifiedUser> identifiedUser;
private final GitRepositoryManager repoManager;
private final Provider<ReviewDb> dbProvider;
private final GitReferenceUpdated referenceUpdated;
private final ChangeHooks hooks;
@Inject
DeleteBranch(IdentifiedUser identifiedUser, GitRepositoryManager repoManager,
Provider<ReviewDb> dbProvider, GitReferenceUpdated referenceUpdated,
ChangeHooks hooks) {
DeleteBranch(Provider<IdentifiedUser> identifiedUser,
GitRepositoryManager repoManager, Provider<ReviewDb> dbProvider,
GitReferenceUpdated referenceUpdated, ChangeHooks hooks) {
this.identifiedUser = identifiedUser;
this.repoManager = repoManager;
this.dbProvider = dbProvider;
@ -89,7 +89,7 @@ public class DeleteBranch implements RestModifyView<BranchResource, Input>{
case FAST_FORWARD:
case FORCED:
referenceUpdated.fire(rsrc.getNameKey(), u);
hooks.doRefUpdatedHook(rsrc.getBranchKey(), u, identifiedUser.getAccount());
hooks.doRefUpdatedHook(rsrc.getBranchKey(), u, identifiedUser.get().getAccount());
break;
case REJECTED_CURRENT_BRANCH: