Mercurial > hg
annotate rust/hg-core/src/config/config_items.rs @ 50983:8343947af6a7
rust-config: fix incorrect coercion of null values to false
As explained in the previous changeset:
Probably being too trigger happy about boolean values, I incorrectly set
the transform for a `None` to a `Some(false)`. It would cause for example
the `ui.formatted` value to be set to `Some(false)`, which turns off the colors
among other things, when `None` would trigger the automatic behavior.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Wed, 09 Aug 2023 15:46:35 +0200 |
parents | 58390f59826f |
children |
rev | line source |
---|---|
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
1 //! Code for parsing default Mercurial config items. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
2 use itertools::Itertools; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
3 use serde::Deserialize; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
4 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
5 use crate::{errors::HgError, exit_codes, FastHashMap}; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
6 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
7 /// Corresponds to the structure of `mercurial/configitems.toml`. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
8 #[derive(Debug, Deserialize)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
9 pub struct ConfigItems { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
10 items: Vec<DefaultConfigItem>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
11 templates: FastHashMap<String, Vec<TemplateItem>>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
12 #[serde(rename = "template-applications")] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
13 template_applications: Vec<TemplateApplication>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
14 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
15 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
16 /// Corresponds to a config item declaration in `mercurial/configitems.toml`. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
17 #[derive(Clone, Debug, PartialEq, Deserialize)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
18 #[serde(try_from = "RawDefaultConfigItem")] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
19 pub struct DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
20 /// Section of the config the item is in (e.g. `[merge-tools]`) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
21 section: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
22 /// Name of the item (e.g. `meld.gui`) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
23 name: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
24 /// Default value (can be dynamic, see [`DefaultConfigItemType`]) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
25 default: Option<DefaultConfigItemType>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
26 /// If the config option is generic (e.g. `merge-tools.*`), defines |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
27 /// the priority of this item relative to other generic items. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
28 /// If we're looking for <pattern>, then all generic items within the same |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
29 /// section will be sorted by order of priority, and the first regex match |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
30 /// against `name` is returned. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
31 #[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
32 priority: Option<isize>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
33 /// Aliases, if any. Each alias is a tuple of `(section, name)` for each |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
34 /// option that is aliased to this one. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
35 #[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
36 alias: Vec<(String, String)>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
37 /// Whether the config item is marked as experimental |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
38 #[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
39 experimental: bool, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
40 /// The (possibly empty) docstring for the item |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
41 #[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
42 documentation: String, |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
43 /// Whether the item is part of an in-core extension. This allows us to |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
44 /// hide them if the extension is not enabled, to preserve legacy |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
45 /// behavior. |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
46 #[serde(default)] |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
47 in_core_extension: Option<String>, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
48 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
49 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
50 /// Corresponds to the raw (i.e. on disk) structure of config items. Used as |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
51 /// an intermediate step in deserialization. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
52 #[derive(Clone, Debug, Deserialize)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
53 struct RawDefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
54 section: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
55 name: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
56 default: Option<toml::Value>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
57 #[serde(rename = "default-type")] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
58 default_type: Option<String>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
59 #[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
60 priority: isize, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
61 #[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
62 generic: bool, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
63 #[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
64 alias: Vec<(String, String)>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
65 #[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
66 experimental: bool, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
67 #[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
68 documentation: String, |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
69 #[serde(default)] |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
70 in_core_extension: Option<String>, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
71 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
72 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
73 impl TryFrom<RawDefaultConfigItem> for DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
74 type Error = HgError; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
75 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
76 fn try_from(value: RawDefaultConfigItem) -> Result<Self, Self::Error> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
77 Ok(Self { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
78 section: value.section, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
79 name: value.name, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
80 default: raw_default_to_concrete( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
81 value.default_type, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
82 value.default, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
83 )?, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
84 priority: if value.generic { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
85 Some(value.priority) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
86 } else { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
87 None |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
88 }, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
89 alias: value.alias, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
90 experimental: value.experimental, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
91 documentation: value.documentation, |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
92 in_core_extension: value.in_core_extension, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
93 }) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
94 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
95 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
96 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
97 impl DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
98 fn is_generic(&self) -> bool { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
99 self.priority.is_some() |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
100 } |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
101 |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
102 pub fn in_core_extension(&self) -> Option<&str> { |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
103 self.in_core_extension.as_deref() |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
104 } |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
105 |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
106 pub fn section(&self) -> &str { |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
107 self.section.as_ref() |
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
108 } |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
109 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
110 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
111 impl<'a> TryFrom<&'a DefaultConfigItem> for Option<&'a str> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
112 type Error = HgError; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
113 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
114 fn try_from( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
115 value: &'a DefaultConfigItem, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
116 ) -> Result<Option<&'a str>, Self::Error> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
117 match &value.default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
118 Some(default) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
119 let err = HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
120 format!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
121 "programming error: wrong query on config item '{}.{}'", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
122 value.section, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
123 value.name |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
124 ), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
125 exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
126 Some(format!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
127 "asked for '&str', type of default is '{}'", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
128 default.type_str() |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
129 )), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
130 ); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
131 match default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
132 DefaultConfigItemType::Primitive(toml::Value::String( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
133 s, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
134 )) => Ok(Some(s)), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
135 _ => Err(err), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
136 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
137 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
138 None => Ok(None), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
139 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
140 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
141 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
142 |
50981
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
143 impl<'a> TryFrom<&'a DefaultConfigItem> for Option<&'a [u8]> { |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
144 type Error = HgError; |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
145 |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
146 fn try_from( |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
147 value: &'a DefaultConfigItem, |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
148 ) -> Result<Option<&'a [u8]>, Self::Error> { |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
149 match &value.default { |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
150 Some(default) => { |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
151 let err = HgError::abort( |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
152 format!( |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
153 "programming error: wrong query on config item '{}.{}'", |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
154 value.section, |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
155 value.name |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
156 ), |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
157 exit_codes::ABORT, |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
158 Some(format!( |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
159 "asked for bytes, type of default is '{}', \ |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
160 which cannot be interpreted as bytes", |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
161 default.type_str() |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
162 )), |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
163 ); |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
164 match default { |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
165 DefaultConfigItemType::Primitive(p) => { |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
166 Ok(p.as_str().map(str::as_bytes)) |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
167 } |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
168 _ => Err(err), |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
169 } |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
170 } |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
171 None => Ok(None), |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
172 } |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
173 } |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
174 } |
58390f59826f
rust-config: fix fallback to default not parsing the default value
Raphaël Gomès <rgomes@octobus.net>
parents:
50765
diff
changeset
|
175 |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
176 impl TryFrom<&DefaultConfigItem> for Option<bool> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
177 type Error = HgError; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
178 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
179 fn try_from(value: &DefaultConfigItem) -> Result<Self, Self::Error> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
180 match &value.default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
181 Some(default) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
182 let err = HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
183 format!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
184 "programming error: wrong query on config item '{}.{}'", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
185 value.section, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
186 value.name |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
187 ), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
188 exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
189 Some(format!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
190 "asked for 'bool', type of default is '{}'", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
191 default.type_str() |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
192 )), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
193 ); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
194 match default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
195 DefaultConfigItemType::Primitive( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
196 toml::Value::Boolean(b), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
197 ) => Ok(Some(*b)), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
198 _ => Err(err), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
199 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
200 } |
50983
8343947af6a7
rust-config: fix incorrect coercion of null values to false
Raphaël Gomès <rgomes@octobus.net>
parents:
50981
diff
changeset
|
201 None => Ok(None), |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
202 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
203 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
204 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
205 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
206 impl TryFrom<&DefaultConfigItem> for Option<u32> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
207 type Error = HgError; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
208 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
209 fn try_from(value: &DefaultConfigItem) -> Result<Self, Self::Error> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
210 match &value.default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
211 Some(default) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
212 let err = HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
213 format!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
214 "programming error: wrong query on config item '{}.{}'", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
215 value.section, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
216 value.name |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
217 ), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
218 exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
219 Some(format!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
220 "asked for 'u32', type of default is '{}'", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
221 default.type_str() |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
222 )), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
223 ); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
224 match default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
225 DefaultConfigItemType::Primitive( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
226 toml::Value::Integer(b), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
227 ) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
228 Ok(Some((*b).try_into().expect("TOML integer to u32"))) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
229 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
230 _ => Err(err), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
231 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
232 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
233 None => Ok(None), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
234 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
235 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
236 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
237 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
238 impl TryFrom<&DefaultConfigItem> for Option<u64> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
239 type Error = HgError; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
240 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
241 fn try_from(value: &DefaultConfigItem) -> Result<Self, Self::Error> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
242 match &value.default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
243 Some(default) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
244 let err = HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
245 format!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
246 "programming error: wrong query on config item '{}.{}'", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
247 value.section, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
248 value.name |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
249 ), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
250 exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
251 Some(format!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
252 "asked for 'u64', type of default is '{}'", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
253 default.type_str() |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
254 )), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
255 ); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
256 match default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
257 DefaultConfigItemType::Primitive( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
258 toml::Value::Integer(b), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
259 ) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
260 Ok(Some((*b).try_into().expect("TOML integer to u64"))) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
261 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
262 _ => Err(err), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
263 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
264 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
265 None => Ok(None), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
266 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
267 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
268 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
269 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
270 /// Allows abstracting over more complex default values than just primitives. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
271 /// The former `configitems.py` contained some dynamic code that is encoded |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
272 /// in this enum. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
273 #[derive(Debug, PartialEq, Clone, Deserialize)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
274 pub enum DefaultConfigItemType { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
275 /// Some primitive type (string, integer, boolean) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
276 Primitive(toml::Value), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
277 /// A dynamic value that will be given by the code at runtime |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
278 Dynamic, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
279 /// An lazily-returned array (possibly only relevant in the Python impl) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
280 /// Example: `lambda: [b"zstd", b"zlib"]` |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
281 Lambda(Vec<String>), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
282 /// For now, a special case for `web.encoding` that points to the |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
283 /// `encoding.encoding` module in the Python impl so that local encoding |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
284 /// is correctly resolved at runtime |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
285 LazyModule(String), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
286 ListType, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
287 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
288 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
289 impl DefaultConfigItemType { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
290 pub fn type_str(&self) -> &str { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
291 match self { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
292 DefaultConfigItemType::Primitive(primitive) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
293 primitive.type_str() |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
294 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
295 DefaultConfigItemType::Dynamic => "dynamic", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
296 DefaultConfigItemType::Lambda(_) => "lambda", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
297 DefaultConfigItemType::LazyModule(_) => "lazy_module", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
298 DefaultConfigItemType::ListType => "list_type", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
299 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
300 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
301 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
302 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
303 /// Most of the fields are shared with [`DefaultConfigItem`]. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
304 #[derive(Debug, Clone, Deserialize)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
305 #[serde(try_from = "RawTemplateItem")] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
306 struct TemplateItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
307 suffix: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
308 default: Option<DefaultConfigItemType>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
309 priority: Option<isize>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
310 #[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
311 alias: Vec<(String, String)>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
312 #[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
313 experimental: bool, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
314 #[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
315 documentation: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
316 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
317 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
318 /// Corresponds to the raw (i.e. on disk) representation of a template item. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
319 /// Used as an intermediate step in deserialization. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
320 #[derive(Clone, Debug, Deserialize)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
321 struct RawTemplateItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
322 suffix: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
323 default: Option<toml::Value>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
324 #[serde(rename = "default-type")] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
325 default_type: Option<String>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
326 #[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
327 priority: isize, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
328 #[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
329 generic: bool, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
330 #[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
331 alias: Vec<(String, String)>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
332 #[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
333 experimental: bool, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
334 #[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
335 documentation: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
336 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
337 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
338 impl TemplateItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
339 fn into_default_item( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
340 self, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
341 application: TemplateApplication, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
342 ) -> DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
343 DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
344 section: application.section, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
345 name: application |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
346 .prefix |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
347 .map(|prefix| format!("{}.{}", prefix, self.suffix)) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
348 .unwrap_or(self.suffix), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
349 default: self.default, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
350 priority: self.priority, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
351 alias: self.alias, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
352 experimental: self.experimental, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
353 documentation: self.documentation, |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
354 in_core_extension: None, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
355 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
356 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
357 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
358 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
359 impl TryFrom<RawTemplateItem> for TemplateItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
360 type Error = HgError; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
361 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
362 fn try_from(value: RawTemplateItem) -> Result<Self, Self::Error> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
363 Ok(Self { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
364 suffix: value.suffix, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
365 default: raw_default_to_concrete( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
366 value.default_type, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
367 value.default, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
368 )?, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
369 priority: if value.generic { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
370 Some(value.priority) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
371 } else { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
372 None |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
373 }, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
374 alias: value.alias, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
375 experimental: value.experimental, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
376 documentation: value.documentation, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
377 }) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
378 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
379 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
380 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
381 /// Transforms the on-disk string-based representation of complex default types |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
382 /// to the concrete [`DefaultconfigItemType`]. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
383 fn raw_default_to_concrete( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
384 default_type: Option<String>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
385 default: Option<toml::Value>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
386 ) -> Result<Option<DefaultConfigItemType>, HgError> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
387 Ok(match default_type.as_deref() { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
388 None => default.as_ref().map(|default| { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
389 DefaultConfigItemType::Primitive(default.to_owned()) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
390 }), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
391 Some("dynamic") => Some(DefaultConfigItemType::Dynamic), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
392 Some("list_type") => Some(DefaultConfigItemType::ListType), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
393 Some("lambda") => match &default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
394 Some(default) => Some(DefaultConfigItemType::Lambda( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
395 default.to_owned().try_into().map_err(|e| { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
396 HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
397 e.to_string(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
398 exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
399 Some("Check 'mercurial/configitems.toml'".into()), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
400 ) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
401 })?, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
402 )), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
403 None => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
404 return Err(HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
405 "lambda defined with no return value".to_string(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
406 exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
407 Some("Check 'mercurial/configitems.toml'".into()), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
408 )) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
409 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
410 }, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
411 Some("lazy_module") => match &default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
412 Some(default) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
413 Some(DefaultConfigItemType::LazyModule(match default { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
414 toml::Value::String(module) => module.to_owned(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
415 _ => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
416 return Err(HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
417 "lazy_module module name should be a string" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
418 .to_string(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
419 exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
420 Some("Check 'mercurial/configitems.toml'".into()), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
421 )) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
422 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
423 })) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
424 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
425 None => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
426 return Err(HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
427 "lazy_module should have a default value".to_string(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
428 exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
429 Some("Check 'mercurial/configitems.toml'".into()), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
430 )) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
431 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
432 }, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
433 Some(invalid) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
434 return Err(HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
435 format!("invalid default_type '{}'", invalid), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
436 exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
437 Some("Check 'mercurial/configitems.toml'".into()), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
438 )) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
439 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
440 }) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
441 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
442 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
443 #[derive(Debug, Clone, Deserialize)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
444 struct TemplateApplication { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
445 template: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
446 section: String, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
447 #[serde(default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
448 prefix: Option<String>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
449 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
450 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
451 /// Represents the (dynamic) set of default core Mercurial config items from |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
452 /// `mercurial/configitems.toml`. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
453 #[derive(Clone, Debug, Default)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
454 pub struct DefaultConfig { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
455 /// Mapping of section -> (mapping of name -> item) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
456 items: FastHashMap<String, FastHashMap<String, DefaultConfigItem>>, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
457 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
458 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
459 impl DefaultConfig { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
460 pub fn empty() -> DefaultConfig { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
461 Self { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
462 items: Default::default(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
463 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
464 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
465 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
466 /// Returns `Self`, given the contents of `mercurial/configitems.toml` |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
467 #[logging_timer::time("trace")] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
468 pub fn from_contents(contents: &str) -> Result<Self, HgError> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
469 let mut from_file: ConfigItems = |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
470 toml::from_str(contents).map_err(|e| { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
471 HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
472 e.to_string(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
473 exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
474 Some("Check 'mercurial/configitems.toml'".into()), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
475 ) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
476 })?; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
477 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
478 let mut flat_items = from_file.items; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
479 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
480 for application in from_file.template_applications.drain(..) { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
481 match from_file.templates.get(&application.template) { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
482 None => return Err( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
483 HgError::abort( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
484 format!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
485 "template application refers to undefined template '{}'", |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
486 application.template |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
487 ), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
488 exit_codes::ABORT, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
489 Some("Check 'mercurial/configitems.toml'".into()) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
490 ) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
491 ), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
492 Some(template_items) => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
493 for template_item in template_items { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
494 flat_items.push( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
495 template_item |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
496 .clone() |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
497 .into_default_item(application.clone()), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
498 ) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
499 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
500 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
501 }; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
502 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
503 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
504 let items = flat_items.into_iter().fold( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
505 FastHashMap::default(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
506 |mut acc, item| { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
507 acc.entry(item.section.to_owned()) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
508 .or_insert_with(|| { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
509 let mut section = FastHashMap::default(); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
510 section.insert(item.name.to_owned(), item.to_owned()); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
511 section |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
512 }) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
513 .insert(item.name.to_owned(), item); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
514 acc |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
515 }, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
516 ); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
517 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
518 Ok(Self { items }) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
519 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
520 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
521 /// Return the default config item that matches `section` and `item`. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
522 pub fn get( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
523 &self, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
524 section: &[u8], |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
525 item: &[u8], |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
526 ) -> Option<&DefaultConfigItem> { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
527 // Core items must be valid UTF-8 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
528 let section = String::from_utf8_lossy(section); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
529 let section_map = self.items.get(section.as_ref())?; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
530 let item_name_lossy = String::from_utf8_lossy(item); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
531 match section_map.get(item_name_lossy.as_ref()) { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
532 Some(item) => Some(item), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
533 None => { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
534 for generic_item in section_map |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
535 .values() |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
536 .filter(|item| item.is_generic()) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
537 .sorted_by_key(|item| match item.priority { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
538 Some(priority) => (priority, &item.name), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
539 _ => unreachable!(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
540 }) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
541 { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
542 if regex::bytes::Regex::new(&generic_item.name) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
543 .expect("invalid regex in configitems") |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
544 .is_match(item) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
545 { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
546 return Some(generic_item); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
547 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
548 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
549 None |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
550 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
551 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
552 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
553 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
554 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
555 #[cfg(test)] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
556 mod tests { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
557 use crate::config::config_items::{ |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
558 DefaultConfigItem, DefaultConfigItemType, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
559 }; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
560 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
561 use super::DefaultConfig; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
562 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
563 #[test] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
564 fn test_config_read() { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
565 let contents = r#" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
566 [[items]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
567 section = "alias" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
568 name = "abcd.*" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
569 default = 3 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
570 generic = true |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
571 priority = -1 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
572 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
573 [[items]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
574 section = "alias" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
575 name = ".*" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
576 default-type = "dynamic" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
577 generic = true |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
578 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
579 [[items]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
580 section = "cmdserver" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
581 name = "track-log" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
582 default-type = "lambda" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
583 default = [ "chgserver", "cmdserver", "repocache",] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
584 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
585 [[items]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
586 section = "chgserver" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
587 name = "idletimeout" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
588 default = 3600 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
589 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
590 [[items]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
591 section = "cmdserver" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
592 name = "message-encodings" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
593 default-type = "list_type" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
594 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
595 [[items]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
596 section = "web" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
597 name = "encoding" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
598 default-type = "lazy_module" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
599 default = "encoding.encoding" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
600 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
601 [[items]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
602 section = "command-templates" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
603 name = "graphnode" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
604 alias = [["ui", "graphnodetemplate"]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
605 documentation = """This is a docstring. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
606 This is another line \ |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
607 but this is not.""" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
608 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
609 [[items]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
610 section = "censor" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
611 name = "policy" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
612 default = "abort" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
613 experimental = true |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
614 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
615 [[template-applications]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
616 template = "diff-options" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
617 section = "commands" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
618 prefix = "revert.interactive" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
619 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
620 [[template-applications]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
621 template = "diff-options" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
622 section = "diff" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
623 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
624 [templates] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
625 [[templates.diff-options]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
626 suffix = "nodates" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
627 default = false |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
628 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
629 [[templates.diff-options]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
630 suffix = "showfunc" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
631 default = false |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
632 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
633 [[templates.diff-options]] |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
634 suffix = "unified" |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
635 "#; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
636 let res = DefaultConfig::from_contents(contents); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
637 let config = match res { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
638 Ok(config) => config, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
639 Err(e) => panic!("{}", e), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
640 }; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
641 let expected = DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
642 section: "censor".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
643 name: "policy".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
644 default: Some(DefaultConfigItemType::Primitive("abort".into())), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
645 priority: None, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
646 alias: vec![], |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
647 experimental: true, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
648 documentation: "".into(), |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
649 in_core_extension: None, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
650 }; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
651 assert_eq!(config.get(b"censor", b"policy"), Some(&expected)); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
652 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
653 // Test generic priority. The `.*` pattern is wider than `abcd.*`, but |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
654 // `abcd.*` has priority, so it should match first. |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
655 let expected = DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
656 section: "alias".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
657 name: "abcd.*".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
658 default: Some(DefaultConfigItemType::Primitive(3.into())), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
659 priority: Some(-1), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
660 alias: vec![], |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
661 experimental: false, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
662 documentation: "".into(), |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
663 in_core_extension: None, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
664 }; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
665 assert_eq!(config.get(b"alias", b"abcdsomething"), Some(&expected)); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
666 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
667 //... but if it doesn't, we should fallback to `.*` |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
668 let expected = DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
669 section: "alias".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
670 name: ".*".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
671 default: Some(DefaultConfigItemType::Dynamic), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
672 priority: Some(0), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
673 alias: vec![], |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
674 experimental: false, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
675 documentation: "".into(), |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
676 in_core_extension: None, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
677 }; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
678 assert_eq!(config.get(b"alias", b"something"), Some(&expected)); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
679 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
680 let expected = DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
681 section: "chgserver".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
682 name: "idletimeout".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
683 default: Some(DefaultConfigItemType::Primitive(3600.into())), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
684 priority: None, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
685 alias: vec![], |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
686 experimental: false, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
687 documentation: "".into(), |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
688 in_core_extension: None, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
689 }; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
690 assert_eq!(config.get(b"chgserver", b"idletimeout"), Some(&expected)); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
691 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
692 let expected = DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
693 section: "cmdserver".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
694 name: "track-log".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
695 default: Some(DefaultConfigItemType::Lambda(vec![ |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
696 "chgserver".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
697 "cmdserver".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
698 "repocache".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
699 ])), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
700 priority: None, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
701 alias: vec![], |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
702 experimental: false, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
703 documentation: "".into(), |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
704 in_core_extension: None, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
705 }; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
706 assert_eq!(config.get(b"cmdserver", b"track-log"), Some(&expected)); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
707 |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
708 let expected = DefaultConfigItem { |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
709 section: "command-templates".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
710 name: "graphnode".into(), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
711 default: None, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
712 priority: None, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
713 alias: vec![("ui".into(), "graphnodetemplate".into())], |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
714 experimental: false, |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
715 documentation: |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
716 "This is a docstring.\nThis is another line but this is not." |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
717 .into(), |
50765
7f8f6fe13fa9
configitems: move blackbox's config items to the new configitems.toml
Raphaël Gomès <rgomes@octobus.net>
parents:
50763
diff
changeset
|
718 in_core_extension: None, |
50763
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
719 }; |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
720 assert_eq!( |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
721 config.get(b"command-templates", b"graphnode"), |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
722 Some(&expected) |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
723 ); |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
724 } |
f8412da86d05
rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
725 } |