# HG changeset patch # User Arseniy Alekseyev # Date 2022-09-20 22:28:25 # Node ID e37416d432e951ab19c6749f229bb547f15fd87c # Parent 467d9df98c68350689e9b6af07b1db987a58fe4d rhg: support tweakdefaults diff --git a/rust/hg-core/src/config/config.rs b/rust/hg-core/src/config/config.rs --- a/rust/hg-core/src/config/config.rs +++ b/rust/hg-core/src/config/config.rs @@ -463,13 +463,23 @@ impl Config { ) -> Option<(&ConfigLayer, &ConfigValue)> { // Filter out the config items that are hidden by [PLAIN]. // This differs from python hg where we delete them from the config. - if should_ignore(&self.plain, §ion, &item) { - return None; - } + let should_ignore = should_ignore(&self.plain, §ion, &item); for layer in self.layers.iter().rev() { if !layer.trusted { continue; } + //The [PLAIN] config should not affect the defaults. + // + // However, PLAIN should also affect the "tweaked" defaults (unless + // "tweakdefault" is part of "HGPLAINEXCEPT"). + // + // In practice the tweak-default layer is only added when it is + // relevant, so we can safely always take it into + // account here. + if should_ignore && !(layer.origin == ConfigOrigin::Tweakdefaults) + { + continue; + } if let Some(v) = layer.get(§ion, &item) { return Some((&layer, v)); } @@ -557,6 +567,38 @@ impl Config { } res } + + // a config layer that's introduced by ui.tweakdefaults + fn tweakdefaults_layer() -> ConfigLayer { + let mut layer = ConfigLayer::new(ConfigOrigin::Tweakdefaults); + + let mut add = |section: &[u8], item: &[u8], value: &[u8]| { + layer.add( + section[..].into(), + item[..].into(), + value[..].into(), + None, + ); + }; + // duplication of [tweakrc] from [ui.py] + add(b"ui", b"rollback", b"False"); + add(b"ui", b"statuscopies", b"yes"); + add(b"ui", b"interface", b"curses"); + add(b"ui", b"relative-paths", b"yes"); + add(b"commands", b"grep.all-files", b"True"); + add(b"commands", b"update.check", b"noconflict"); + add(b"commands", b"status.verbose", b"True"); + add(b"commands", b"resolve.explicit-re-merge", b"True"); + add(b"git", b"git", b"1"); + add(b"git", b"showfunc", b"1"); + add(b"git", b"word-diff", b"1"); + return layer; + } + + // introduce the tweaked defaults as implied by ui.tweakdefaults + pub fn tweakdefaults<'a>(&mut self) -> () { + self.layers.insert(0, Config::tweakdefaults_layer()); + } } #[cfg(test)] diff --git a/rust/hg-core/src/config/layer.rs b/rust/hg-core/src/config/layer.rs --- a/rust/hg-core/src/config/layer.rs +++ b/rust/hg-core/src/config/layer.rs @@ -300,6 +300,8 @@ pub struct ConfigValue { pub enum ConfigOrigin { /// From a configuration file File(PathBuf), + /// From [ui.tweakdefaults] + Tweakdefaults, /// From a `--config` CLI argument CommandLine, /// From a `--color` CLI argument @@ -322,6 +324,9 @@ impl DisplayBytes for ConfigOrigin { ConfigOrigin::CommandLine => out.write_all(b"--config"), ConfigOrigin::CommandLineColor => out.write_all(b"--color"), ConfigOrigin::Environment(e) => write_bytes!(out, b"${}", e), + ConfigOrigin::Tweakdefaults => { + write_bytes!(out, b"ui.tweakdefaults") + } } } } diff --git a/rust/rhg/src/commands/status.rs b/rust/rhg/src/commands/status.rs --- a/rust/rhg/src/commands/status.rs +++ b/rust/rhg/src/commands/status.rs @@ -185,11 +185,6 @@ fn has_unfinished_state(repo: &Repo) -> pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { // TODO: lift these limitations - if invocation.config.get_bool(b"ui", b"tweakdefaults")? { - return Err(CommandError::unsupported( - "ui.tweakdefaults is not yet supported with rhg status", - )); - } if invocation.config.get_bool(b"ui", b"statuscopies")? { return Err(CommandError::unsupported( "ui.statuscopies is not yet supported with rhg status", 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 @@ -330,8 +330,26 @@ fn rhg_main(argv: Vec) -> ! { let mut config_cow = Cow::Borrowed(config); config_cow.to_mut().apply_plain(PlainInfo::from_env()); + if !ui::plain(Some("tweakdefaults")) + && config_cow + .as_ref() + .get_bool(b"ui", b"tweakdefaults") + .unwrap_or_else(|error| { + exit( + &argv, + &initial_current_dir, + &Ui::new_infallible(&config), + OnUnsupported::from_config(&config), + Err(error.into()), + config + .get_bool(b"ui", b"detailed-exit-code") + .unwrap_or(false), + ) + }) + { + config_cow.to_mut().tweakdefaults() + }; let config = config_cow.as_ref(); - let ui = Ui::new(&config).unwrap_or_else(|error| { exit( &argv,