changeset 48770:f19be290756a

rhg: signal when falling back in logs We use the `trace` level for the actual message because it can get really busy. Differential Revision: https://phab.mercurial-scm.org/D11814
author Raphaël Gomès <rgomes@octobus.net>
date Fri, 26 Nov 2021 15:38:04 +0100
parents 1bb62821f080
children 79a967128055
files rust/rhg/src/main.rs rust/rhg/src/ui.rs
diffstat 2 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/rust/rhg/src/main.rs	Mon Feb 07 13:23:58 2022 +0100
+++ b/rust/rhg/src/main.rs	Fri Nov 26 15:38:04 2021 +0100
@@ -1,6 +1,6 @@
 extern crate log;
 use crate::error::CommandError;
-use crate::ui::Ui;
+use crate::ui::{local_to_utf8, Ui};
 use clap::App;
 use clap::AppSettings;
 use clap::Arg;
@@ -383,7 +383,7 @@
 ) -> ! {
     if let (
         OnUnsupported::Fallback { executable },
-        Err(CommandError::UnsupportedFeature { .. }),
+        Err(CommandError::UnsupportedFeature { message }),
     ) = (&on_unsupported, &result)
     {
         let mut args = std::env::args_os();
@@ -413,6 +413,8 @@
             ));
             on_unsupported = OnUnsupported::Abort
         } else {
+            log::debug!("falling back (see trace-level log)");
+            log::trace!("{}", local_to_utf8(message));
             // `args` is now `argv[1..]` since we’ve already consumed
             // `argv[0]`
             let mut command = Command::new(executable_path);
--- a/rust/rhg/src/ui.rs	Mon Feb 07 13:23:58 2022 +0100
+++ b/rust/rhg/src/ui.rs	Fri Nov 26 15:38:04 2021 +0100
@@ -219,6 +219,12 @@
     Cow::Borrowed(bytes)
 }
 
+/// Decode user system bytes to Rust string.
+pub fn local_to_utf8(s: &[u8]) -> Cow<str> {
+    // TODO decode from the user's system
+    String::from_utf8_lossy(s)
+}
+
 /// Should formatted output be used?
 ///
 /// Note: rhg does not have the formatter mechanism yet,