##// END OF EJS Templates
rhg: split non_repo_config and `--config` loading in different functions...
Pulkit Goyal -
r48198:3237ed4d default
parent child Browse files
Show More
@@ -88,9 +88,7 b' impl Config {'
88 /// Load system and user configuration from various files.
88 /// Load system and user configuration from various files.
89 ///
89 ///
90 /// This is also affected by some environment variables.
90 /// This is also affected by some environment variables.
91 pub fn load(
91 pub fn load_non_repo() -> Result<Self, ConfigError> {
92 cli_config_args: impl IntoIterator<Item = impl AsRef<[u8]>>,
93 ) -> Result<Self, ConfigError> {
94 let mut config = Self { layers: Vec::new() };
92 let mut config = Self { layers: Vec::new() };
95 let opt_rc_path = env::var_os("HGRCPATH");
93 let opt_rc_path = env::var_os("HGRCPATH");
96 // HGRCPATH replaces system config
94 // HGRCPATH replaces system config
@@ -133,10 +131,17 b' impl Config {'
133 }
131 }
134 }
132 }
135 }
133 }
134 Ok(config)
135 }
136
137 pub fn load_cli_args_config(
138 &mut self,
139 cli_config_args: impl IntoIterator<Item = impl AsRef<[u8]>>,
140 ) -> Result<(), ConfigError> {
136 if let Some(layer) = ConfigLayer::parse_cli_args(cli_config_args)? {
141 if let Some(layer) = ConfigLayer::parse_cli_args(cli_config_args)? {
137 config.layers.push(layer)
142 self.layers.push(layer)
138 }
143 }
139 Ok(config)
144 Ok(())
140 }
145 }
141
146
142 fn add_trusted_dir(&mut self, path: &Path) -> Result<(), ConfigError> {
147 fn add_trusted_dir(&mut self, path: &Path) -> Result<(), ConfigError> {
@@ -126,8 +126,8 b' fn main() {'
126 })
126 })
127 });
127 });
128
128
129 let non_repo_config =
129 let mut non_repo_config =
130 Config::load(early_args.config).unwrap_or_else(|error| {
130 Config::load_non_repo().unwrap_or_else(|error| {
131 // Normally this is decided based on config, but we don’t have that
131 // Normally this is decided based on config, but we don’t have that
132 // available. As of this writing config loading never returns an
132 // available. As of this writing config loading never returns an
133 // "unsupported" error but that is not enforced by the type system.
133 // "unsupported" error but that is not enforced by the type system.
@@ -142,6 +142,20 b' fn main() {'
142 )
142 )
143 });
143 });
144
144
145 non_repo_config
146 .load_cli_args_config(early_args.config)
147 .unwrap_or_else(|error| {
148 exit(
149 &initial_current_dir,
150 &ui,
151 OnUnsupported::from_config(&ui, &non_repo_config),
152 Err(error.into()),
153 non_repo_config
154 .get_bool(b"ui", b"detailed-exit-code")
155 .unwrap_or(false),
156 )
157 });
158
145 if let Some(repo_path_bytes) = &early_args.repo {
159 if let Some(repo_path_bytes) = &early_args.repo {
146 lazy_static::lazy_static! {
160 lazy_static::lazy_static! {
147 static ref SCHEME_RE: regex::bytes::Regex =
161 static ref SCHEME_RE: regex::bytes::Regex =
General Comments 0
You need to be logged in to leave comments. Login now