Skip to content

Commit 0fdbcc0

Browse files
authored
Support turning a FileMode into an i32 as well (#649)
On some platforms, file modes use i32 rather than u32. Support both, for portability.
1 parent 0e3781f commit 0fdbcc0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,19 @@ pub enum FileMode {
10491049
Commit,
10501050
}
10511051

1052+
impl From<FileMode> for i32 {
1053+
fn from(mode: FileMode) -> i32 {
1054+
match mode {
1055+
FileMode::Unreadable => raw::GIT_FILEMODE_UNREADABLE as i32,
1056+
FileMode::Tree => raw::GIT_FILEMODE_TREE as i32,
1057+
FileMode::Blob => raw::GIT_FILEMODE_BLOB as i32,
1058+
FileMode::BlobExecutable => raw::GIT_FILEMODE_BLOB_EXECUTABLE as i32,
1059+
FileMode::Link => raw::GIT_FILEMODE_LINK as i32,
1060+
FileMode::Commit => raw::GIT_FILEMODE_COMMIT as i32,
1061+
}
1062+
}
1063+
}
1064+
10521065
impl From<FileMode> for u32 {
10531066
fn from(mode: FileMode) -> u32 {
10541067
match mode {
@@ -1465,6 +1478,8 @@ mod tests {
14651478

14661479
#[test]
14671480
fn convert_filemode() {
1481+
assert_eq!(i32::from(FileMode::Blob), 0o100644);
1482+
assert_eq!(i32::from(FileMode::BlobExecutable), 0o100755);
14681483
assert_eq!(u32::from(FileMode::Blob), 0o100644);
14691484
assert_eq!(u32::from(FileMode::BlobExecutable), 0o100755);
14701485
}

0 commit comments

Comments
 (0)