diff rust/rhg/src/main.rs @ 46746:1bac7764ceef

rhg: Fall back to Python if unsupported extensions are enabled Extensions might affect behavior in ways we can?t anticipate, so just ignoring them is not correct. Later we?ll add opt-in configuration to ignore specific extensions. Differential Revision: https://phab.mercurial-scm.org/D10112
author Simon Sapin <simon.sapin@octobus.net>
date Thu, 04 Mar 2021 10:58:43 +0100
parents 3d692e724d06
children 1a036d33bc18
line wrap: on
line diff
--- a/rust/rhg/src/main.rs	Wed Mar 03 20:02:07 2021 +0100
+++ b/rust/rhg/src/main.rs	Thu Mar 04 10:58:43 2021 +0100
@@ -4,7 +4,7 @@
 use clap::AppSettings;
 use clap::Arg;
 use clap::ArgMatches;
-use format_bytes::format_bytes;
+use format_bytes::{format_bytes, join};
 use hg::config::Config;
 use hg::repo::{Repo, RepoError};
 use hg::utils::files::{get_bytes_from_os_str, get_path_from_bytes};
@@ -25,6 +25,8 @@
     repo: Result<&Repo, &NoRepoInCwdError>,
     config: &Config,
 ) -> Result<(), CommandError> {
+    check_extensions(config)?;
+
     let app = App::new("rhg")
         .global_setting(AppSettings::AllowInvalidUtf8)
         .setting(AppSettings::SubcommandRequired)
@@ -352,3 +354,25 @@
         }
     }
 }
+
+const SUPPORTED_EXTENSIONS: &[&[u8]] = &[b"blackbox", b"share"];
+
+fn check_extensions(config: &Config) -> Result<(), CommandError> {
+    let enabled = config.get_section_keys(b"extensions");
+
+    let mut unsupported = enabled;
+    for supported in SUPPORTED_EXTENSIONS {
+        unsupported.remove(supported);
+    }
+
+    if unsupported.is_empty() {
+        Ok(())
+    } else {
+        Err(CommandError::UnsupportedFeature {
+            message: format_bytes!(
+                b"extensions: {}",
+                join(unsupported, b", ")
+            ),
+        })
+    }
+}