InlineEdit: Implement SBS2 integration
SBS2 now includes "edit" in the list of patch sets at the top, and is capable of diffing an edit against other patch sets. Change-Id: I18c185f0209c9d9c8243a44d16030ed9d9c4b85a
This commit is contained in:
@@ -148,7 +148,7 @@ public class Dispatcher {
|
||||
if (diffBase != null) {
|
||||
p.append(diffBase.get()).append("..");
|
||||
}
|
||||
p.append(revision.get()).append("/").append(KeyUtil.encode(fileName));
|
||||
p.append(revision.getId()).append("/").append(KeyUtil.encode(fileName));
|
||||
if (type != null && !type.isEmpty()) {
|
||||
p.append(",").append(type);
|
||||
}
|
||||
@@ -553,16 +553,14 @@ public class Dispatcher {
|
||||
rest = "";
|
||||
}
|
||||
|
||||
PatchSet.Id base;
|
||||
PatchSet.Id base = null;
|
||||
PatchSet.Id ps;
|
||||
int dotdot = psIdStr.indexOf("..");
|
||||
if (1 <= dotdot) {
|
||||
base = new PatchSet.Id(id, Integer.parseInt(psIdStr.substring(0, dotdot)));
|
||||
ps = new PatchSet.Id(id, Integer.parseInt(psIdStr.substring(dotdot + 2)));
|
||||
} else {
|
||||
base = null;
|
||||
ps = new PatchSet.Id(id, Integer.parseInt(psIdStr));
|
||||
psIdStr = psIdStr.substring(dotdot + 2);
|
||||
}
|
||||
ps = toPsId(id, psIdStr);
|
||||
|
||||
if (!rest.isEmpty()) {
|
||||
DisplaySide side = DisplaySide.B;
|
||||
@@ -597,6 +595,12 @@ public class Dispatcher {
|
||||
}
|
||||
}
|
||||
|
||||
private static PatchSet.Id toPsId(Change.Id id, String psIdStr) {
|
||||
return new PatchSet.Id(id, psIdStr.equals("edit")
|
||||
? 0
|
||||
: Integer.parseInt(psIdStr));
|
||||
}
|
||||
|
||||
private static void extension(final String token) {
|
||||
ExtensionScreen view = new ExtensionScreen(skip(token));
|
||||
if (view.isFound()) {
|
||||
|
||||
@@ -210,7 +210,7 @@ class PatchSetsBox extends Composite {
|
||||
.closeSpan()
|
||||
.append(' ');
|
||||
}
|
||||
sb.append(r._number());
|
||||
sb.append(r.id());
|
||||
sb.closeTd();
|
||||
|
||||
sb.openTd()
|
||||
|
||||
@@ -101,8 +101,7 @@ class Header extends Composite {
|
||||
SafeHtml.setInnerHTML(filePath, formatPath(path, null, null));
|
||||
up.setTargetHistoryToken(PageLinks.toChange(
|
||||
patchSetId.getParentKey(),
|
||||
base != null ? String.valueOf(base.get()) : null,
|
||||
String.valueOf(patchSetId.get())));
|
||||
base != null ? base.getId() : null, patchSetId.getId()));
|
||||
}
|
||||
|
||||
private static SafeHtml formatPath(String path, String project, String commit) {
|
||||
@@ -191,7 +190,7 @@ class Header extends Composite {
|
||||
GitwebLink gw = Gerrit.getGitwebLink();
|
||||
if (gw != null) {
|
||||
for (RevisionInfo rev : Natives.asList(info.revisions().values())) {
|
||||
if (rev._number() == patchSetId.get()) {
|
||||
if (patchSetId.getId().equals(rev.id())) {
|
||||
String c = rev.name();
|
||||
SafeHtml.setInnerHTML(filePath, formatPath(path, info.project(), c));
|
||||
SafeHtml.setInnerHTML(project, new SafeHtmlBuilder()
|
||||
|
||||
@@ -85,10 +85,10 @@ class PatchSetSelectBox2 extends Composite {
|
||||
}
|
||||
for (int i = 0; i < list.length(); i++) {
|
||||
RevisionInfo r = list.get(i);
|
||||
InlineHyperlink link = createLink(
|
||||
String.valueOf(r._number()), new PatchSet.Id(changeId, r._number()));
|
||||
InlineHyperlink link = createLink(r.id(),
|
||||
new PatchSet.Id(changeId, r._number()));
|
||||
linkPanel.add(link);
|
||||
if (revision != null && r._number() == revision.get()) {
|
||||
if (revision != null && r.id().equals(revision.getId())) {
|
||||
selectedLink = link;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.google.gerrit.client.account.DiffPreferences;
|
||||
import com.google.gerrit.client.change.ChangeScreen2;
|
||||
import com.google.gerrit.client.changes.ChangeApi;
|
||||
import com.google.gerrit.client.changes.ChangeInfo;
|
||||
import com.google.gerrit.client.changes.ChangeInfo.EditInfo;
|
||||
import com.google.gerrit.client.changes.ChangeInfo.RevisionInfo;
|
||||
import com.google.gerrit.client.changes.ChangeList;
|
||||
import com.google.gerrit.client.diff.DiffInfo.FileMeta;
|
||||
@@ -119,6 +120,7 @@ public class SideBySide2 extends Screen {
|
||||
private ScrollSynchronizer scrollSynchronizer;
|
||||
private DiffInfo diff;
|
||||
private FileSize fileSize;
|
||||
private EditInfo edit;
|
||||
private ChunkManager chunkManager;
|
||||
private CommentManager commentManager;
|
||||
private SkipManager skipManager;
|
||||
@@ -190,6 +192,16 @@ public class SideBySide2 extends Screen {
|
||||
}
|
||||
}));
|
||||
|
||||
if (Gerrit.isSignedIn()) {
|
||||
ChangeApi.edit(changeId.get(), group.add(
|
||||
new GerritCallback<EditInfo>() {
|
||||
@Override
|
||||
public void onSuccess(EditInfo result) {
|
||||
edit = result;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
final CommentsCollections comments = new CommentsCollections();
|
||||
comments.load(base, revision, path, group);
|
||||
|
||||
@@ -200,6 +212,11 @@ public class SideBySide2 extends Screen {
|
||||
@Override
|
||||
public void onSuccess(ChangeInfo info) {
|
||||
info.revisions().copyKeysIntoChildren("name");
|
||||
if (edit != null) {
|
||||
edit.set_name(edit.commit().commit());
|
||||
info.set_edit(edit);
|
||||
info.revisions().put(edit.name(), RevisionInfo.fromEdit(edit));
|
||||
}
|
||||
JsArray<RevisionInfo> list = info.revisions().values();
|
||||
RevisionInfo.sortRevisionInfoByNumber(list);
|
||||
diffTable.set(prefs, list, diff);
|
||||
@@ -798,8 +815,8 @@ public class SideBySide2 extends Screen {
|
||||
group.addListener(new GerritCallback<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
String b = base != null ? String.valueOf(base.get()) : null;
|
||||
String rev = String.valueOf(revision.get());
|
||||
String b = base != null ? base.getId() : null;
|
||||
String rev = revision.getId();
|
||||
Gerrit.display(
|
||||
PageLinks.toChange(changeId, b, rev),
|
||||
new ChangeScreen2(changeId, b, rev, openReplyBox));
|
||||
|
||||
@@ -33,6 +33,6 @@ class UpToChangeCommand2 extends KeyCommand {
|
||||
public void onKeyPress(final KeyPressEvent event) {
|
||||
Gerrit.display(PageLinks.toChange(
|
||||
revision.getParentKey(),
|
||||
String.valueOf(revision.get())));
|
||||
revision.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.common.data.PatchScript;
|
||||
import com.google.gerrit.common.data.PatchScript.DisplayMethod;
|
||||
import com.google.gerrit.common.data.PatchScript.FileMode;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.CacheControl;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
@@ -36,6 +37,7 @@ import com.google.gerrit.reviewdb.client.Patch.ChangeType;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.server.git.LargeObjectException;
|
||||
import com.google.gerrit.server.patch.PatchScriptFactory;
|
||||
import com.google.gerrit.server.project.InvalidChangeOperationException;
|
||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gerrit.server.project.ProjectState;
|
||||
@@ -53,6 +55,7 @@ import org.kohsuke.args4j.spi.OptionHandler;
|
||||
import org.kohsuke.args4j.spi.Parameters;
|
||||
import org.kohsuke.args4j.spi.Setter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -84,7 +87,8 @@ public class GetDiff implements RestReadView<FileResource> {
|
||||
|
||||
@Override
|
||||
public Response<Result> apply(FileResource resource)
|
||||
throws ResourceConflictException, ResourceNotFoundException, OrmException {
|
||||
throws ResourceConflictException, ResourceNotFoundException,
|
||||
OrmException, AuthException, InvalidChangeOperationException, IOException {
|
||||
PatchSet.Id basePatchSet = null;
|
||||
if (base != null) {
|
||||
RevisionResource baseResource = revisions.parse(
|
||||
|
||||
@@ -14,9 +14,11 @@
|
||||
|
||||
package com.google.gerrit.server.patch;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.common.data.CommentDetail;
|
||||
import com.google.gerrit.common.data.PatchScript;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
|
||||
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
|
||||
@@ -31,10 +33,13 @@ import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.PatchLineCommentsUtil;
|
||||
import com.google.gerrit.server.account.AccountInfoCacheFactory;
|
||||
import com.google.gerrit.server.edit.ChangeEdit;
|
||||
import com.google.gerrit.server.edit.ChangeEditUtil;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.LargeObjectException;
|
||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.InvalidChangeOperationException;
|
||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
@@ -80,6 +85,7 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
||||
private final PatchSet.Id psa;
|
||||
private final PatchSet.Id psb;
|
||||
private final AccountDiffPreference diffPrefs;
|
||||
private final ChangeEditUtil editReader;
|
||||
|
||||
private final Change.Id changeId;
|
||||
private boolean loadHistory = true;
|
||||
@@ -99,6 +105,7 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
||||
final PatchListCache patchListCache, final ReviewDb db,
|
||||
final AccountInfoCacheFactory.Factory aicFactory,
|
||||
PatchLineCommentsUtil plcUtil,
|
||||
ChangeEditUtil editReader,
|
||||
@Assisted ChangeControl control,
|
||||
@Assisted final String fileName,
|
||||
@Assisted("patchSetA") @Nullable final PatchSet.Id patchSetA,
|
||||
@@ -111,6 +118,7 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
||||
this.control = control;
|
||||
this.aicFactory = aicFactory;
|
||||
this.plcUtil = plcUtil;
|
||||
this.editReader = editReader;
|
||||
|
||||
this.fileName = fileName;
|
||||
this.psa = patchSetA;
|
||||
@@ -130,7 +138,8 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
||||
|
||||
@Override
|
||||
public PatchScript call() throws OrmException, NoSuchChangeException,
|
||||
LargeObjectException {
|
||||
LargeObjectException, AuthException,
|
||||
InvalidChangeOperationException, IOException {
|
||||
validatePatchSetId(psa);
|
||||
validatePatchSetId(psb);
|
||||
|
||||
@@ -197,12 +206,16 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
||||
}
|
||||
|
||||
private ObjectId toObjectId(final ReviewDb db, final PatchSet.Id psId)
|
||||
throws OrmException, NoSuchChangeException {
|
||||
throws OrmException, NoSuchChangeException, AuthException,
|
||||
InvalidChangeOperationException, NoSuchChangeException, IOException {
|
||||
if (!changeId.equals(psId.getParentKey())) {
|
||||
throw new NoSuchChangeException(changeId);
|
||||
}
|
||||
|
||||
final PatchSet ps = db.patchSets().get(psId);
|
||||
if (psId.get() == 0) {
|
||||
return getEditRev();
|
||||
}
|
||||
PatchSet ps = db.patchSets().get(psId);
|
||||
if (ps == null || ps.getRevision() == null
|
||||
|| ps.getRevision().get() == null) {
|
||||
throw new NoSuchChangeException(changeId);
|
||||
@@ -216,6 +229,15 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
||||
}
|
||||
}
|
||||
|
||||
private ObjectId getEditRev() throws AuthException,
|
||||
NoSuchChangeException, IOException, InvalidChangeOperationException {
|
||||
Optional<ChangeEdit> edit = editReader.byChange(change);
|
||||
if (edit.isPresent()) {
|
||||
return edit.get().getRef().getObjectId();
|
||||
}
|
||||
throw new NoSuchChangeException(change.getId());
|
||||
}
|
||||
|
||||
private void validatePatchSetId(final PatchSet.Id psId)
|
||||
throws NoSuchChangeException {
|
||||
if (psId == null) { // OK, means use base;
|
||||
|
||||
Reference in New Issue
Block a user