Fix client error when current patch set is not visible to user

If the latest patch set of a change is a draft that is not visible to
the logged in user, clicking on the side by side diff link causes a
javascript error on the client.

Root cause is that the current_revision() method returns null in this
case.

Bug: Issue 3477
Change-Id: I0cd771ae8b42489f6d5bf374a6810b5812fcaf31
This commit is contained in:
David Pursehouse
2015-08-03 19:25:58 +09:00
parent 09670a3e17
commit 40045c4cb7
3 changed files with 9 additions and 7 deletions

View File

@@ -150,12 +150,12 @@ class DiffTable extends Composite {
}
void set(DiffPreferences prefs, JsArray<RevisionInfo> list, DiffInfo info,
boolean editExists, int currentPatchSet, boolean open, boolean binary) {
boolean editExists, boolean current, boolean open, boolean binary) {
this.changeType = info.change_type();
patchSetSelectBoxA.setUpPatchSetNav(list, info.meta_a(), editExists,
currentPatchSet, open, binary);
current, open, binary);
patchSetSelectBoxB.setUpPatchSetNav(list, info.meta_b(), editExists,
currentPatchSet, open, binary);
current, open, binary);
JsArrayString hdr = info.diff_header();
if (hdr != null) {

View File

@@ -82,7 +82,7 @@ class PatchSetSelectBox extends Composite {
}
void setUpPatchSetNav(JsArray<RevisionInfo> list, DiffInfo.FileMeta meta,
boolean editExists, int currentPatchSet, boolean open, boolean binary) {
boolean editExists, boolean current, boolean open, boolean binary) {
InlineHyperlink baseLink = null;
InlineHyperlink selectedLink = null;
if (sideA) {
@@ -112,7 +112,7 @@ class PatchSetSelectBox extends Composite {
}
if (!binary && open && idActive != null && Gerrit.isSignedIn()) {
if ((editExists && idActive.get() == 0)
|| (!editExists && idActive.get() == currentPatchSet)) {
|| (!editExists && current)) {
linkPanel.add(createEditIcon());
}
}

View File

@@ -242,10 +242,12 @@ public class SideBySide extends Screen {
info.set_edit(edit);
info.revisions().put(edit.name(), RevisionInfo.fromEdit(edit));
}
int currentPatchSet = info.revision(info.current_revision())._number();
String currentRevision = info.current_revision();
boolean current = currentRevision != null &&
revision.get() == info.revision(currentRevision)._number();
JsArray<RevisionInfo> list = info.revisions().values();
RevisionInfo.sortRevisionInfoByNumber(list);
diffTable.set(prefs, list, diff, edit != null, currentPatchSet,
diffTable.set(prefs, list, diff, edit != null, current,
changeStatus.isOpen(), diff.binary());
header.setChangeInfo(info);
}