changeset 46756:84a3deca963a

rhg: Silently ignore missing files in config %include … instead of aborting with an error message. This is what Python-based hg does. Differential Revision: https://phab.mercurial-scm.org/D10141
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 08 Mar 2021 19:07:29 +0100
parents 91ab5190a3de
children b1f2c2b336ec
files rust/hg-core/src/config/layer.rs
diffstat 1 files changed, 21 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/config/layer.rs	Mon Mar 08 15:35:32 2021 +0100
+++ b/rust/hg-core/src/config/layer.rs	Mon Mar 08 19:07:29 2021 +0100
@@ -160,20 +160,28 @@
                 // `Path::join` with an absolute argument correctly ignores the
                 // base path
                 let filename = dir.join(&get_path_from_bytes(&filename_bytes));
-                let data = std::fs::read(&filename).map_err(|io_error| {
-                    ConfigParseError {
-                        origin: ConfigOrigin::File(src.to_owned()),
-                        line,
-                        message: format_bytes!(
-                            b"cannot include {} ({})",
-                            filename_bytes,
-                            format_bytes::Utf8(io_error)
-                        ),
+                match std::fs::read(&filename) {
+                    Ok(data) => {
+                        layers.push(current_layer);
+                        layers.extend(Self::parse(&filename, &data)?);
+                        current_layer =
+                            Self::new(ConfigOrigin::File(src.to_owned()));
                     }
-                })?;
-                layers.push(current_layer);
-                layers.extend(Self::parse(&filename, &data)?);
-                current_layer = Self::new(ConfigOrigin::File(src.to_owned()));
+                    Err(error) => {
+                        if error.kind() != std::io::ErrorKind::NotFound {
+                            return Err(ConfigParseError {
+                                origin: ConfigOrigin::File(src.to_owned()),
+                                line,
+                                message: format_bytes!(
+                                    b"cannot include {} ({})",
+                                    filename_bytes,
+                                    format_bytes::Utf8(error)
+                                ),
+                            }
+                            .into());
+                        }
+                    }
+                }
             } else if let Some(_) = EMPTY_RE.captures(&bytes) {
             } else if let Some(m) = SECTION_RE.captures(&bytes) {
                 section = m[1].to_vec();