From 9918693037dce8aa4bb6f08741b6812923486c18 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 19 Jun 2024 11:26:03 +0200 Subject: Merging upstream version 1.76.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/gix-index/src/entry/mode.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'vendor/gix-index/src/entry/mode.rs') diff --git a/vendor/gix-index/src/entry/mode.rs b/vendor/gix-index/src/entry/mode.rs index 0301df438..fca861d2b 100644 --- a/vendor/gix-index/src/entry/mode.rs +++ b/vendor/gix-index/src/entry/mode.rs @@ -11,6 +11,12 @@ impl Mode { *self == Self::DIR | Self::SYMLINK } + /// Convert this instance to a tree's entry mode, or return `None` if for some + /// and unexpected reason the bitflags don't resemble any known entry-mode. + pub fn to_tree_entry_mode(&self) -> Option { + gix_object::tree::EntryMode::try_from(self.bits()).ok() + } + /// Compares this mode to the file system version ([`std::fs::symlink_metadata`]) /// and returns the change needed to update this mode to match the file. /// @@ -37,7 +43,7 @@ impl Mode { /// can not be committed to git). pub fn change_to_match_fs( self, - stat: &std::fs::Metadata, + stat: &crate::fs::Metadata, has_symlinks: bool, executable_bit: bool, ) -> Option { @@ -46,15 +52,13 @@ impl Mode { Mode::SYMLINK if has_symlinks && !stat.is_symlink() => (), Mode::SYMLINK if !has_symlinks && !stat.is_file() => (), Mode::COMMIT | Mode::DIR if !stat.is_dir() => (), - Mode::FILE if executable_bit && gix_fs::is_executable(stat) => return Some(Change::ExecutableBit), - Mode::FILE_EXECUTABLE if executable_bit && !gix_fs::is_executable(stat) => { - return Some(Change::ExecutableBit) - } + Mode::FILE if executable_bit && stat.is_executable() => return Some(Change::ExecutableBit), + Mode::FILE_EXECUTABLE if executable_bit && !stat.is_executable() => return Some(Change::ExecutableBit), _ => return None, }; let new_mode = if stat.is_dir() { Mode::COMMIT - } else if executable_bit && gix_fs::is_executable(stat) { + } else if executable_bit && stat.is_executable() { Mode::FILE_EXECUTABLE } else { Mode::FILE -- cgit v1.2.3