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 @@ -311,27 +311,27 @@ } impl OnUnsupported { - const DEFAULT: Self = OnUnsupported::Abort; const DEFAULT_FALLBACK_EXECUTABLE: &'static [u8] = b"hg"; fn from_config(config: &Config) -> Self { - match config + let fallback = b"fallback"; + match &*config .get(b"rhg", b"on-unsupported") - .map(|value| value.to_ascii_lowercase()) - .as_deref() + .unwrap_or(fallback) + .to_ascii_lowercase() { - Some(b"abort") => OnUnsupported::Abort, - Some(b"abort-silent") => OnUnsupported::AbortSilent, - Some(b"fallback") => OnUnsupported::Fallback { - executable: config - .get(b"rhg", b"fallback-executable") - .unwrap_or(Self::DEFAULT_FALLBACK_EXECUTABLE) - .to_owned(), - }, - None => Self::DEFAULT, - Some(_) => { - // TODO: warn about unknown config value - Self::DEFAULT + b"abort" => OnUnsupported::Abort, + b"abort-silent" => OnUnsupported::AbortSilent, + value => { + if value != fallback { + // TODO: warn about unknown config value + } + OnUnsupported::Fallback { + executable: config + .get(b"rhg", b"fallback-executable") + .unwrap_or(Self::DEFAULT_FALLBACK_EXECUTABLE) + .to_owned(), + } } } } diff --git a/tests/test-rhg.t b/tests/test-rhg.t --- a/tests/test-rhg.t +++ b/tests/test-rhg.t @@ -12,7 +12,7 @@ > } Unimplemented command - $ rhg unimplemented-command + $ rhg unimplemented-command --config rhg.on-unsupported=abort unsupported feature: error: Found argument 'unimplemented-command' which wasn't expected, or isn't valid in this context USAGE: @@ -153,22 +153,21 @@ original content Fallback to Python - $ rhg cat original + $ rhg cat original --config rhg.on-unsupported=abort unsupported feature: `rhg cat` without `--rev` / `-r` [252] - $ FALLBACK="--config rhg.on-unsupported=fallback" - $ rhg cat original $FALLBACK + $ rhg cat original original content - $ rhg cat original $FALLBACK --config rhg.fallback-executable=false + $ rhg cat original --config rhg.fallback-executable=false [1] - $ rhg cat original $FALLBACK --config rhg.fallback-executable=hg-non-existent + $ rhg cat original --config rhg.fallback-executable=hg-non-existent tried to fall back to a 'hg-non-existent' sub-process but got error $ENOENT$ unsupported feature: `rhg cat` without `--rev` / `-r` [252] - $ rhg cat original $FALLBACK --config rhg.fallback-executable="$RHG" + $ rhg cat original --config rhg.fallback-executable="$RHG" Blocking recursive fallback. The 'rhg.fallback-executable = */rust/target/release/rhg' config points to `rhg` itself. (glob) unsupported feature: `rhg cat` without `--rev` / `-r` [252] @@ -183,15 +182,15 @@ store $ echo indoor-pool >> .hg/requires - $ rhg files + $ rhg files --config rhg.on-unsupported=abort unsupported feature: repository requires feature unknown to this Mercurial: indoor-pool [252] - $ rhg cat -r 1 copy_of_original + $ rhg cat -r 1 copy_of_original --config rhg.on-unsupported=abort unsupported feature: repository requires feature unknown to this Mercurial: indoor-pool [252] - $ rhg debugrequirements + $ rhg debugrequirements --config rhg.on-unsupported=abort unsupported feature: repository requires feature unknown to this Mercurial: indoor-pool [252]