# HG changeset patch # User Arseniy Alekseyev # Date 1690560517 -3600 # Node ID 53d77f96e0493414b1b00aaa4a274f583468593f # Parent e9a2e1c77f28d72e7b83f47273c48c3ba67309c6 rhg: tweak rhg fallback code structure The goal here is to share the code that accesses the config setting, but also move it to the top-level, so that we can more easily change this code later. (in fact in Jane Street we want to make it choose chg in some cases) diff -r e9a2e1c77f28 -r 53d77f96e049 rust/rhg/src/main.rs --- a/rust/rhg/src/main.rs Fri Jul 21 15:26:15 2023 +0200 +++ b/rust/rhg/src/main.rs Fri Jul 28 17:08:37 2023 +0100 @@ -350,11 +350,7 @@ &argv, &initial_current_dir, &ui, - OnUnsupported::Fallback { - executable: config - .get(b"rhg", b"fallback-executable") - .map(ToOwned::to_owned), - }, + OnUnsupported::fallback(config), Err(CommandError::unsupported( "`rhg.fallback-immediately is true`", )), @@ -663,6 +659,18 @@ impl OnUnsupported { const DEFAULT: Self = OnUnsupported::Abort; + fn fallback_executable(config: &Config) -> Option> { + config + .get(b"rhg", b"fallback-executable") + .map(|x| x.to_owned()) + } + + fn fallback(config: &Config) -> Self { + OnUnsupported::Fallback { + executable: Self::fallback_executable(config), + } + } + fn from_config(config: &Config) -> Self { match config .get(b"rhg", b"on-unsupported") @@ -671,11 +679,7 @@ { Some(b"abort") => OnUnsupported::Abort, Some(b"abort-silent") => OnUnsupported::AbortSilent, - Some(b"fallback") => OnUnsupported::Fallback { - executable: config - .get(b"rhg", b"fallback-executable") - .map(|x| x.to_owned()), - }, + Some(b"fallback") => Self::fallback(config), None => Self::DEFAULT, Some(_) => { // TODO: warn about unknown config value