Merge "Add 'Parent $x' options to diff for merge commits"

This commit is contained in:
Dave Borowitz
2016-07-19 16:27:53 +00:00
committed by Gerrit Code Review
42 changed files with 942 additions and 183 deletions

View File

@@ -981,24 +981,25 @@ public class ChangeScreen extends Screen {
final List<NativeMap<JsArray<CommentInfo>>> comments,
final List<NativeMap<JsArray<CommentInfo>>> drafts) {
DiffApi.list(changeId.get(),
base != null ? base.name() : null,
rev.name(),
group.add(new AsyncCallback<NativeMap<FileInfo>>() {
@Override
public void onSuccess(NativeMap<FileInfo> m) {
files.set(
base != null ? new PatchSet.Id(changeId, base._number()) : null,
new PatchSet.Id(changeId, rev._number()),
style, reply, fileTableMode, edit != null);
files.setValue(m, myLastReply,
comments != null ? comments.get(0) : null,
drafts != null ? drafts.get(0) : null);
}
rev.name(),
base,
group.add(
new AsyncCallback<NativeMap<FileInfo>>() {
@Override
public void onSuccess(NativeMap<FileInfo> m) {
files.set(
base != null ? new PatchSet.Id(changeId, base._number()) : null,
new PatchSet.Id(changeId, rev._number()),
style, reply, fileTableMode, edit != null);
files.setValue(m, myLastReply,
comments != null ? comments.get(0) : null,
drafts != null ? drafts.get(0) : null);
}
@Override
public void onFailure(Throwable caught) {
}
}));
@Override
public void onFailure(Throwable caught) {
}
}));
}
private List<NativeMap<JsArray<CommentInfo>>> loadComments(
@@ -1117,7 +1118,6 @@ public class ChangeScreen extends Screen {
}
/**
*
* Resolve a revision or patch set id string to RevisionInfo.
* When this view is created from the changes table, revision
* is passed as a real revision.
@@ -1131,8 +1131,17 @@ public class ChangeScreen extends Screen {
*/
private RevisionInfo resolveRevisionOrPatchSetId(ChangeInfo info,
String revOrId, String defaultValue) {
int parentNum;
if (revOrId == null) {
revOrId = defaultValue;
} else if ((parentNum = toParentNum(revOrId)) > 0) {
CommitInfo commitInfo = info.revision(revision).commit();
if (commitInfo != null) {
JsArray<CommitInfo> parents = commitInfo.parents();
if (parents.length() >= parentNum) {
return RevisionInfo.forParent(-parentNum, parents.get(parentNum - 1));
}
}
} else if (!info.revisions().containsKey(revOrId)) {
JsArray<RevisionInfo> list = info.revisions().values();
for (int i = 0; i < list.length(); i++) {
@@ -1389,9 +1398,20 @@ public class ChangeScreen extends Screen {
RevisionInfo rev = info.revisions().get(revision);
JsArray<CommitInfo> parents = rev.commit().parents();
diffBase.addItem(
parents.length() > 1 ? Util.C.autoMerge() : Util.C.baseDiffItem(),
"");
if (parents.length() > 1) {
diffBase.addItem(Util.C.autoMerge(), "");
for (int i = 0; i < parents.length(); i++) {
int parentNum = i + 1;
diffBase.addItem(Util.M.diffBaseParent(parentNum),
String.valueOf(-parentNum));
}
int parentNum = toParentNum(base);
if (parentNum > 0) {
selectedIdx = list.length() + parentNum;
}
} else {
diffBase.addItem(Util.C.baseDiffItem(), "");
}
diffBase.setSelectedIndex(selectedIdx);
}
@@ -1443,4 +1463,22 @@ public class ChangeScreen extends Screen {
private static String normalize(String r) {
return r != null && !r.isEmpty() ? r : null;
}
/**
* @param parentToken
* @return 1-based parentNum if parentToken is a String which can be parsed as
* a negative integer i.e. "-1", "-2", etc. If parentToken cannot be
* parsed as a negative integer, return zero.
*/
private static int toParentNum(String parentToken) {
try {
int n = Integer.parseInt(parentToken);
if (n < 0) {
return -n;
}
return 0;
} catch (NumberFormatException e) {
return 0;
}
}
}

View File

@@ -36,6 +36,7 @@ import com.google.gerrit.client.rpc.RestApi;
import com.google.gerrit.client.ui.NavigationTable;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.extensions.client.Side;
import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.Patch.ChangeType;
import com.google.gerrit.reviewdb.client.PatchSet;
@@ -712,8 +713,8 @@ public class FileTable extends FlowPanel {
}
private void columnComments(SafeHtmlBuilder sb, FileInfo info) {
JsArray<CommentInfo> cList = get(info.path(), comments);
JsArray<CommentInfo> dList = get(info.path(), drafts);
JsArray<CommentInfo> cList = filterForParent(get(info.path(), comments));
JsArray<CommentInfo> dList = filterForParent(get(info.path(), drafts));
sb.openTd().setStyleName(R.css().draftColumn());
if (dList.length() > 0) {
@@ -747,6 +748,20 @@ public class FileTable extends FlowPanel {
sb.closeTd();
}
private JsArray<CommentInfo> filterForParent(JsArray<CommentInfo> list) {
JsArray<CommentInfo> result = JsArray.createArray().cast();
for (CommentInfo c : Natives.asList(list)) {
if (c.side() == Side.REVISION) {
result.push(c);
} else if (base == null && !c.hasParent()) {
result.push(c);
} else if (base != null && c.parent() == -base.get()) {
result.push(c);
}
}
return result;
}
private JsArray<CommentInfo> get(String p, NativeMap<JsArray<CommentInfo>> m) {
JsArray<CommentInfo> r = null;
if (m != null) {

View File

@@ -42,4 +42,6 @@ public interface ChangeMessages extends Messages {
String changeQueryPageTitle(String query);
String insertionsAndDeletions(int insertions, int deletions);
String diffBaseParent(int parentNum);
}

View File

@@ -23,3 +23,5 @@ changeQueryWindowTitle = {0}
changeQueryPageTitle = Search for {0}
insertionsAndDeletions = +{0}, -{1}
diffBaseParent = Parent {0}

View File

@@ -25,9 +25,15 @@ import java.sql.Timestamp;
public class CommentInfo extends JavaScriptObject {
public static CommentInfo create(String path, Side side,
int line, CommentRange range) {
return create(path, side, 0, line, range);
}
public static CommentInfo create(String path, Side side, int parent,
int line, CommentRange range) {
CommentInfo n = createObject().cast();
n.path(path);
n.side(side);
n.parent(parent);
if (range != null) {
n.line(range.endLine());
n.range(range);
@@ -41,6 +47,7 @@ public class CommentInfo extends JavaScriptObject {
CommentInfo n = createObject().cast();
n.path(r.path());
n.side(r.side());
n.parent(r.parent());
n.inReplyTo(r.id());
if (r.hasRange()) {
n.line(r.range().endLine());
@@ -55,6 +62,7 @@ public class CommentInfo extends JavaScriptObject {
CommentInfo n = createObject().cast();
n.path(s.path());
n.side(s.side());
n.parent(s.parent());
n.id(s.id());
n.inReplyTo(s.inReplyTo());
n.message(s.message());
@@ -78,6 +86,8 @@ public class CommentInfo extends JavaScriptObject {
sideRaw(side.toString());
}
private native void sideRaw(String s) /*-{ this.side = s }-*/;
public final native void parent(int n) /*-{ this.parent = n }-*/;
public final native boolean hasParent() /*-{ return this.hasOwnProperty('parent') }-*/;
public final native String path() /*-{ return this.path }-*/;
public final native String id() /*-{ return this.id }-*/;
@@ -91,6 +101,7 @@ public class CommentInfo extends JavaScriptObject {
: Side.REVISION;
}
private native String sideRaw() /*-{ return this.side }-*/;
public final native int parent() /*-{ return this.parent }-*/;
public final Timestamp updated() {
Timestamp r = updatedTimestamp();

View File

@@ -129,16 +129,29 @@ abstract class CommentManager {
}
Side getStoredSideFromDisplaySide(DisplaySide side) {
return side == DisplaySide.A && base == null ? Side.PARENT : Side.REVISION;
if (side == DisplaySide.A && (base == null || base.get() < 0)) {
return Side.PARENT;
}
return Side.REVISION;
}
int getParentNumFromDisplaySide(DisplaySide side) {
if (side == DisplaySide.A && base != null && base.get() < 0) {
return -base.get();
}
return 0;
}
PatchSet.Id getPatchSetIdFromSide(DisplaySide side) {
return side == DisplaySide.A && base != null ? base : revision;
if (side == DisplaySide.A && base != null && base.get() >= 0) {
return base;
}
return revision;
}
DisplaySide displaySide(CommentInfo info, DisplaySide forSide) {
if (info.side() == Side.PARENT) {
return base == null ? DisplaySide.A : null;
return (base == null || base.get() < 0) ? DisplaySide.A : null;
}
return forSide;
}
@@ -179,6 +192,7 @@ abstract class CommentManager {
addDraftBox(side, CommentInfo.create(
getPath(),
getStoredSideFromDisplaySide(side),
getParentNumFromDisplaySide(side),
line,
null)).setEdit(true);
}

View File

@@ -20,6 +20,7 @@ import com.google.gerrit.client.changes.CommentInfo;
import com.google.gerrit.client.rpc.CallbackGroup;
import com.google.gerrit.client.rpc.NativeMap;
import com.google.gerrit.client.rpc.Natives;
import com.google.gerrit.extensions.client.Side;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.user.client.rpc.AsyncCallback;
@@ -46,13 +47,13 @@ class CommentsCollections {
}
void load(CallbackGroup group) {
if (base != null) {
if (base != null && base.get() > 0) {
CommentApi.comments(base, group.add(publishedBase()));
}
CommentApi.comments(revision, group.add(publishedRevision()));
if (Gerrit.isSignedIn()) {
if (base != null) {
if (base != null && base.get() > 0) {
CommentApi.drafts(base, group.add(draftsBase()));
}
CommentApi.drafts(revision, group.add(draftsRevision()));
@@ -60,7 +61,7 @@ class CommentsCollections {
}
boolean hasCommentForPath(String filePath) {
if (base != null) {
if (base != null && base.get() > 0) {
JsArray<CommentInfo> forBase = publishedBaseAll.get(filePath);
if (forBase != null && forBase.length() > 0) {
return true;
@@ -91,6 +92,9 @@ class CommentsCollections {
return new AsyncCallback<NativeMap<JsArray<CommentInfo>>>() {
@Override
public void onSuccess(NativeMap<JsArray<CommentInfo>> result) {
for (String k : result.keySet()) {
result.put(k, filterForParent(result.get(k)));
}
publishedRevisionAll = result;
publishedRevision = sort(result.get(path));
}
@@ -101,6 +105,20 @@ class CommentsCollections {
};
}
private JsArray<CommentInfo> filterForParent(JsArray<CommentInfo> list) {
JsArray<CommentInfo> result = JsArray.createArray().cast();
for (CommentInfo c : Natives.asList(list)) {
if (c.side() == Side.REVISION) {
result.push(c);
} else if (base == null && !c.hasParent()) {
result.push(c);
} else if (base != null && c.parent() == -base.get()) {
result.push(c);
}
}
return result;
}
private AsyncCallback<NativeMap<JsArray<CommentInfo>>> draftsBase() {
return new AsyncCallback<NativeMap<JsArray<CommentInfo>>>() {
@Override
@@ -118,6 +136,9 @@ class CommentsCollections {
return new AsyncCallback<NativeMap<JsArray<CommentInfo>>>() {
@Override
public void onSuccess(NativeMap<JsArray<CommentInfo>> result) {
for (String k : result.keySet()) {
result.put(k, filterForParent(result.get(k)));
}
draftsRevision = sort(result.get(path));
}

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.client.diff;
import static com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace.IGNORE_ALL;
import com.google.gerrit.client.changes.ChangeApi;
import com.google.gerrit.client.info.ChangeInfo.RevisionInfo;
import com.google.gerrit.client.info.FileInfo;
import com.google.gerrit.client.rpc.NativeMap;
import com.google.gerrit.client.rpc.RestApi;
@@ -25,11 +26,15 @@ import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gwt.user.client.rpc.AsyncCallback;
public class DiffApi {
public static void list(int id, String base, String revision,
public static void list(int id, String revision, RevisionInfo base,
AsyncCallback<NativeMap<FileInfo>> cb) {
RestApi api = ChangeApi.revision(id, revision).view("files");
if (base != null) {
api.addParameter("base", base);
if (base._number() < 0) {
api.addParameter("parent", -base._number());
} else {
api.addParameter("base", base.name());
}
}
api.get(NativeMap.copyKeysIntoChildren("path", cb));
}
@@ -38,7 +43,11 @@ public class DiffApi {
AsyncCallback<NativeMap<FileInfo>> cb) {
RestApi api = ChangeApi.revision(id).view("files");
if (base != null) {
api.addParameter("base", base.get());
if (base.get() < 0) {
api.addParameter("parent", -base.get());
} else {
api.addParameter("base", base.get());
}
}
api.get(NativeMap.copyKeysIntoChildren("path", cb));
}
@@ -57,7 +66,11 @@ public class DiffApi {
public DiffApi base(PatchSet.Id id) {
if (id != null) {
call.addParameter("base", id.get());
if (id.get() < 0) {
call.addParameter("parent", -id.get());
} else {
call.addParameter("base", id.get());
}
}
return this;
}

View File

@@ -27,6 +27,7 @@ import com.google.gerrit.client.changes.ChangeList;
import com.google.gerrit.client.diff.DiffInfo.FileMeta;
import com.google.gerrit.client.diff.LineMapper.LineOnOtherInfo;
import com.google.gerrit.client.info.ChangeInfo;
import com.google.gerrit.client.info.ChangeInfo.CommitInfo;
import com.google.gerrit.client.info.ChangeInfo.EditInfo;
import com.google.gerrit.client.info.ChangeInfo.RevisionInfo;
import com.google.gerrit.client.info.FileInfo;
@@ -116,6 +117,7 @@ abstract class DiffScreen extends Screen {
private List<HandlerRegistration> handlers;
private PreferencesAction prefsAction;
private int reloadVersionId;
private int parents;
@UiField(provided = true)
Header header;
@@ -213,6 +215,8 @@ abstract class DiffScreen extends Screen {
new CommentsCollections(base, revision, path);
comments.load(group2);
countParents(group2);
RestApi call = ChangeApi.detail(changeId.get());
ChangeList.addOptions(call, EnumSet.of(
ListChangesOption.ALL_REVISIONS));
@@ -231,7 +235,7 @@ abstract class DiffScreen extends Screen {
revision.get() == info.revision(currentRevision)._number();
JsArray<RevisionInfo> list = info.revisions().values();
RevisionInfo.sortRevisionInfoByNumber(list);
getDiffTable().set(prefs, list, diff, edit != null, current,
getDiffTable().set(prefs, list, parents, diff, edit != null, current,
changeStatus.isOpen(), diff.binary());
header.setChangeInfo(info);
}
@@ -245,6 +249,22 @@ abstract class DiffScreen extends Screen {
getScreenLoadCallback(comments)));
}
private void countParents(CallbackGroup cbg) {
ChangeApi.revision(changeId.get(), revision.getId())
.view("commit")
.get(cbg.add(new AsyncCallback<CommitInfo>() {
@Override
public void onSuccess(CommitInfo info) {
parents = info.parents().length();
}
@Override
public void onFailure(Throwable caught) {
parents = 0;
}
}));
}
@Override
public void onShowView() {
super.onShowView();

View File

@@ -108,12 +108,12 @@ abstract class DiffTable extends Composite {
patchSetSelectBoxB.setUpBlame(cm, false, rev, path);
}
void set(DiffPreferences prefs, JsArray<RevisionInfo> list, DiffInfo info,
void set(DiffPreferences prefs, JsArray<RevisionInfo> list, int parents, DiffInfo info,
boolean editExists, boolean current, boolean open, boolean binary) {
this.changeType = info.changeType();
patchSetSelectBoxA.setUpPatchSetNav(list, info.metaA(), editExists,
patchSetSelectBoxA.setUpPatchSetNav(list, parents, info.metaA(), editExists,
current, open, binary);
patchSetSelectBoxB.setUpPatchSetNav(list, info.metaB(), editExists,
patchSetSelectBoxB.setUpPatchSetNav(list, parents, info.metaB(), editExists,
current, open, binary);
JsArrayString hdr = info.diffHeader();

View File

@@ -18,6 +18,7 @@ import com.google.gerrit.client.Dispatcher;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.blame.BlameInfo;
import com.google.gerrit.client.changes.ChangeApi;
import com.google.gerrit.client.changes.Util;
import com.google.gerrit.client.info.ChangeInfo.RevisionInfo;
import com.google.gerrit.client.info.WebLinkInfo;
import com.google.gerrit.client.patches.PatchUtil;
@@ -87,13 +88,29 @@ class PatchSetSelectBox extends Composite {
this.path = path;
}
void setUpPatchSetNav(JsArray<RevisionInfo> list, DiffInfo.FileMeta meta,
void setUpPatchSetNav(JsArray<RevisionInfo> list, int parents, DiffInfo.FileMeta meta,
boolean editExists, boolean current, boolean open, boolean binary) {
InlineHyperlink baseLink = null;
InlineHyperlink selectedLink = null;
if (sideA) {
baseLink = createLink(PatchUtil.C.patchBase(), null);
linkPanel.add(baseLink);
if (parents <= 1) {
InlineHyperlink link = createLink(PatchUtil.C.patchBase(), null);
linkPanel.add(link);
selectedLink = link;
} else {
for (int i = parents; i > 0; i--) {
PatchSet.Id id = new PatchSet.Id(changeId, -i);
InlineHyperlink link = createLink(Util.M.diffBaseParent(i), id);
linkPanel.add(link);
if (revision != null && id.equals(revision)) {
selectedLink = link;
}
}
InlineHyperlink link = createLink(Util.C.autoMerge(), null);
linkPanel.add(link);
if (selectedLink == null) {
selectedLink = link;
}
}
}
for (int i = 0; i < list.length(); i++) {
RevisionInfo r = list.get(i);
@@ -106,8 +123,6 @@ class PatchSetSelectBox extends Composite {
}
if (selectedLink != null) {
selectedLink.setStyleName(style.selected());
} else if (sideA) {
baseLink.setStyleName(style.selected());
}
if (meta == null) {

View File

@@ -84,6 +84,7 @@ class SideBySideCommentManager extends CommentManager {
addDraftBox(cm.side(), CommentInfo.create(
getPath(),
getStoredSideFromDisplaySide(cm.side()),
getParentNumFromDisplaySide(cm.side()),
line,
CommentRange.create(fromTo))).setEdit(true);
cm.setCursor(fromTo.to());