rust-revset: add separate match logic for shortcuts
authorRaphaël Gomès <rgomes@octobus.net>
Sat, 11 Sep 2021 00:05:08 +0200
changeset 48078 ddde80830aea
parent 48077 ba773bd99203
child 48079 3da7bf75fdb2
rust-revset: add separate match logic for shortcuts The next change will add a shortcut for the `.` revision. One day we might start matching `tip` and others, so this is an easy refactor. Differential Revision: https://phab.mercurial-scm.org/D11401
rust/hg-core/src/revset.rs
--- a/rust/hg-core/src/revset.rs	Mon Sep 13 15:12:35 2021 +0200
+++ b/rust/hg-core/src/revset.rs	Sat Sep 11 00:05:08 2021 +0200
@@ -18,21 +18,19 @@
 ) -> Result<Revision, RevlogError> {
     let changelog = repo.changelog()?;
 
-    match resolve_rev_number_or_hex_prefix(input, &changelog.revlog) {
-        Err(RevlogError::InvalidRevision) => {} // Try other syntax
-        result => return result,
+    match input {
+        "null" => return Ok(NULL_REVISION),
+        _ => {}
     }
 
-    if input == "null" {
-        return Ok(NULL_REVISION);
+    match resolve_rev_number_or_hex_prefix(input, &changelog.revlog) {
+        Err(RevlogError::InvalidRevision) => {
+            // TODO: support for the rest of the language here.
+            let msg = format!("cannot parse revset '{}'", input);
+            Err(HgError::unsupported(msg).into())
+        }
+        result => return result,
     }
-
-    // TODO: support for the rest of the language here.
-
-    Err(
-        HgError::unsupported(format!("cannot parse revset '{}'", input))
-            .into(),
-    )
 }
 
 /// Resolve the small subset of the language suitable for revlogs other than