Rebase: Fix CurrentRevision in NoteDb

This caller was missed long ago when we refactored everything to use
PatchSetUtil to look up PatchSets. Probably not coincidentally because
it was never tested, nor indeed plumbed into ChangeApi.

Change-Id: Ib77304286df14f22370375911bb59bd8bd3e6356
This commit is contained in:
Dave Borowitz 2017-02-23 16:20:05 -05:00
parent e32ed73ac2
commit cfc9e6da54
4 changed files with 59 additions and 6 deletions

View File

@ -88,6 +88,7 @@ import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup;
@ -328,8 +329,22 @@ public class ChangeIT extends AbstractDaemonTest {
gApi.changes().id(r.getChangeId()).revert();
}
@FunctionalInterface
private interface Rebase {
void call(String id) throws RestApiException;
}
@Test
public void rebase() throws Exception {
public void rebaseViaRevisionApi() throws Exception {
testRebase(id -> gApi.changes().id(id).current().rebase());
}
@Test
public void rebaseViaChangeApi() throws Exception {
testRebase(id -> gApi.changes().id(id).rebase());
}
private void testRebase(Rebase rebase) throws Exception {
// Create two changes both with the same parent
PushOneCommit.Result r = createChange();
testRepo.reset("HEAD~1");
@ -342,7 +357,7 @@ public class ChangeIT extends AbstractDaemonTest {
String changeId = r2.getChangeId();
// Rebase the second change
gApi.changes().id(changeId).current().rebase();
rebase.call(changeId);
// Second change should have 2 patch sets
ChangeInfo c2 = gApi.changes().id(changeId).get();

View File

@ -114,6 +114,12 @@ public interface ChangeApi {
/** Publishes a draft change. */
void publish() throws RestApiException;
/** Rebase the current revision of a change using default options. */
void rebase() throws RestApiException;
/** Rebase the current revision of a change. */
void rebase(RebaseInput in) throws RestApiException;
/** Deletes a change. */
void delete() throws RestApiException;
@ -315,6 +321,16 @@ public interface ChangeApi {
throw new NotImplementedException();
}
@Override
public void rebase() {
throw new NotImplementedException();
}
@Override
public void rebase(RebaseInput in) {
throw new NotImplementedException();
}
@Override
public void delete() {
throw new NotImplementedException();

View File

@ -14,6 +14,7 @@
package com.google.gerrit.server.api.changes;
import com.google.gerrit.common.errors.EmailException;
import com.google.gerrit.extensions.api.changes.AbandonInput;
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
import com.google.gerrit.extensions.api.changes.AssigneeInput;
@ -24,6 +25,7 @@ import com.google.gerrit.extensions.api.changes.FixInput;
import com.google.gerrit.extensions.api.changes.HashtagsInput;
import com.google.gerrit.extensions.api.changes.IncludedInInfo;
import com.google.gerrit.extensions.api.changes.MoveInput;
import com.google.gerrit.extensions.api.changes.RebaseInput;
import com.google.gerrit.extensions.api.changes.RestoreInput;
import com.google.gerrit.extensions.api.changes.RevertInput;
import com.google.gerrit.extensions.api.changes.ReviewerApi;
@ -63,6 +65,7 @@ import com.google.gerrit.server.change.PostReviewers;
import com.google.gerrit.server.change.PublishDraftPatchSet;
import com.google.gerrit.server.change.PutAssignee;
import com.google.gerrit.server.change.PutTopic;
import com.google.gerrit.server.change.Rebase;
import com.google.gerrit.server.change.Restore;
import com.google.gerrit.server.change.Revert;
import com.google.gerrit.server.change.Reviewers;
@ -99,6 +102,7 @@ class ChangeApiImpl implements ChangeApi {
private final CreateMergePatchSet updateByMerge;
private final Provider<SubmittedTogether> submittedTogether;
private final PublishDraftPatchSet.CurrentRevision publishDraftChange;
private final Rebase.CurrentRevision rebase;
private final DeleteChange deleteChange;
private final GetTopic getTopic;
private final PutTopic putTopic;
@ -133,6 +137,7 @@ class ChangeApiImpl implements ChangeApi {
CreateMergePatchSet updateByMerge,
Provider<SubmittedTogether> submittedTogether,
PublishDraftPatchSet.CurrentRevision publishDraftChange,
Rebase.CurrentRevision rebase,
DeleteChange deleteChange,
GetTopic getTopic,
PutTopic putTopic,
@ -165,6 +170,7 @@ class ChangeApiImpl implements ChangeApi {
this.updateByMerge = updateByMerge;
this.submittedTogether = submittedTogether;
this.publishDraftChange = publishDraftChange;
this.rebase = rebase;
this.deleteChange = deleteChange;
this.getTopic = getTopic;
this.putTopic = putTopic;
@ -325,6 +331,20 @@ class ChangeApiImpl implements ChangeApi {
}
}
@Override
public void rebase() throws RestApiException {
rebase(new RebaseInput());
}
@Override
public void rebase(RebaseInput in) throws RestApiException {
try {
rebase.apply(change, in);
} catch (EmailException | OrmException | UpdateException | RestApiException | IOException e) {
throw new RestApiException("Cannot rebase change", e);
}
}
@Override
public void delete() throws RestApiException {
try {

View File

@ -29,6 +29,7 @@ import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Change.Status;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.change.RebaseUtil.Base;
import com.google.gerrit.server.git.BatchUpdate;
import com.google.gerrit.server.git.GitRepositoryManager;
@ -204,18 +205,19 @@ public class Rebase
}
public static class CurrentRevision implements RestModifyView<ChangeResource, RebaseInput> {
private final PatchSetUtil psUtil;
private final Rebase rebase;
@Inject
CurrentRevision(Rebase rebase) {
CurrentRevision(PatchSetUtil psUtil, Rebase rebase) {
this.psUtil = psUtil;
this.rebase = rebase;
}
@Override
public ChangeInfo apply(ChangeResource rsrc, RebaseInput input)
throws EmailException, OrmException, UpdateException, RestApiException, IOException,
NoSuchChangeException {
PatchSet ps = rebase.dbProvider.get().patchSets().get(rsrc.getChange().currentPatchSetId());
throws EmailException, OrmException, UpdateException, RestApiException, IOException {
PatchSet ps = psUtil.current(rebase.dbProvider.get(), rsrc.getNotes());
if (ps == null) {
throw new ResourceConflictException("current revision is missing");
} else if (!rsrc.getControl().isPatchVisible(ps, rebase.dbProvider.get())) {