summaryrefslogtreecommitdiffstats
path: root/vendor/gix-config/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/gix-config/src
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-config/src')
-rw-r--r--vendor/gix-config/src/file/access/raw.rs2
-rw-r--r--vendor/gix-config/src/file/init/comfort.rs16
-rw-r--r--vendor/gix-config/src/file/init/from_paths.rs53
-rw-r--r--vendor/gix-config/src/file/init/types.rs4
-rw-r--r--vendor/gix-config/src/file/section/body.rs2
-rw-r--r--vendor/gix-config/src/parse/events.rs2
-rw-r--r--vendor/gix-config/src/parse/mod.rs2
-rw-r--r--vendor/gix-config/src/source.rs91
8 files changed, 73 insertions, 99 deletions
diff --git a/vendor/gix-config/src/file/access/raw.rs b/vendor/gix-config/src/file/access/raw.rs
index 46f1fb006..44b318f24 100644
--- a/vendor/gix-config/src/file/access/raw.rs
+++ b/vendor/gix-config/src/file/access/raw.rs
@@ -136,7 +136,7 @@ impl<'event> File<'event> {
/// ain order of occurrence.
///
/// The ordering means that the last of the returned values is the one that would be the
- /// value used in the single-value case.nd key.
+ /// value used in the single-value case.and key.
///
/// # Examples
///
diff --git a/vendor/gix-config/src/file/init/comfort.rs b/vendor/gix-config/src/file/init/comfort.rs
index ffe859a1a..aa77fb9c0 100644
--- a/vendor/gix-config/src/file/init/comfort.rs
+++ b/vendor/gix-config/src/file/init/comfort.rs
@@ -1,5 +1,3 @@
-use std::path::PathBuf;
-
use crate::{
file::{init, Metadata},
path, source, File, Source,
@@ -30,7 +28,7 @@ impl File<'static> {
.flat_map(|kind| kind.sources())
.filter_map(|source| {
let path = source
- .storage_location(&mut |name| std::env::var_os(name))
+ .storage_location(&mut gix_path::env::var)
.and_then(|p| p.is_file().then_some(p))
.map(|p| p.into_owned());
@@ -43,7 +41,7 @@ impl File<'static> {
.into()
});
- let home = std::env::var("HOME").ok().map(PathBuf::from);
+ let home = gix_path::env::home_dir();
let options = init::Options {
includes: init::includes::Options::follow_without_conditional(home.as_deref()),
..Default::default()
@@ -59,7 +57,7 @@ impl File<'static> {
///
/// [`gix-config`'s documentation]: https://git-scm.com/docs/gix-config#Documentation/gix-config.txt-GITCONFIGCOUNT
pub fn from_environment_overrides() -> Result<File<'static>, init::from_env::Error> {
- let home = std::env::var("HOME").ok().map(PathBuf::from);
+ let home = gix_path::env::home_dir();
let options = init::Options {
includes: init::includes::Options::follow_without_conditional(home.as_deref()),
..Default::default()
@@ -88,7 +86,7 @@ impl File<'static> {
let mut path = dir.into();
path.push(
source
- .storage_location(&mut |n| std::env::var_os(n))
+ .storage_location(&mut gix_path::env::var)
.expect("location available for local"),
);
let local = Self::from_path_no_includes(&path, source)?;
@@ -101,7 +99,7 @@ impl File<'static> {
let source = Source::Worktree;
let path = git_dir.join(
source
- .storage_location(&mut |n| std::env::var_os(n))
+ .storage_location(&mut gix_path::env::var)
.expect("location available for worktree"),
);
Self::from_path_no_includes(path, source)
@@ -110,7 +108,7 @@ impl File<'static> {
}
.transpose()?;
- let home = std::env::var("HOME").ok().map(PathBuf::from);
+ let home = gix_path::env::home_dir();
let options = init::Options {
includes: init::includes::Options::follow(
path::interpolate::Context {
@@ -122,7 +120,7 @@ impl File<'static> {
branch_name: None,
},
),
- lossy: false,
+ ..Default::default()
};
let mut globals = Self::from_globals()?;
diff --git a/vendor/gix-config/src/file/init/from_paths.rs b/vendor/gix-config/src/file/init/from_paths.rs
index 5d671b69e..73737075e 100644
--- a/vendor/gix-config/src/file/init/from_paths.rs
+++ b/vendor/gix-config/src/file/init/from_paths.rs
@@ -9,8 +9,11 @@ use crate::{
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
- #[error(transparent)]
- Io(#[from] std::io::Error),
+ #[error("The configuration file at \"{}\" could not be read", path.display())]
+ Io {
+ source: std::io::Error,
+ path: std::path::PathBuf,
+ },
#[error(transparent)]
Init(#[from] init::Error),
}
@@ -22,10 +25,22 @@ impl File<'static> {
/// Note that the path will be checked for ownership to derive trust.
pub fn from_path_no_includes(path: impl Into<std::path::PathBuf>, source: crate::Source) -> Result<Self, Error> {
let path = path.into();
- let trust = gix_sec::Trust::from_path_ownership(&path)?;
+ let trust = match gix_sec::Trust::from_path_ownership(&path) {
+ Ok(t) => t,
+ Err(err) => return Err(Error::Io { source: err, path }),
+ };
let mut buf = Vec::new();
- std::io::copy(&mut std::fs::File::open(&path)?, &mut buf)?;
+ match std::io::copy(
+ &mut match std::fs::File::open(&path) {
+ Ok(f) => f,
+ Err(err) => return Err(Error::Io { source: err, path }),
+ },
+ &mut buf,
+ ) {
+ Ok(_) => {}
+ Err(err) => return Err(Error::Io { source: err, path }),
+ }
Ok(File::from_bytes_owned(
&mut buf,
@@ -69,14 +84,38 @@ impl File<'static> {
}
buf.clear();
- std::io::copy(
+ match std::io::copy(
&mut match std::fs::File::open(&path) {
Ok(f) => f,
Err(err) if !err_on_non_existing_paths && err.kind() == std::io::ErrorKind::NotFound => continue,
- Err(err) => return Err(err.into()),
+ Err(err) => {
+ let err = Error::Io { source: err, path };
+ if options.ignore_io_errors {
+ log::warn!("ignoring: {err:#?}");
+ continue;
+ } else {
+ return Err(err);
+ }
+ }
},
buf,
- )?;
+ ) {
+ Ok(_) => {}
+ Err(err) => {
+ if options.ignore_io_errors {
+ log::warn!(
+ "ignoring: {:#?}",
+ Error::Io {
+ source: err,
+ path: path.clone()
+ }
+ );
+ buf.clear();
+ } else {
+ return Err(Error::Io { source: err, path });
+ }
+ }
+ };
meta.path = Some(path);
let config = Self::from_bytes_owned(buf, meta, options)?;
diff --git a/vendor/gix-config/src/file/init/types.rs b/vendor/gix-config/src/file/init/types.rs
index fcb17c0ca..952d1910b 100644
--- a/vendor/gix-config/src/file/init/types.rs
+++ b/vendor/gix-config/src/file/init/types.rs
@@ -22,6 +22,10 @@ pub struct Options<'a> {
/// Note that doing so will degenerate [`write_to()`][crate::File::write_to()] and strip it off its comments
/// and additional whitespace entirely, but will otherwise be a valid configuration file.
pub lossy: bool,
+ /// If true, any IO error happening when reading a configuration file will be ignored.
+ ///
+ /// That way it's possible to pass multiple files and read as many as possible, to have 'something' instead of nothing.
+ pub ignore_io_errors: bool,
}
impl Options<'_> {
diff --git a/vendor/gix-config/src/file/section/body.rs b/vendor/gix-config/src/file/section/body.rs
index e1a53efd9..ad196d133 100644
--- a/vendor/gix-config/src/file/section/body.rs
+++ b/vendor/gix-config/src/file/section/body.rs
@@ -121,7 +121,7 @@ impl<'event> Body<'event> {
&self.0
}
- /// Returns the the range containing the value events for the `key`, with value range being `None` if there is no key-value separator
+ /// Returns the range containing the value events for the `key`, with value range being `None` if there is no key-value separator
/// and only a 'fake' Value event with an empty string in side.
/// If the value is not found, `None` is returned.
pub(crate) fn key_and_value_range_by(&self, key: &Key<'_>) -> Option<(Range<usize>, Option<Range<usize>>)> {
diff --git a/vendor/gix-config/src/parse/events.rs b/vendor/gix-config/src/parse/events.rs
index 62f621b52..24bb45253 100644
--- a/vendor/gix-config/src/parse/events.rs
+++ b/vendor/gix-config/src/parse/events.rs
@@ -51,7 +51,7 @@ pub type FrontMatterEvents<'a> = SmallVec<[Event<'a>; 8]>;
/// - Only equal signs (optionally padded by spaces) are valid name/value
/// delimiters.
///
-/// Note that that things such as case-sensitivity or duplicate sections are
+/// Note that things such as case-sensitivity or duplicate sections are
/// _not_ handled. This parser is a low level _syntactic_ interpreter
/// and higher level wrappers around this parser, which may
/// or may not be zero-copy, should handle _semantic_ values. This also means
diff --git a/vendor/gix-config/src/parse/mod.rs b/vendor/gix-config/src/parse/mod.rs
index 50363873c..e943a22b4 100644
--- a/vendor/gix-config/src/parse/mod.rs
+++ b/vendor/gix-config/src/parse/mod.rs
@@ -57,7 +57,7 @@ pub enum Event<'a> {
/// A completed value. This may be any single-line string, including the empty string
/// if an implicit boolean value is used.
/// Note that these values may contain spaces and any special character. This value is
- /// also unprocessed, so it it may contain double quotes that should be
+ /// also unprocessed, so it may contain double quotes that should be
/// [normalized][crate::value::normalize()] before interpretation.
Value(Cow<'a, BStr>),
/// Represents any token used to signify a newline character. On Unix
diff --git a/vendor/gix-config/src/source.rs b/vendor/gix-config/src/source.rs
index b1991e6b4..d8ca60db4 100644
--- a/vendor/gix-config/src/source.rs
+++ b/vendor/gix-config/src/source.rs
@@ -55,7 +55,7 @@ impl Source {
/// Returns the location at which a file of this type would be stored, or `None` if
/// there is no notion of persistent storage for this source, with `env_var` to obtain environment variables.
/// Note that the location can be relative for repository-local sources like `Local` and `Worktree`,
- /// and the caller has to known which base it it relative to, namely the `common_dir` in the `Local` case
+ /// and the caller has to known which base it is relative to, namely the `common_dir` in the `Local` case
/// and the `git_dir` in the `Worktree` case.
/// Be aware that depending on environment overrides, multiple scopes might return the same path, which should
/// only be loaded once nonetheless.
@@ -65,29 +65,19 @@ impl Source {
pub fn storage_location(self, env_var: &mut dyn FnMut(&str) -> Option<OsString>) -> Option<Cow<'static, Path>> {
use Source::*;
match self {
- GitInstallation => git::install_config_path().map(gix_path::from_bstr),
- System => env_var("GIT_CONFIG_NO_SYSTEM")
- .is_none()
- .then(|| PathBuf::from(env_var("GIT_CONFIG_SYSTEM").unwrap_or_else(|| "/etc/gitconfig".into())).into()),
+ GitInstallation => gix_path::env::installation_config().map(Into::into),
+ System => {
+ if env_var("GIT_CONFIG_NO_SYSTEM").is_some() {
+ None
+ } else {
+ env_var("GIT_CONFIG_SYSTEM")
+ .map(|p| Cow::Owned(p.into()))
+ .or_else(|| gix_path::env::system_prefix().map(|p| p.join("etc/gitconfig").into()))
+ }
+ }
Git => match env_var("GIT_CONFIG_GLOBAL") {
Some(global_override) => Some(PathBuf::from(global_override).into()),
- None => env_var("XDG_CONFIG_HOME")
- .map(|home| {
- let mut p = PathBuf::from(home);
- p.push("git");
- p.push("config");
- p
- })
- .or_else(|| {
- env_var("HOME").map(|home| {
- let mut p = PathBuf::from(home);
- p.push(".config");
- p.push("git");
- p.push("config");
- p
- })
- })
- .map(Cow::Owned),
+ None => gix_path::env::xdg_config("config", env_var).map(Cow::Owned),
},
User => env_var("GIT_CONFIG_GLOBAL")
.map(|global_override| PathBuf::from(global_override).into())
@@ -104,60 +94,3 @@ impl Source {
}
}
}
-
-/// Environment information involving the `git` program itself.
-mod git {
- use std::process::{Command, Stdio};
-
- use bstr::{BStr, BString, ByteSlice};
-
- /// Returns the file that contains git configuration coming with the installation of the `git` file in the current `PATH`, or `None`
- /// if no `git` executable was found or there were other errors during execution.
- pub fn install_config_path() -> Option<&'static BStr> {
- static PATH: once_cell::sync::Lazy<Option<BString>> = once_cell::sync::Lazy::new(|| {
- let mut cmd = Command::new(if cfg!(windows) { "git.exe" } else { "git" });
- cmd.args(["config", "-l", "--show-origin"])
- .stdin(Stdio::null())
- .stderr(Stdio::null());
- first_file_from_config_with_origin(cmd.output().ok()?.stdout.as_slice().into()).map(ToOwned::to_owned)
- });
- PATH.as_ref().map(|b| b.as_ref())
- }
-
- fn first_file_from_config_with_origin(source: &BStr) -> Option<&BStr> {
- let file = source.strip_prefix(b"file:")?;
- let end_pos = file.find_byte(b'\t')?;
- file[..end_pos].as_bstr().into()
- }
-
- #[cfg(test)]
- mod tests {
- #[test]
- fn first_file_from_config_with_origin() {
- let macos = "file:/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig credential.helper=osxkeychain\nfile:/Users/byron/.gitconfig push.default=simple\n";
- let win_msys =
- "file:C:/git-sdk-64/etc/gitconfig core.symlinks=false\r\nfile:C:/git-sdk-64/etc/gitconfig core.autocrlf=true";
- let win_cmd = "file:C:/Program Files/Git/etc/gitconfig diff.astextplain.textconv=astextplain\r\nfile:C:/Program Files/Git/etc/gitconfig filter.lfs.clean=gix-lfs clean -- %f\r\n";
- let linux = "file:/home/parallels/.gitconfig core.excludesfile=~/.gitignore\n";
- let bogus = "something unexpected";
- let empty = "";
-
- for (source, expected) in [
- (
- macos,
- Some("/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig"),
- ),
- (win_msys, Some("C:/git-sdk-64/etc/gitconfig")),
- (win_cmd, Some("C:/Program Files/Git/etc/gitconfig")),
- (linux, Some("/home/parallels/.gitconfig")),
- (bogus, None),
- (empty, None),
- ] {
- assert_eq!(
- super::first_file_from_config_with_origin(source.into()),
- expected.map(Into::into)
- );
- }
- }
- }
-}