Avoid change find mismatch

In servers with a big number of changes the legacy-id can have 7 or more
digits and the sha-1 regex will match and return change not found if there
is not a commit in the project starting with the exact same sequence of
digits, which is a remote possibility.

Check first for legacy-id so sequences of digits are taken as legacy-id.

Change-Id: Ibb87b22f2e8efeb025031fa61ebd27d8b5d90156
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/ChangeFinder.java b/gerrit-server/src/main/java/com/google/gerrit/server/ChangeFinder.java
index b6222a4..33203ff 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/ChangeFinder.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/ChangeFinder.java
@@ -54,11 +54,6 @@
     // to force rereading in case the index is stale.
     InternalChangeQuery query = queryProvider.get().noFields();
 
-    //Try commit hash
-    if (id.matches("^([0-9a-fA-F]{" + RevId.ABBREV_LEN + "," + RevId.LEN + "})$")) {
-      return asChangeControls(query.byCommit(id), user);
-    }
-
     // Try legacy id
     if (!id.isEmpty() && id.charAt(0) != '0') {
       Integer n = Ints.tryParse(id);
@@ -67,6 +62,11 @@
       }
     }
 
+    // Try commit hash
+    if (id.matches("^([0-9a-fA-F]{" + RevId.ABBREV_LEN + "," + RevId.LEN + "})$")) {
+      return asChangeControls(query.byCommit(id), user);
+    }
+
     // Try isolated changeId
     if (!id.contains("~")) {
       return asChangeControls(query.byKeyPrefix(id), user);