Patchwork D11814: rhg: signal when falling back in logs

login
register
mail settings
Submitter phabricator
Date Nov. 26, 2021, 2:38 p.m.
Message ID <differential-rev-PHID-DREV-onwhu4nkek5yjqovk5jv-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50140/
State New
Headers show

Comments

phabricator - Nov. 26, 2021, 2:38 p.m.
Alphare created this revision.
Alphare added a comment.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.


  Pending CI refresh

REVISION SUMMARY
  We use the `trace` level for the actual message because it can get really busy.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/rhg/src/main.rs
  rust/rhg/src/ui.rs

CHANGE DETAILS




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

Patch

diff --git a/rust/rhg/src/ui.rs b/rust/rhg/src/ui.rs
--- a/rust/rhg/src/ui.rs
+++ b/rust/rhg/src/ui.rs
@@ -130,3 +130,9 @@ 
     let bytes = s.as_bytes();
     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)
+}
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
@@ -1,4 +1,5 @@ 
 extern crate log;
+use crate::ui::local_to_utf8;
 use crate::ui::Ui;
 use clap::App;
 use clap::AppSettings;
@@ -358,7 +359,7 @@ 
 ) -> ! {
     if let (
         OnUnsupported::Fallback { executable },
-        Err(CommandError::UnsupportedFeature { .. }),
+        Err(CommandError::UnsupportedFeature { message }),
     ) = (&on_unsupported, &result)
     {
         let mut args = std::env::args_os();
@@ -374,6 +375,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);
             command.args(args);