summaryrefslogtreecommitdiffstats
path: root/vendor/gix-index/src/entry/mode.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/gix-index/src/entry/mode.rs
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-index/src/entry/mode.rs')
-rw-r--r--vendor/gix-index/src/entry/mode.rs16
1 files changed, 10 insertions, 6 deletions
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> {
+ 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<Change> {
@@ -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