Skip to content

Commit 82e85fd

Browse files
committed
feat: Allow the creation of any EntryMode. (#1259)
This helps testing for one, but might also be useful in other contexts. After all, this is a plumbing crate.
1 parent 67833df commit 82e85fd

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

gix-object/src/tree/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ pub mod write;
1212
/// The mode of items storable in a tree, similar to the file mode on a unix file system.
1313
///
1414
/// Used in [`mutable::Entry`][crate::tree::Entry] and [`EntryRef`].
15+
///
16+
/// Note that even though it can be created from any `u16`, it should be preferable to
17+
/// create it by converting [`EntryKind`] into `EntryMode`.
1518
#[derive(Clone, Copy, PartialEq, Eq, Debug, Ord, PartialOrd, Hash)]
1619
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
17-
pub struct EntryMode(u16);
20+
pub struct EntryMode(pub u16);
1821

1922
/// A discretized version of ideal and valid values for entry modes.
2023
///

gix-object/tests/tree/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,33 @@ mod entry_mode {
220220
}
221221

222222
assert!(mode(EntryKind::Blob).is_blob());
223+
assert!(EntryMode(0o100645).is_blob());
224+
assert_eq!(EntryMode(0o100645).kind(), EntryKind::Blob);
225+
assert!(!EntryMode(0o100675).is_executable());
226+
assert!(EntryMode(0o100700).is_executable());
227+
assert_eq!(EntryMode(0o100700).kind(), EntryKind::BlobExecutable);
223228
assert!(!mode(EntryKind::Blob).is_link());
224229
assert!(mode(EntryKind::BlobExecutable).is_blob());
230+
assert!(mode(EntryKind::BlobExecutable).is_executable());
225231
assert!(mode(EntryKind::Blob).is_blob_or_symlink());
226232
assert!(mode(EntryKind::BlobExecutable).is_blob_or_symlink());
227233

228234
assert!(!mode(EntryKind::Link).is_blob());
229235
assert!(mode(EntryKind::Link).is_link());
236+
assert!(EntryMode(0o121234).is_link());
237+
assert_eq!(EntryMode(0o121234).kind(), EntryKind::Link);
230238
assert!(mode(EntryKind::Link).is_blob_or_symlink());
231239
assert!(mode(EntryKind::Tree).is_tree());
240+
assert!(EntryMode(0o040101).is_tree());
241+
assert_eq!(EntryMode(0o040101).kind(), EntryKind::Tree);
232242
assert!(mode(EntryKind::Commit).is_commit());
243+
assert!(EntryMode(0o167124).is_commit());
244+
assert_eq!(EntryMode(0o167124).kind(), EntryKind::Commit);
245+
assert_eq!(
246+
EntryMode(0o000000).kind(),
247+
EntryKind::Commit,
248+
"commit is really 'anything else' as `kind()` can't fail"
249+
);
233250
}
234251

235252
#[test]

0 commit comments

Comments
 (0)