changeset 50809:53d77f96e049

rhg: tweak rhg fallback code structure The goal here is to share the code that accesses the config setting, but also move it to the top-level, so that we can more easily change this code later. (in fact in Jane Street we want to make it choose chg in some cases)
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Fri, 28 Jul 2023 17:08:37 +0100
parents e9a2e1c77f28
children 5c3d07950bac
files rust/rhg/src/main.rs
diffstat 1 files changed, 14 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/rust/rhg/src/main.rs	Fri Jul 21 15:26:15 2023 +0200
+++ b/rust/rhg/src/main.rs	Fri Jul 28 17:08:37 2023 +0100
@@ -350,11 +350,7 @@
             &argv,
             &initial_current_dir,
             &ui,
-            OnUnsupported::Fallback {
-                executable: config
-                    .get(b"rhg", b"fallback-executable")
-                    .map(ToOwned::to_owned),
-            },
+            OnUnsupported::fallback(config),
             Err(CommandError::unsupported(
                 "`rhg.fallback-immediately is true`",
             )),
@@ -663,6 +659,18 @@
 impl OnUnsupported {
     const DEFAULT: Self = OnUnsupported::Abort;
 
+    fn fallback_executable(config: &Config) -> Option<Vec<u8>> {
+        config
+            .get(b"rhg", b"fallback-executable")
+            .map(|x| x.to_owned())
+    }
+
+    fn fallback(config: &Config) -> Self {
+        OnUnsupported::Fallback {
+            executable: Self::fallback_executable(config),
+        }
+    }
+
     fn from_config(config: &Config) -> Self {
         match config
             .get(b"rhg", b"on-unsupported")
@@ -671,11 +679,7 @@
         {
             Some(b"abort") => OnUnsupported::Abort,
             Some(b"abort-silent") => OnUnsupported::AbortSilent,
-            Some(b"fallback") => OnUnsupported::Fallback {
-                executable: config
-                    .get(b"rhg", b"fallback-executable")
-                    .map(|x| x.to_owned()),
-            },
+            Some(b"fallback") => Self::fallback(config),
             None => Self::DEFAULT,
             Some(_) => {
                 // TODO: warn about unknown config value