ChangeScreen2: Handle missing current revision

If for a change the current revision is not returned ChangeScreen2
fails to load and the "Working ..." label is displayed forever.

If the current revision is missing, diplay the last revision that was
returned. If no revision was returned display an error.

The current revision is missing for changes where the current revision
is a draft patch set that is not visible to the calling user.

There are also corrupt changes that return no revision at all.

Change-Id: I9a063b4dbc6ad7ae5b67d9a022b2141ce66ead32
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2013-11-23 07:26:28 +01:00
parent ca80447775
commit 693fdd253f
3 changed files with 22 additions and 1 deletions

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.client.change;
import com.google.gerrit.client.ErrorDialog;
import com.google.gerrit.client.FormatUtil;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.actions.ActionInfo;
@@ -671,7 +672,25 @@ public class ChangeScreen2 extends Screen {
}
}
}
return info.revision(revision);
RevisionInfo rev = revision != null ? info.revision(revision) : null;
if (rev != null) {
return rev;
}
// the revision is not visible to the calling user (maybe it is a draft?)
// or the change is corrupt, take the last revision that was returned,
// if no revision was returned display an error
JsArray<RevisionInfo> revisions = info.revisions().values();
if (revisions.length() > 0) {
RevisionInfo.sortRevisionInfoByNumber(revisions);
rev = revisions.get(revisions.length() - 1);
revision = rev.name();
return rev;
} else {
new ErrorDialog(
Resources.M.changeWithNoRevisions(info.legacy_id().get())).center();
throw new IllegalStateException("no revision, cannot proceed");
}
}
private void renderChangeInfo(ChangeInfo info) {

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.client.change;
public interface Messages extends com.google.gwt.i18n.client.Messages {
String changeWithNoRevisions(int changeId);
String relatedChanges(int count);
String relatedChanges(String count);
String conflictingChanges(int count);

View File

@@ -1,3 +1,4 @@
changeWithNoRevisions = Cannot display change {0} because it has no revisions.
relatedChanges = Related Changes ({0})
conflictingChanges = Conflicts With ({0})
cherryPicks = Cherry-Picks ({0})