rhg: add a config option to fall back immediately stable
authorRaphaël Gomès <rgomes@octobus.net>
Thu, 03 Nov 2022 16:30:35 +0100
branchstable
changeset 49569 5318ac25dfdc
parent 49566 05ef5f097df4
child 49576 d12446766a35
rhg: add a config option to fall back immediately This is useful for debugging the behavior of the "default" `hg` in tests without having to manually substitute the fallback path.
mercurial/helptext/config.txt
rust/rhg/src/main.rs
tests/test-rhg.t
--- a/mercurial/helptext/config.txt	Thu Nov 03 15:57:37 2022 +0100
+++ b/mercurial/helptext/config.txt	Thu Nov 03 16:30:35 2022 +0100
@@ -2165,6 +2165,14 @@
     Path to the executable to run in a sub-process when falling back to
     another implementation of Mercurial.
 
+``fallback-immediately``
+    Fall back to ``fallback-executable`` as soon as possible, regardless of
+    the `rhg.on-unsupported` configuration. Useful for debugging, for example to
+    bypass `rhg` if the deault `hg` points to `rhg`.
+
+    Note that because this requires loading the configuration, it is possible
+    that `rhg` error out before being able to fall back.
+
 ``ignored-extensions``
     Controls which extensions should be ignored by `rhg`. By default, `rhg`
     triggers the `rhg.on-unsupported` behavior any unsupported extensions.
--- a/rust/rhg/src/main.rs	Thu Nov 03 15:57:37 2022 +0100
+++ b/rust/rhg/src/main.rs	Thu Nov 03 16:30:35 2022 +0100
@@ -348,6 +348,24 @@
     let config = config_cow.as_ref();
     let ui = Ui::new(&config)
         .unwrap_or_else(|error| early_exit(&config, error.into()));
+
+    if let Ok(true) = config.get_bool(b"rhg", b"fallback-immediately") {
+        exit(
+            &argv,
+            &initial_current_dir,
+            &ui,
+            OnUnsupported::Fallback {
+                executable: config
+                    .get(b"rhg", b"fallback-executable")
+                    .map(ToOwned::to_owned),
+            },
+            Err(CommandError::unsupported(
+                "`rhg.fallback-immediately is true`",
+            )),
+            false,
+        )
+    }
+
     let result = main_with_result(
         argv.iter().map(|s| s.to_owned()).collect(),
         &process_start_time,
--- a/tests/test-rhg.t	Thu Nov 03 15:57:37 2022 +0100
+++ b/tests/test-rhg.t	Thu Nov 03 16:30:35 2022 +0100
@@ -168,6 +168,10 @@
   $ rhg cat original --exclude="*.rs"
   original content
 
+Check that `fallback-immediately` overrides `$NO_FALLBACK`
+  $ $NO_FALLBACK rhg cat original --exclude="*.rs" --config rhg.fallback-immediately=1
+  original content
+
   $ (unset RHG_FALLBACK_EXECUTABLE; rhg cat original --exclude="*.rs")
   abort: 'rhg.on-unsupported=fallback' without 'rhg.fallback-executable' set.
   [255]