Patchwork D11401: rust-revset: simplify match logic

login
register
mail settings
Submitter phabricator
Date Sept. 10, 2021, 10:10 p.m.
Message ID <differential-rev-PHID-DREV-zbfr6qcqhvgxpy4ramyb-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49717/
State New
Headers show

Comments

phabricator - Sept. 10, 2021, 10:10 p.m.
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11401

AFFECTED FILES
  rust/hg-core/src/revset.rs

CHANGE DETAILS




To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/rust/hg-core/src/revset.rs b/rust/hg-core/src/revset.rs
--- a/rust/hg-core/src/revset.rs
+++ b/rust/hg-core/src/revset.rs
@@ -19,21 +19,19 @@ 
 ) -> Result<Revision, RevlogError> {
     let changelog = Changelog::open(repo)?;
 
-    match resolve_rev_number_or_hex_prefix(input, &changelog.revlog) {
-        Err(RevlogError::InvalidRevision) => {} // Try other syntax
-        result => return result,
-    }
-
-    if input == "null" {
-        return Ok(NULL_REVISION);
+    match 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