[Updated] D10837: rhg: split non_repo_config and `--config` loading in different functions

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Fri Jun 11 07:46:16 UTC 2021


Closed by commit rHG3237ed4dcda4: rhg: split non_repo_config and `--config` loading in different functions (authored by pulkit).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D10837?vs=28536&id=28545

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D10837/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D10837

AFFECTED FILES
  rust/hg-core/src/config/config.rs
  rust/rhg/src/main.rs

CHANGE DETAILS

diff --git a/rust/rhg/src/main.rs b/rust/rhg/src/main.rs
--- a/rust/rhg/src/main.rs
+++ b/rust/rhg/src/main.rs
@@ -126,8 +126,8 @@
             })
     });
 
-    let non_repo_config =
-        Config::load(early_args.config).unwrap_or_else(|error| {
+    let mut non_repo_config =
+        Config::load_non_repo().unwrap_or_else(|error| {
             // Normally this is decided based on config, but we don’t have that
             // available. As of this writing config loading never returns an
             // "unsupported" error but that is not enforced by the type system.
@@ -142,6 +142,20 @@
             )
         });
 
+    non_repo_config
+        .load_cli_args_config(early_args.config)
+        .unwrap_or_else(|error| {
+            exit(
+                &initial_current_dir,
+                &ui,
+                OnUnsupported::from_config(&ui, &non_repo_config),
+                Err(error.into()),
+                non_repo_config
+                    .get_bool(b"ui", b"detailed-exit-code")
+                    .unwrap_or(false),
+            )
+        });
+
     if let Some(repo_path_bytes) = &early_args.repo {
         lazy_static::lazy_static! {
             static ref SCHEME_RE: regex::bytes::Regex =
diff --git a/rust/hg-core/src/config/config.rs b/rust/hg-core/src/config/config.rs
--- a/rust/hg-core/src/config/config.rs
+++ b/rust/hg-core/src/config/config.rs
@@ -88,9 +88,7 @@
     /// Load system and user configuration from various files.
     ///
     /// This is also affected by some environment variables.
-    pub fn load(
-        cli_config_args: impl IntoIterator<Item = impl AsRef<[u8]>>,
-    ) -> Result<Self, ConfigError> {
+    pub fn load_non_repo() -> Result<Self, ConfigError> {
         let mut config = Self { layers: Vec::new() };
         let opt_rc_path = env::var_os("HGRCPATH");
         // HGRCPATH replaces system config
@@ -133,10 +131,17 @@
                 }
             }
         }
+        Ok(config)
+    }
+
+    pub fn load_cli_args_config(
+        &mut self,
+        cli_config_args: impl IntoIterator<Item = impl AsRef<[u8]>>,
+    ) -> Result<(), ConfigError> {
         if let Some(layer) = ConfigLayer::parse_cli_args(cli_config_args)? {
-            config.layers.push(layer)
+            self.layers.push(layer)
         }
-        Ok(config)
+        Ok(())
     }
 
     fn add_trusted_dir(&mut self, path: &Path) -> Result<(), ConfigError> {



To: pulkit, #hg-reviewers, SimonSapin, Alphare
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20210611/ece7c641/attachment-0002.html>


More information about the Mercurial-patches mailing list