Don't direct link to a change found by operators
If operators were used in the change query (e.g. "is:starred") its
weird for the user if we jump to the only matching record. Instead
we want to display a table of results, with the one record showing
so its clear there was only one match.
However we still want to direct link to a change if the user
enters a legacy id number from the URL, a newer-style Change-Id,
or a commit SHA-1 and only one change matched.
Change-Id: I6784a1d277fa1c1a991ca338f7dfae8569c1667c
Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/SearchPanel.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/SearchPanel.java
index ff9da49..2d3d2e8 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/SearchPanel.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/SearchPanel.java
@@ -14,6 +14,7 @@
package com.google.gerrit.client;
+import com.google.gerrit.client.changes.QueryScreen;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.reviewdb.Change;
import com.google.gwt.event.dom.client.BlurEvent;
@@ -137,7 +138,7 @@
if (query.matches("^[1-9][0-9]*$")) {
Gerrit.display(PageLinks.toChange(Change.Id.parse(query)));
} else {
- Gerrit.display(PageLinks.toChangeQuery(query));
+ Gerrit.display(PageLinks.toChangeQuery(query), QueryScreen.forQuery(query));
}
}
}
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/QueryScreen.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/QueryScreen.java
index c600569..bcd2ed2 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/QueryScreen.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/QueryScreen.java
@@ -19,6 +19,7 @@
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.common.data.ChangeInfo;
import com.google.gerrit.common.data.SingleListChangeInfo;
+import com.google.gerrit.reviewdb.RevId;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwtorm.client.KeyUtil;
@@ -51,7 +52,7 @@
return new GerritCallback<SingleListChangeInfo>() {
public final void onSuccess(final SingleListChangeInfo result) {
if (isAttached()) {
- if (result.getChanges().size() == 1) {
+ if (result.getChanges().size() == 1 && isSingleQuery(query)) {
final ChangeInfo c = result.getChanges().get(0);
Gerrit.display(PageLinks.toChange(c), new ChangeScreen(c));
} else {
@@ -73,4 +74,26 @@
protected void loadNext() {
Util.LIST_SVC.allQueryNext(query, pos, pageSize, loadCallback());
}
+
+ private static boolean isSingleQuery(String query) {
+ if (query.matches("^[1-9][0-9]*$")) {
+ // Legacy numeric identifier.
+ //
+ return true;
+ }
+
+ if (query.matches("^[iI][0-9a-f]{4,}$")) {
+ // Newer style Change-Id.
+ //
+ return true;
+ }
+
+ if (query.matches("^([0-9a-fA-F]{4," + RevId.LEN + "})$")) {
+ // Commit SHA-1 of any change.
+ //
+ return true;
+ }
+
+ return false;
+ }
}