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:
parent
e32ed73ac2
commit
cfc9e6da54
@ -88,6 +88,7 @@ import com.google.gerrit.extensions.restapi.BadRequestException;
|
|||||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
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.extensions.restapi.UnprocessableEntityException;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||||
@ -328,8 +329,22 @@ public class ChangeIT extends AbstractDaemonTest {
|
|||||||
gApi.changes().id(r.getChangeId()).revert();
|
gApi.changes().id(r.getChangeId()).revert();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
private interface Rebase {
|
||||||
|
void call(String id) throws RestApiException;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@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
|
// Create two changes both with the same parent
|
||||||
PushOneCommit.Result r = createChange();
|
PushOneCommit.Result r = createChange();
|
||||||
testRepo.reset("HEAD~1");
|
testRepo.reset("HEAD~1");
|
||||||
@ -342,7 +357,7 @@ public class ChangeIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
String changeId = r2.getChangeId();
|
String changeId = r2.getChangeId();
|
||||||
// Rebase the second change
|
// Rebase the second change
|
||||||
gApi.changes().id(changeId).current().rebase();
|
rebase.call(changeId);
|
||||||
|
|
||||||
// Second change should have 2 patch sets
|
// Second change should have 2 patch sets
|
||||||
ChangeInfo c2 = gApi.changes().id(changeId).get();
|
ChangeInfo c2 = gApi.changes().id(changeId).get();
|
||||||
|
@ -114,6 +114,12 @@ public interface ChangeApi {
|
|||||||
/** Publishes a draft change. */
|
/** Publishes a draft change. */
|
||||||
void publish() throws RestApiException;
|
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. */
|
/** Deletes a change. */
|
||||||
void delete() throws RestApiException;
|
void delete() throws RestApiException;
|
||||||
|
|
||||||
@ -315,6 +321,16 @@ public interface ChangeApi {
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rebase() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rebase(RebaseInput in) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete() {
|
public void delete() {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.api.changes;
|
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.AbandonInput;
|
||||||
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
|
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
|
||||||
import com.google.gerrit.extensions.api.changes.AssigneeInput;
|
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.HashtagsInput;
|
||||||
import com.google.gerrit.extensions.api.changes.IncludedInInfo;
|
import com.google.gerrit.extensions.api.changes.IncludedInInfo;
|
||||||
import com.google.gerrit.extensions.api.changes.MoveInput;
|
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.RestoreInput;
|
||||||
import com.google.gerrit.extensions.api.changes.RevertInput;
|
import com.google.gerrit.extensions.api.changes.RevertInput;
|
||||||
import com.google.gerrit.extensions.api.changes.ReviewerApi;
|
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.PublishDraftPatchSet;
|
||||||
import com.google.gerrit.server.change.PutAssignee;
|
import com.google.gerrit.server.change.PutAssignee;
|
||||||
import com.google.gerrit.server.change.PutTopic;
|
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.Restore;
|
||||||
import com.google.gerrit.server.change.Revert;
|
import com.google.gerrit.server.change.Revert;
|
||||||
import com.google.gerrit.server.change.Reviewers;
|
import com.google.gerrit.server.change.Reviewers;
|
||||||
@ -99,6 +102,7 @@ class ChangeApiImpl implements ChangeApi {
|
|||||||
private final CreateMergePatchSet updateByMerge;
|
private final CreateMergePatchSet updateByMerge;
|
||||||
private final Provider<SubmittedTogether> submittedTogether;
|
private final Provider<SubmittedTogether> submittedTogether;
|
||||||
private final PublishDraftPatchSet.CurrentRevision publishDraftChange;
|
private final PublishDraftPatchSet.CurrentRevision publishDraftChange;
|
||||||
|
private final Rebase.CurrentRevision rebase;
|
||||||
private final DeleteChange deleteChange;
|
private final DeleteChange deleteChange;
|
||||||
private final GetTopic getTopic;
|
private final GetTopic getTopic;
|
||||||
private final PutTopic putTopic;
|
private final PutTopic putTopic;
|
||||||
@ -133,6 +137,7 @@ class ChangeApiImpl implements ChangeApi {
|
|||||||
CreateMergePatchSet updateByMerge,
|
CreateMergePatchSet updateByMerge,
|
||||||
Provider<SubmittedTogether> submittedTogether,
|
Provider<SubmittedTogether> submittedTogether,
|
||||||
PublishDraftPatchSet.CurrentRevision publishDraftChange,
|
PublishDraftPatchSet.CurrentRevision publishDraftChange,
|
||||||
|
Rebase.CurrentRevision rebase,
|
||||||
DeleteChange deleteChange,
|
DeleteChange deleteChange,
|
||||||
GetTopic getTopic,
|
GetTopic getTopic,
|
||||||
PutTopic putTopic,
|
PutTopic putTopic,
|
||||||
@ -165,6 +170,7 @@ class ChangeApiImpl implements ChangeApi {
|
|||||||
this.updateByMerge = updateByMerge;
|
this.updateByMerge = updateByMerge;
|
||||||
this.submittedTogether = submittedTogether;
|
this.submittedTogether = submittedTogether;
|
||||||
this.publishDraftChange = publishDraftChange;
|
this.publishDraftChange = publishDraftChange;
|
||||||
|
this.rebase = rebase;
|
||||||
this.deleteChange = deleteChange;
|
this.deleteChange = deleteChange;
|
||||||
this.getTopic = getTopic;
|
this.getTopic = getTopic;
|
||||||
this.putTopic = putTopic;
|
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
|
@Override
|
||||||
public void delete() throws RestApiException {
|
public void delete() throws RestApiException {
|
||||||
try {
|
try {
|
||||||
|
@ -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.Change.Status;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
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.change.RebaseUtil.Base;
|
||||||
import com.google.gerrit.server.git.BatchUpdate;
|
import com.google.gerrit.server.git.BatchUpdate;
|
||||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||||
@ -204,18 +205,19 @@ public class Rebase
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class CurrentRevision implements RestModifyView<ChangeResource, RebaseInput> {
|
public static class CurrentRevision implements RestModifyView<ChangeResource, RebaseInput> {
|
||||||
|
private final PatchSetUtil psUtil;
|
||||||
private final Rebase rebase;
|
private final Rebase rebase;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
CurrentRevision(Rebase rebase) {
|
CurrentRevision(PatchSetUtil psUtil, Rebase rebase) {
|
||||||
|
this.psUtil = psUtil;
|
||||||
this.rebase = rebase;
|
this.rebase = rebase;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChangeInfo apply(ChangeResource rsrc, RebaseInput input)
|
public ChangeInfo apply(ChangeResource rsrc, RebaseInput input)
|
||||||
throws EmailException, OrmException, UpdateException, RestApiException, IOException,
|
throws EmailException, OrmException, UpdateException, RestApiException, IOException {
|
||||||
NoSuchChangeException {
|
PatchSet ps = psUtil.current(rebase.dbProvider.get(), rsrc.getNotes());
|
||||||
PatchSet ps = rebase.dbProvider.get().patchSets().get(rsrc.getChange().currentPatchSetId());
|
|
||||||
if (ps == null) {
|
if (ps == null) {
|
||||||
throw new ResourceConflictException("current revision is missing");
|
throw new ResourceConflictException("current revision is missing");
|
||||||
} else if (!rsrc.getControl().isPatchVisible(ps, rebase.dbProvider.get())) {
|
} else if (!rsrc.getControl().isPatchVisible(ps, rebase.dbProvider.get())) {
|
||||||
|
Loading…
Reference in New Issue
Block a user