diff rust/rhg/src/main.rs @ 46729:6cd9f53aaed8

rhg: Fall back to Python on --repository with an URL A low-hanging fruit to improve on this would be to properly parse and handle `file:` URLs. But other Python-based hg supports some other URL schemes for features that rhg does not support yet. Differential Revision: https://phab.mercurial-scm.org/D10101
author Simon Sapin <simon.sapin@octobus.net>
date Wed, 03 Mar 2021 19:02:06 +0100
parents 93e9f448273c
children 3d692e724d06
line wrap: on
line diff
--- a/rust/rhg/src/main.rs	Wed Mar 03 18:43:05 2021 +0100
+++ b/rust/rhg/src/main.rs	Wed Mar 03 19:02:06 2021 +0100
@@ -95,6 +95,25 @@
             exit(&ui, on_unsupported, Err(error.into()))
         });
 
+    if let Some(repo_path_bytes) = &early_args.repo {
+        lazy_static::lazy_static! {
+            static ref SCHEME_RE: regex::bytes::Regex =
+                // Same as `_matchscheme` in `mercurial/util.py`
+                regex::bytes::Regex::new("^[a-zA-Z0-9+.\\-]+:").unwrap();
+        }
+        if SCHEME_RE.is_match(&repo_path_bytes) {
+            exit(
+                &ui,
+                OnUnsupported::from_config(&non_repo_config),
+                Err(CommandError::UnsupportedFeature {
+                    message: format_bytes!(
+                        b"URL-like --repository {}",
+                        repo_path_bytes
+                    ),
+                }),
+            )
+        }
+    }
     let repo_path = early_args.repo.as_deref().map(get_path_from_bytes);
     let repo_result = match Repo::find(&non_repo_config, repo_path) {
         Ok(repo) => Ok(repo),