diff options
Diffstat (limited to 'vendor/gix-fs/src')
-rw-r--r-- | vendor/gix-fs/src/capabilities.rs | 11 | ||||
-rw-r--r-- | vendor/gix-fs/src/dir/create.rs | 14 | ||||
-rw-r--r-- | vendor/gix-fs/src/dir/remove.rs | 3 | ||||
-rw-r--r-- | vendor/gix-fs/src/lib.rs | 18 | ||||
-rw-r--r-- | vendor/gix-fs/src/snapshot.rs | 26 | ||||
-rw-r--r-- | vendor/gix-fs/src/stack.rs | 10 |
6 files changed, 56 insertions, 26 deletions
diff --git a/vendor/gix-fs/src/capabilities.rs b/vendor/gix-fs/src/capabilities.rs index 2b51deacc..4c0d2f8d9 100644 --- a/vendor/gix-fs/src/capabilities.rs +++ b/vendor/gix-fs/src/capabilities.rs @@ -45,14 +45,13 @@ impl Capabilities { /// `git_dir` is a typical git repository, expected to be populated with the typical files like `config`. /// /// All errors are ignored and interpreted on top of the default for the platform the binary is compiled for. - pub fn probe(git_dir: impl AsRef<Path>) -> Self { - let root = git_dir.as_ref(); + pub fn probe(git_dir: &Path) -> Self { let ctx = Capabilities::default(); Capabilities { - symlink: Self::probe_symlink(root).unwrap_or(ctx.symlink), - ignore_case: Self::probe_ignore_case(root).unwrap_or(ctx.ignore_case), - precompose_unicode: Self::probe_precompose_unicode(root).unwrap_or(ctx.precompose_unicode), - executable_bit: Self::probe_file_mode(root).unwrap_or(ctx.executable_bit), + symlink: Self::probe_symlink(git_dir).unwrap_or(ctx.symlink), + ignore_case: Self::probe_ignore_case(git_dir).unwrap_or(ctx.ignore_case), + precompose_unicode: Self::probe_precompose_unicode(git_dir).unwrap_or(ctx.precompose_unicode), + executable_bit: Self::probe_file_mode(git_dir).unwrap_or(ctx.executable_bit), } } diff --git a/vendor/gix-fs/src/dir/create.rs b/vendor/gix-fs/src/dir/create.rs index 7c7c9a033..642629bfd 100644 --- a/vendor/gix-fs/src/dir/create.rs +++ b/vendor/gix-fs/src/dir/create.rs @@ -116,7 +116,7 @@ impl<'a> Iter<'a> { } impl<'a> Iter<'a> { - fn pernanent_failure( + fn permanent_failure( &mut self, dir: &'a Path, err: impl Into<std::io::Error>, @@ -151,24 +151,24 @@ impl<'a> Iterator for Iter<'a> { self.state = State::CurrentlyCreatingDirectories; Some(Ok(dir)) } - AlreadyExists => self.pernanent_failure(dir, err), // is non-directory + AlreadyExists => self.permanent_failure(dir, err), // is non-directory NotFound => { self.retries.on_create_directory_failure -= 1; if let State::CurrentlyCreatingDirectories = self.state { self.state = State::SearchingUpwardsForExistingDirectory; self.retries.to_create_entire_directory -= 1; if self.retries.to_create_entire_directory < 1 { - return self.pernanent_failure(dir, NotFound); + return self.permanent_failure(dir, NotFound); } self.retries.on_create_directory_failure = self.original_retries.on_create_directory_failure; } if self.retries.on_create_directory_failure < 1 { - return self.pernanent_failure(dir, NotFound); + return self.permanent_failure(dir, NotFound); }; self.cursors.push(dir); self.cursors.push(match dir.parent() { - None => return self.pernanent_failure(dir, InvalidInput), + None => return self.permanent_failure(dir, InvalidInput), Some(parent) => parent, }); self.intermediate_failure(dir, err) @@ -176,12 +176,12 @@ impl<'a> Iterator for Iter<'a> { Interrupted => { self.retries.on_interrupt -= 1; if self.retries.on_interrupt <= 1 { - return self.pernanent_failure(dir, Interrupted); + return self.permanent_failure(dir, Interrupted); }; self.cursors.push(dir); self.intermediate_failure(dir, err) } - _unexpected_kind => self.pernanent_failure(dir, err), + _unexpected_kind => self.permanent_failure(dir, err), }, }, None => None, diff --git a/vendor/gix-fs/src/dir/remove.rs b/vendor/gix-fs/src/dir/remove.rs index ac7b212fa..cb5bff47c 100644 --- a/vendor/gix-fs/src/dir/remove.rs +++ b/vendor/gix-fs/src/dir/remove.rs @@ -78,8 +78,7 @@ pub fn empty_upward_until_boundary<'a>(delete_dir: &'a Path, boundary_dir: &'a P /// If any encountered directory contains a file the entire operation is aborted. /// Please note that this is inherently racy and no attempts are made to counter that, which will allow creators to win /// as long as they retry. -pub fn empty_depth_first(delete_dir: impl Into<PathBuf>) -> std::io::Result<()> { - let delete_dir = delete_dir.into(); +pub fn empty_depth_first(delete_dir: PathBuf) -> std::io::Result<()> { if let Ok(()) = std::fs::remove_dir(&delete_dir) { return Ok(()); } diff --git a/vendor/gix-fs/src/lib.rs b/vendor/gix-fs/src/lib.rs index aa576c240..1a3168928 100644 --- a/vendor/gix-fs/src/lib.rs +++ b/vendor/gix-fs/src/lib.rs @@ -2,6 +2,8 @@ #![deny(rust_2018_idioms, missing_docs)] #![forbid(unsafe_code)] +use std::path::PathBuf; + /// Common knowledge about the worktree that is needed across most interactions with the work tree #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)] @@ -25,9 +27,6 @@ pub struct Capabilities { mod capabilities; mod snapshot; - -use std::path::PathBuf; - pub use snapshot::{FileSnapshot, SharedFileSnapshot, SharedFileSnapshotMut}; /// @@ -51,5 +50,18 @@ pub struct Stack { current_is_directory: bool, } +#[cfg(unix)] +/// Returns whether a a file has the executable permission set. +pub fn is_executable(metadata: &std::fs::Metadata) -> bool { + use std::os::unix::fs::MetadataExt; + (metadata.mode() & 0o100) != 0 +} + +#[cfg(not(unix))] +/// Returns whether a a file has the executable permission set. +pub fn is_executable(_metadata: &std::fs::Metadata) -> bool { + false +} + /// pub mod stack; diff --git a/vendor/gix-fs/src/snapshot.rs b/vendor/gix-fs/src/snapshot.rs index 02a0ec843..2b21d0d9f 100644 --- a/vendor/gix-fs/src/snapshot.rs +++ b/vendor/gix-fs/src/snapshot.rs @@ -10,6 +10,26 @@ pub struct FileSnapshot<T: std::fmt::Debug> { modified: std::time::SystemTime, } +/// Lifecycle +impl<T: std::fmt::Debug> FileSnapshot<T> { + /// A way for users to create 'fake' snapshot from `value` that isn't actually linked to a file on disk. + /// + /// This is useful if there are alternative ways of obtaining the contained instance as fallback to trying + /// to read it from disk. + pub fn new(value: T) -> Self { + FileSnapshot { + value, + modified: std::time::UNIX_EPOCH, + } + } +} + +impl<T: std::fmt::Debug> From<T> for FileSnapshot<T> { + fn from(value: T) -> Self { + FileSnapshot::new(value) + } +} + impl<T: Clone + std::fmt::Debug> Clone for FileSnapshot<T> { fn clone(&self) -> Self { Self { @@ -37,6 +57,12 @@ impl<T: std::fmt::Debug> Deref for FileSnapshot<T> { } } +impl<T: std::fmt::Debug> std::ops::DerefMut for FileSnapshot<T> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.value + } +} + impl<T: std::fmt::Debug> Deref for SharedFileSnapshotMut<T> { type Target = MutableOnDemand<Option<SharedFileSnapshot<T>>>; diff --git a/vendor/gix-fs/src/stack.rs b/vendor/gix-fs/src/stack.rs index 163c14464..d90d662ca 100644 --- a/vendor/gix-fs/src/stack.rs +++ b/vendor/gix-fs/src/stack.rs @@ -42,8 +42,7 @@ pub trait Delegate { impl Stack { /// Create a new instance with `root` being the base for all future paths we handle, assuming it to be valid which includes /// symbolic links to be included in it as well. - pub fn new(root: impl Into<PathBuf>) -> Self { - let root = root.into(); + pub fn new(root: PathBuf) -> Self { Stack { current: root.clone(), current_relative: PathBuf::with_capacity(128), @@ -59,12 +58,7 @@ impl Stack { /// The full path to `relative` will be returned along with the data returned by `push_comp`. /// Note that this only works correctly for the delegate's `push_directory()` and `pop_directory()` methods if /// `relative` paths are terminal, so point to their designated file or directory. - pub fn make_relative_path_current( - &mut self, - relative: impl AsRef<Path>, - delegate: &mut impl Delegate, - ) -> std::io::Result<()> { - let relative = relative.as_ref(); + pub fn make_relative_path_current(&mut self, relative: &Path, delegate: &mut dyn Delegate) -> std::io::Result<()> { debug_assert!( relative.is_relative(), "only index paths are handled correctly here, must be relative" |