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
--- 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)?
}