Show More
@@ -463,13 +463,23 b' impl Config {' | |||||
463 | ) -> Option<(&ConfigLayer, &ConfigValue)> { |
|
463 | ) -> Option<(&ConfigLayer, &ConfigValue)> { | |
464 | // Filter out the config items that are hidden by [PLAIN]. |
|
464 | // Filter out the config items that are hidden by [PLAIN]. | |
465 | // This differs from python hg where we delete them from the config. |
|
465 | // This differs from python hg where we delete them from the config. | |
466 |
|
|
466 | let should_ignore = should_ignore(&self.plain, §ion, &item); | |
467 | return None; |
|
|||
468 | } |
|
|||
469 | for layer in self.layers.iter().rev() { |
|
467 | for layer in self.layers.iter().rev() { | |
470 | if !layer.trusted { |
|
468 | if !layer.trusted { | |
471 | continue; |
|
469 | continue; | |
472 | } |
|
470 | } | |
|
471 | //The [PLAIN] config should not affect the defaults. | |||
|
472 | // | |||
|
473 | // However, PLAIN should also affect the "tweaked" defaults (unless | |||
|
474 | // "tweakdefault" is part of "HGPLAINEXCEPT"). | |||
|
475 | // | |||
|
476 | // In practice the tweak-default layer is only added when it is | |||
|
477 | // relevant, so we can safely always take it into | |||
|
478 | // account here. | |||
|
479 | if should_ignore && !(layer.origin == ConfigOrigin::Tweakdefaults) | |||
|
480 | { | |||
|
481 | continue; | |||
|
482 | } | |||
473 | if let Some(v) = layer.get(§ion, &item) { |
|
483 | if let Some(v) = layer.get(§ion, &item) { | |
474 | return Some((&layer, v)); |
|
484 | return Some((&layer, v)); | |
475 | } |
|
485 | } | |
@@ -557,6 +567,38 b' impl Config {' | |||||
557 | } |
|
567 | } | |
558 | res |
|
568 | res | |
559 | } |
|
569 | } | |
|
570 | ||||
|
571 | // a config layer that's introduced by ui.tweakdefaults | |||
|
572 | fn tweakdefaults_layer() -> ConfigLayer { | |||
|
573 | let mut layer = ConfigLayer::new(ConfigOrigin::Tweakdefaults); | |||
|
574 | ||||
|
575 | let mut add = |section: &[u8], item: &[u8], value: &[u8]| { | |||
|
576 | layer.add( | |||
|
577 | section[..].into(), | |||
|
578 | item[..].into(), | |||
|
579 | value[..].into(), | |||
|
580 | None, | |||
|
581 | ); | |||
|
582 | }; | |||
|
583 | // duplication of [tweakrc] from [ui.py] | |||
|
584 | add(b"ui", b"rollback", b"False"); | |||
|
585 | add(b"ui", b"statuscopies", b"yes"); | |||
|
586 | add(b"ui", b"interface", b"curses"); | |||
|
587 | add(b"ui", b"relative-paths", b"yes"); | |||
|
588 | add(b"commands", b"grep.all-files", b"True"); | |||
|
589 | add(b"commands", b"update.check", b"noconflict"); | |||
|
590 | add(b"commands", b"status.verbose", b"True"); | |||
|
591 | add(b"commands", b"resolve.explicit-re-merge", b"True"); | |||
|
592 | add(b"git", b"git", b"1"); | |||
|
593 | add(b"git", b"showfunc", b"1"); | |||
|
594 | add(b"git", b"word-diff", b"1"); | |||
|
595 | return layer; | |||
|
596 | } | |||
|
597 | ||||
|
598 | // introduce the tweaked defaults as implied by ui.tweakdefaults | |||
|
599 | pub fn tweakdefaults<'a>(&mut self) -> () { | |||
|
600 | self.layers.insert(0, Config::tweakdefaults_layer()); | |||
|
601 | } | |||
560 | } |
|
602 | } | |
561 |
|
603 | |||
562 | #[cfg(test)] |
|
604 | #[cfg(test)] |
@@ -300,6 +300,8 b' pub struct ConfigValue {' | |||||
300 | pub enum ConfigOrigin { |
|
300 | pub enum ConfigOrigin { | |
301 | /// From a configuration file |
|
301 | /// From a configuration file | |
302 | File(PathBuf), |
|
302 | File(PathBuf), | |
|
303 | /// From [ui.tweakdefaults] | |||
|
304 | Tweakdefaults, | |||
303 | /// From a `--config` CLI argument |
|
305 | /// From a `--config` CLI argument | |
304 | CommandLine, |
|
306 | CommandLine, | |
305 | /// From a `--color` CLI argument |
|
307 | /// From a `--color` CLI argument | |
@@ -322,6 +324,9 b' impl DisplayBytes for ConfigOrigin {' | |||||
322 | ConfigOrigin::CommandLine => out.write_all(b"--config"), |
|
324 | ConfigOrigin::CommandLine => out.write_all(b"--config"), | |
323 | ConfigOrigin::CommandLineColor => out.write_all(b"--color"), |
|
325 | ConfigOrigin::CommandLineColor => out.write_all(b"--color"), | |
324 | ConfigOrigin::Environment(e) => write_bytes!(out, b"${}", e), |
|
326 | ConfigOrigin::Environment(e) => write_bytes!(out, b"${}", e), | |
|
327 | ConfigOrigin::Tweakdefaults => { | |||
|
328 | write_bytes!(out, b"ui.tweakdefaults") | |||
|
329 | } | |||
325 | } |
|
330 | } | |
326 | } |
|
331 | } | |
327 | } |
|
332 | } |
@@ -185,11 +185,6 b' fn has_unfinished_state(repo: &Repo) -> ' | |||||
185 |
|
185 | |||
186 | pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { |
|
186 | pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { | |
187 | // TODO: lift these limitations |
|
187 | // TODO: lift these limitations | |
188 | if invocation.config.get_bool(b"ui", b"tweakdefaults")? { |
|
|||
189 | return Err(CommandError::unsupported( |
|
|||
190 | "ui.tweakdefaults is not yet supported with rhg status", |
|
|||
191 | )); |
|
|||
192 | } |
|
|||
193 | if invocation.config.get_bool(b"ui", b"statuscopies")? { |
|
188 | if invocation.config.get_bool(b"ui", b"statuscopies")? { | |
194 | return Err(CommandError::unsupported( |
|
189 | return Err(CommandError::unsupported( | |
195 | "ui.statuscopies is not yet supported with rhg status", |
|
190 | "ui.statuscopies is not yet supported with rhg status", |
@@ -330,8 +330,26 b' fn rhg_main(argv: Vec<OsString>) -> ! {' | |||||
330 |
|
330 | |||
331 | let mut config_cow = Cow::Borrowed(config); |
|
331 | let mut config_cow = Cow::Borrowed(config); | |
332 | config_cow.to_mut().apply_plain(PlainInfo::from_env()); |
|
332 | config_cow.to_mut().apply_plain(PlainInfo::from_env()); | |
|
333 | if !ui::plain(Some("tweakdefaults")) | |||
|
334 | && config_cow | |||
|
335 | .as_ref() | |||
|
336 | .get_bool(b"ui", b"tweakdefaults") | |||
|
337 | .unwrap_or_else(|error| { | |||
|
338 | exit( | |||
|
339 | &argv, | |||
|
340 | &initial_current_dir, | |||
|
341 | &Ui::new_infallible(&config), | |||
|
342 | OnUnsupported::from_config(&config), | |||
|
343 | Err(error.into()), | |||
|
344 | config | |||
|
345 | .get_bool(b"ui", b"detailed-exit-code") | |||
|
346 | .unwrap_or(false), | |||
|
347 | ) | |||
|
348 | }) | |||
|
349 | { | |||
|
350 | config_cow.to_mut().tweakdefaults() | |||
|
351 | }; | |||
333 | let config = config_cow.as_ref(); |
|
352 | let config = config_cow.as_ref(); | |
334 |
|
||||
335 | let ui = Ui::new(&config).unwrap_or_else(|error| { |
|
353 | let ui = Ui::new(&config).unwrap_or_else(|error| { | |
336 | exit( |
|
354 | exit( | |
337 | &argv, |
|
355 | &argv, |
General Comments 0
You need to be logged in to leave comments.
Login now