Patchwork D10189: rhg: Remove `rhg.fallback-executable=hg` default configuration

login
register
mail settings
Submitter phabricator
Date March 12, 2021, 10:09 p.m.
Message ID <differential-rev-PHID-DREV-6qryeogfycfbsk2bu7hq-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48508/
State Superseded
Headers show

Comments

phabricator - March 12, 2021, 10:09 p.m.
SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  When `rhg.on-unsupported` is configured to `fallback` and an unsupported
  feature is encountered, the previous default was to look for an `hg`
  executable in `$PATH`.
  
  This default was fragile since it was easy to end up accidentally using
  an older version of Mercurial installed system-wide,
  when a local (perhaps patched) installation was intended.
  
  Instead, it is now an error to have `rhg.on-unsupported=fallback`
  without also configuring an explicit path or the fallback executable.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/rhg/src/main.rs
  tests/test-rhg.t

CHANGE DETAILS




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

Patch

diff --git a/tests/test-rhg.t b/tests/test-rhg.t
--- a/tests/test-rhg.t
+++ b/tests/test-rhg.t
@@ -150,6 +150,10 @@ 
   $ rhg cat original
   original content
 
+  $ env -u RHG_FALLBACK_EXECUTABLE rhg cat original
+  abort: 'rhg.on-unsupported=fallback' requires configuring a 'rhg.fallback-executable' path
+  [255]
+
   $ rhg cat original --config rhg.fallback-executable=false
   [1]
 
diff --git a/rust/rhg/src/main.rs b/rust/rhg/src/main.rs
--- a/rust/rhg/src/main.rs
+++ b/rust/rhg/src/main.rs
@@ -138,7 +138,7 @@ 
             exit(
                 &initial_current_dir,
                 &ui,
-                OnUnsupported::from_config(&non_repo_config),
+                OnUnsupported::from_config(&ui, &non_repo_config),
                 Err(CommandError::UnsupportedFeature {
                     message: format_bytes!(
                         b"URL-like --repository {}",
@@ -158,7 +158,7 @@ 
         Err(error) => exit(
             &initial_current_dir,
             &ui,
-            OnUnsupported::from_config(&non_repo_config),
+            OnUnsupported::from_config(&ui, &non_repo_config),
             Err(error.into()),
         ),
     };
@@ -168,6 +168,7 @@ 
     } else {
         &non_repo_config
     };
+    let on_unsupported = OnUnsupported::from_config(&ui, config);
 
     let result = main_with_result(
         &process_start_time,
@@ -175,12 +176,7 @@ 
         repo_result.as_ref(),
         config,
     );
-    exit(
-        &initial_current_dir,
-        &ui,
-        OnUnsupported::from_config(config),
-        result,
-    )
+    exit(&initial_current_dir, &ui, on_unsupported, result)
 }
 
 fn exit_code(result: &Result<(), CommandError>) -> i32 {
@@ -242,6 +238,14 @@ 
             }
         }
     }
+    exit_no_fallback(ui, on_unsupported, result)
+}
+
+fn exit_no_fallback(
+    ui: &Ui,
+    on_unsupported: OnUnsupported,
+    result: Result<(), CommandError>,
+) -> ! {
     match &result {
         Ok(_) => {}
         Err(CommandError::Unsuccessful) => {}
@@ -387,9 +391,8 @@ 
 
 impl OnUnsupported {
     const DEFAULT: Self = OnUnsupported::Abort;
-    const DEFAULT_FALLBACK_EXECUTABLE: &'static [u8] = b"hg";
 
-    fn from_config(config: &Config) -> Self {
+    fn from_config(ui: &Ui, config: &Config) -> Self {
         match config
             .get(b"rhg", b"on-unsupported")
             .map(|value| value.to_ascii_lowercase())
@@ -400,7 +403,16 @@ 
             Some(b"fallback") => OnUnsupported::Fallback {
                 executable: config
                     .get(b"rhg", b"fallback-executable")
-                    .unwrap_or(Self::DEFAULT_FALLBACK_EXECUTABLE)
+                    .unwrap_or_else(|| {
+                        exit_no_fallback(
+                            ui,
+                            Self::Abort,
+                            Err(CommandError::abort(
+                                "abort: 'rhg.on-unsupported=fallback' requires configuring \
+                                a 'rhg.fallback-executable' path"
+                            )),
+                        )
+                    })
                     .to_owned(),
             },
             None => Self::DEFAULT,