From c23a457e72abe608715ac76f076f47dc42af07a5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 20:31:44 +0200 Subject: Merging upstream version 1.74.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/gix-path/src/convert.rs | 5 ++-- vendor/gix-path/src/env/git.rs | 3 ++- vendor/gix-path/src/lib.rs | 7 ------ vendor/gix-path/src/realpath.rs | 7 +++--- vendor/gix-path/src/spec.rs | 53 ----------------------------------------- 5 files changed, 7 insertions(+), 68 deletions(-) delete mode 100644 vendor/gix-path/src/spec.rs (limited to 'vendor/gix-path/src') diff --git a/vendor/gix-path/src/convert.rs b/vendor/gix-path/src/convert.rs index d8bf70353..445255757 100644 --- a/vendor/gix-path/src/convert.rs +++ b/vendor/gix-path/src/convert.rs @@ -239,6 +239,7 @@ pub fn to_windows_separators<'a>(path: impl Into>) -> Cow<'a, BStr /// Resolve relative components virtually without accessing the file system, e.g. turn `a/./b/c/.././..` into `a`, /// without keeping intermediate `..` and `/a/../b/..` becomes `/`. /// If the input path was relative and ends up being the `current_dir`, `.` is returned instead of the full path to `current_dir`. +/// Note that single `.` components as well as duplicate separators are left untouched. /// /// This is particularly useful when manipulating paths that are based on user input, and not resolving intermediate /// symlinks keeps the path similar to what the user provided. If that's not desirable, use `[realpath()][crate::realpath()` @@ -248,14 +249,12 @@ pub fn to_windows_separators<'a>(path: impl Into>) -> Cow<'a, BStr /// as typical return value of `std::env::current_dir()`. /// As a `current_dir` like `/c` can be exhausted by paths like `../../r`, `None` will be returned to indicate the inability /// to produce a logically consistent path. -pub fn normalize<'a>(path: impl Into>, current_dir: impl AsRef) -> Option> { +pub fn normalize<'a>(path: Cow<'a, Path>, current_dir: &Path) -> Option> { use std::path::Component::ParentDir; - let path = path.into(); if !path.components().any(|c| matches!(c, ParentDir)) { return Some(path); } - let current_dir = current_dir.as_ref(); let mut current_dir_opt = Some(current_dir); let was_relative = path.is_relative(); let components = path.components(); diff --git a/vendor/gix-path/src/env/git.rs b/vendor/gix-path/src/env/git.rs index 2e5d867bb..b8a9bc0d5 100644 --- a/vendor/gix-path/src/env/git.rs +++ b/vendor/gix-path/src/env/git.rs @@ -8,6 +8,7 @@ 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(crate) fn install_config_path() -> Option<&'static BStr> { + let _span = gix_trace::detail!("gix_path::git::install_config_path()"); static PATH: once_cell::sync::Lazy> = once_cell::sync::Lazy::new(|| { // Shortcut: in Msys shells this variable is set which allows to deduce the installation directory // so we can save the `git` invocation. @@ -23,7 +24,7 @@ pub(crate) fn install_config_path() -> Option<&'static BStr> { .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()) + PATH.as_ref().map(AsRef::as_ref) } fn first_file_from_config_with_origin(source: &BStr) -> Option<&BStr> { diff --git a/vendor/gix-path/src/lib.rs b/vendor/gix-path/src/lib.rs index 6895aca46..888141d3c 100644 --- a/vendor/gix-path/src/lib.rs +++ b/vendor/gix-path/src/lib.rs @@ -50,19 +50,12 @@ #![forbid(unsafe_code)] /// A dummy type to represent path specs and help finding all spots that take path specs once it is implemented. - -/// A preliminary version of a path-spec based on glances of the code. -#[derive(Clone, Debug)] -pub struct Spec(bstr::BString); - mod convert; pub use convert::*; mod util; pub use util::is_absolute; -mod spec; - /// pub mod realpath; pub use realpath::function::{realpath, realpath_opts}; diff --git a/vendor/gix-path/src/realpath.rs b/vendor/gix-path/src/realpath.rs index 8b88eb15e..2969bd4d7 100644 --- a/vendor/gix-path/src/realpath.rs +++ b/vendor/gix-path/src/realpath.rs @@ -31,19 +31,18 @@ pub(crate) mod function { /// /// If `path` is relative, the current working directory be used to make it absolute. pub fn realpath(path: impl AsRef) -> Result { + let path = path.as_ref(); let cwd = path - .as_ref() .is_relative() .then(std::env::current_dir) .unwrap_or_else(|| Ok(PathBuf::default())) .map_err(Error::CurrentWorkingDir)?; - realpath_opts(path, cwd, MAX_SYMLINKS) + realpath_opts(path, &cwd, MAX_SYMLINKS) } /// The same as [`realpath()`], but allow to configure `max_symlinks` to configure how many symbolic links we are going to follow. /// This serves to avoid running into cycles or doing unreasonable amounts of work. - pub fn realpath_opts(path: impl AsRef, cwd: impl AsRef, max_symlinks: u8) -> Result { - let path = path.as_ref(); + pub fn realpath_opts(path: &Path, cwd: &Path, max_symlinks: u8) -> Result { if path.as_os_str().is_empty() { return Err(Error::EmptyPath); } diff --git a/vendor/gix-path/src/spec.rs b/vendor/gix-path/src/spec.rs deleted file mode 100644 index 0ff9e661c..000000000 --- a/vendor/gix-path/src/spec.rs +++ /dev/null @@ -1,53 +0,0 @@ -use std::ffi::OsStr; - -use bstr::{BStr, ByteSlice, ByteVec}; - -use crate::Spec; - -impl std::convert::TryFrom<&OsStr> for Spec { - type Error = crate::Utf8Error; - - fn try_from(value: &OsStr) -> Result { - crate::os_str_into_bstr(value).map(|value| { - assert_valid_hack(value); - Spec(value.into()) - }) - } -} - -fn assert_valid_hack(input: &BStr) { - assert!(!input.contains_str(b"/../")); - assert!(!input.contains_str(b"/./")); - assert!(!input.starts_with_str(b"../")); - assert!(!input.starts_with_str(b"./")); - assert!(!input.starts_with_str(b"/")); -} - -impl Spec { - /// Parse `input` into a `Spec` or `None` if it could not be parsed - // TODO: tests, actual implementation probably via `gix-pathspec` to make use of the crate after all. - pub fn from_bytes(input: &BStr) -> Option { - assert_valid_hack(input); - Spec(input.into()).into() - } - /// Return all paths described by this path spec, using slashes on all platforms. - pub fn items(&self) -> impl Iterator { - std::iter::once(self.0.as_bstr()) - } - /// Adjust this path specification according to the given `prefix`, which may be empty to indicate we are the at work-tree root. - // TODO: this is a hack, needs test and time to do according to spec. This is just a minimum version to have -something-. - pub fn apply_prefix(&mut self, prefix: &std::path::Path) -> &Self { - // many more things we can't handle. `Path` never ends with trailing path separator. - let prefix = crate::into_bstr(prefix); - if !prefix.is_empty() { - let mut prefix = crate::to_unix_separators_on_windows(prefix); - { - let path = prefix.to_mut(); - path.push_byte(b'/'); - path.extend_from_slice(&self.0); - } - self.0 = prefix.into_owned(); - } - self - } -} -- cgit v1.2.3