diff rust/hg-core/src/config/config_items.rs @ 50765:7f8f6fe13fa9

configitems: move blackbox's config items to the new configitems.toml In order for the Rust code to gain access to default values of in-core extensions that have a Rust implementation, we need to centralize them alongside the core items declarations. This is the first and so far only one of the extensions that have gained Rust support, I don't think it's worth the churn to move the rest of the extension's configitems yet.
author Raphaël Gomès <rgomes@octobus.net>
date Wed, 05 Jul 2023 23:59:22 +0200
parents f8412da86d05
children 58390f59826f
line wrap: on
line diff
--- a/rust/hg-core/src/config/config_items.rs	Mon Feb 13 18:11:48 2023 +0100
+++ b/rust/hg-core/src/config/config_items.rs	Wed Jul 05 23:59:22 2023 +0200
@@ -40,6 +40,11 @@
     /// 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<String>,
 }
 
 /// Corresponds to the raw (i.e. on disk) structure of config items. Used as
@@ -61,6 +66,8 @@
     experimental: bool,
     #[serde(default)]
     documentation: String,
+    #[serde(default)]
+    in_core_extension: Option<String>,
 }
 
 impl TryFrom<RawDefaultConfigItem> for DefaultConfigItem {
@@ -82,6 +89,7 @@
             alias: value.alias,
             experimental: value.experimental,
             documentation: value.documentation,
+            in_core_extension: value.in_core_extension,
         })
     }
 }
@@ -90,6 +98,14 @@
     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 @@
             alias: self.alias,
             experimental: self.experimental,
             documentation: self.documentation,
+            in_core_extension: None,
         }
     }
 }
@@ -596,6 +613,7 @@
             alias: vec![],
             experimental: true,
             documentation: "".into(),
+            in_core_extension: None,
         };
         assert_eq!(config.get(b"censor", b"policy"), Some(&expected));
 
@@ -609,6 +627,7 @@
             alias: vec![],
             experimental: false,
             documentation: "".into(),
+            in_core_extension: None,
         };
         assert_eq!(config.get(b"alias", b"abcdsomething"), Some(&expected));
 
@@ -621,6 +640,7 @@
             alias: vec![],
             experimental: false,
             documentation: "".into(),
+            in_core_extension: None,
         };
         assert_eq!(config.get(b"alias", b"something"), Some(&expected));
 
@@ -632,6 +652,7 @@
             alias: vec![],
             experimental: false,
             documentation: "".into(),
+            in_core_extension: None,
         };
         assert_eq!(config.get(b"chgserver", b"idletimeout"), Some(&expected));
 
@@ -647,6 +668,7 @@
             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 @@
             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"),