diff --git a/hgext/blackbox.py b/hgext/blackbox.py --- a/hgext/blackbox.py +++ b/hgext/blackbox.py @@ -67,41 +67,6 @@ testedwith = b'ships-with-hg-core' cmdtable = {} command = registrar.command(cmdtable) -configtable = {} -configitem = registrar.configitem(configtable) - -configitem( - b'blackbox', - b'dirty', - default=False, -) -configitem( - b'blackbox', - b'maxsize', - default=b'1 MB', -) -configitem( - b'blackbox', - b'logsource', - default=False, -) -configitem( - b'blackbox', - b'maxfiles', - default=7, -) -configitem( - b'blackbox', - b'track', - default=lambda: [b'*'], -) -configitem( - b'blackbox', - b'ignore', - default=lambda: [b'chgserver', b'cmdserver', b'extension'], -) -configitem(b'blackbox', b'date-format', default=b'') - _lastlogger = loggingutil.proxylogger() diff --git a/mercurial/configitems.py b/mercurial/configitems.py --- a/mercurial/configitems.py +++ b/mercurial/configitems.py @@ -59,6 +59,7 @@ class configitem: priority=0, experimental=False, documentation="", + in_core_extension=None, ): self.section = section self.name = name @@ -69,6 +70,7 @@ class configitem: self.priority = priority self.experimental = experimental self._re = None + self.in_core_extension = in_core_extension if generic: self._re = re.compile(self.name) diff --git a/mercurial/configitems.toml b/mercurial/configitems.toml --- a/mercurial/configitems.toml +++ b/mercurial/configitems.toml @@ -23,6 +23,7 @@ # - alias: list of 2-tuples of strings # - experimental: boolean # - documentation: string +# - in_core_extension: string # # ## Template # @@ -2695,6 +2696,8 @@ default = true section = "worker" name = "numcpus" +# Templates and template applications + [[template-applications]] template = "diff-options" section = "annotate" @@ -2757,3 +2760,48 @@ default = false suffix = "word-diff" default = false +# In-core extensions + +[[items]] +section = "blackbox" +name = "dirty" +default = false +in_core_extension = "blackbox" + +[[items]] +section = "blackbox" +name = "maxsize" +default = "1 MB" +in_core_extension = "blackbox" + +[[items]] +section = "blackbox" +name = "logsource" +default = false +in_core_extension = "blackbox" + +[[items]] +section = "blackbox" +name = "maxfiles" +default = 7 +in_core_extension = "blackbox" + +[[items]] +section = "blackbox" +name = "track" +default-type = "lambda" +default = ["*"] +in_core_extension = "blackbox" + +[[items]] +section = "blackbox" +name = "ignore" +default-type = "lambda" +default = ["chgserver", "cmdserver", "extension"] +in_core_extension = "blackbox" + +[[items]] +section = "blackbox" +name = "date-format" +default = "" +in_core_extension = "blackbox" diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -47,6 +47,7 @@ from . import ( configitems, encoding, error, + extensions, formatter, loggingutil, progress, @@ -659,6 +660,12 @@ class ui: item = self._knownconfig.get(section, {}).get(name) alternates = [(section, name)] + if item is not None and item.in_core_extension is not None: + # Only return the default for an in-core extension item if said + # extension is enabled + if item.in_core_extension in extensions.extensions(self): + item = None + if item is not None: alternates.extend(item.alias) if callable(item.default): diff --git a/rust/hg-core/src/config/config_items.rs b/rust/hg-core/src/config/config_items.rs --- a/rust/hg-core/src/config/config_items.rs +++ b/rust/hg-core/src/config/config_items.rs @@ -40,6 +40,11 @@ pub struct DefaultConfigItem { /// The (possibly empty) docstring for the item #[serde(default)] documentation: String, + /// Whether the item is part of an in-core extension. This allows us to + /// hide them if the extension is not enabled, to preserve legacy + /// behavior. + #[serde(default)] + in_core_extension: Option, } /// Corresponds to the raw (i.e. on disk) structure of config items. Used as @@ -61,6 +66,8 @@ struct RawDefaultConfigItem { experimental: bool, #[serde(default)] documentation: String, + #[serde(default)] + in_core_extension: Option, } impl TryFrom for DefaultConfigItem { @@ -82,6 +89,7 @@ impl TryFrom for D alias: value.alias, experimental: value.experimental, documentation: value.documentation, + in_core_extension: value.in_core_extension, }) } } @@ -90,6 +98,14 @@ impl DefaultConfigItem { fn is_generic(&self) -> bool { self.priority.is_some() } + + pub fn in_core_extension(&self) -> Option<&str> { + self.in_core_extension.as_deref() + } + + pub fn section(&self) -> &str { + self.section.as_ref() + } } impl<'a> TryFrom<&'a DefaultConfigItem> for Option<&'a str> { @@ -302,6 +318,7 @@ impl TemplateItem { alias: self.alias, experimental: self.experimental, documentation: self.documentation, + in_core_extension: None, } } } @@ -596,6 +613,7 @@ suffix = "unified" alias: vec![], experimental: true, documentation: "".into(), + in_core_extension: None, }; assert_eq!(config.get(b"censor", b"policy"), Some(&expected)); @@ -609,6 +627,7 @@ suffix = "unified" alias: vec![], experimental: false, documentation: "".into(), + in_core_extension: None, }; assert_eq!(config.get(b"alias", b"abcdsomething"), Some(&expected)); @@ -621,6 +640,7 @@ suffix = "unified" alias: vec![], experimental: false, documentation: "".into(), + in_core_extension: None, }; assert_eq!(config.get(b"alias", b"something"), Some(&expected)); @@ -632,6 +652,7 @@ suffix = "unified" alias: vec![], experimental: false, documentation: "".into(), + in_core_extension: None, }; assert_eq!(config.get(b"chgserver", b"idletimeout"), Some(&expected)); @@ -647,6 +668,7 @@ suffix = "unified" alias: vec![], experimental: false, documentation: "".into(), + in_core_extension: None, }; assert_eq!(config.get(b"cmdserver", b"track-log"), Some(&expected)); @@ -660,6 +682,7 @@ suffix = "unified" documentation: "This is a docstring.\nThis is another line but this is not." .into(), + in_core_extension: None, }; assert_eq!( config.get(b"command-templates", b"graphnode"), diff --git a/rust/hg-core/src/config/mod.rs b/rust/hg-core/src/config/mod.rs --- a/rust/hg-core/src/config/mod.rs +++ b/rust/hg-core/src/config/mod.rs @@ -373,7 +373,17 @@ impl Config { Some("`mercurial/configitems.toml` is not valid".into()), ) })?; - Ok(default_config.get(section, item)) + let default_opt = default_config.get(section, item); + Ok(default_opt.filter(|default| { + default + .in_core_extension() + .map(|extension| { + // Only return the default for an in-core extension item + // if said extension is enabled + self.is_extension_enabled(extension.as_bytes()) + }) + .unwrap_or(true) + })) } fn get_parse<'config, T: 'config>( diff --git a/rust/rhg/src/blackbox.rs b/rust/rhg/src/blackbox.rs --- a/rust/rhg/src/blackbox.rs +++ b/rust/rhg/src/blackbox.rs @@ -7,12 +7,6 @@ use hg::repo::Repo; use hg::utils::{files::get_bytes_from_os_str, shell_quote}; use std::ffi::OsString; -const ONE_MEBIBYTE: u64 = 1 << 20; - -// TODO: somehow keep defaults in sync with `configitem` in `hgext/blackbox.py` -const DEFAULT_MAX_SIZE: u64 = ONE_MEBIBYTE; -const DEFAULT_MAX_FILES: u32 = 7; - // Python does not support %.3f, only %f const DEFAULT_DATE_FORMAT: &str = "%Y-%m-%d %H:%M:%S%.3f"; @@ -62,15 +56,28 @@ impl<'a> Blackbox<'a> { max_size: invocation .config .get_byte_size(b"blackbox", b"maxsize")? - .unwrap_or(DEFAULT_MAX_SIZE), + .expect( + "blackbox.maxsize should have a default value", + ), max_files: invocation .config .get_u32(b"blackbox", b"maxfiles")? - .unwrap_or(DEFAULT_MAX_FILES), + .expect( + "blackbox.maxfiles should have a default value", + ), date_format: invocation .config .get_str(b"blackbox", b"date-format")? - .unwrap_or(DEFAULT_DATE_FORMAT), + .map(|f| { + if f.is_empty() { + DEFAULT_DATE_FORMAT + } else { + f + } + }) + .expect( + "blackbox.date-format should have a default value", + ), }) } } else {