rhg: Sort config files when adding a directory
authorSimon Sapin <simon.sapin@octobus.net>
Wed, 03 Mar 2021 20:02:07 +0100
changeset 46732 60fe9ebae29b
parent 46731 3d692e724d06
child 46733 1bac7764ceef
rhg: Sort config files when adding a directory For example in `/etc/mercurial/hgrc.d/` or with `HGRCPATH=some-directory`. Previously files where parsed in the order returned by the filesystem, which is undefined. But order is significant when multiple files define the same configuration key: the "last" one wins. Differential Revision: https://phab.mercurial-scm.org/D10111
rust/hg-core/src/config/config.rs
--- a/rust/hg-core/src/config/config.rs	Wed Mar 03 19:47:48 2021 +0100
+++ b/rust/hg-core/src/config/config.rs	Wed Mar 03 20:02:07 2021 +0100
@@ -125,8 +125,13 @@
             .when_reading_file(path)
             .io_not_found_as_none()?
         {
-            for entry in entries {
-                let file_path = entry.when_reading_file(path)?.path();
+            let mut file_paths = entries
+                .map(|result| {
+                    result.when_reading_file(path).map(|entry| entry.path())
+                })
+                .collect::<Result<Vec<_>, _>>()?;
+            file_paths.sort();
+            for file_path in &file_paths {
                 if file_path.extension() == Some(std::ffi::OsStr::new("rc")) {
                     self.add_trusted_file(&file_path)?
                 }