# HG changeset patch # User Raphaël Gomès # Date 2021-11-26 14:38:04 # Node ID f19be290756a4c83fe5c2bd7588f3846841b4ab3 # Parent 1bb62821f080a49bcb4c3692746a4fc83e832151 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 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,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 @@ fn exit( ) -> ! { 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 @@ fn exit( )); 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); 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 @@ -219,6 +219,12 @@ pub fn utf8_to_local(s: &str) -> Cow<[u8 Cow::Borrowed(bytes) } +/// Decode user system bytes to Rust string. +pub fn local_to_utf8(s: &[u8]) -> Cow { + // 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,