@@ -72,46 +72,50 @@ impl std::ops::Deref for EntryMode {
72
72
}
73
73
}
74
74
75
+ const IFMT : u16 = 0o170000 ;
76
+
75
77
impl EntryMode {
76
78
/// Discretize the raw mode into an enum with well-known state while dropping unnecessary details.
77
79
pub const fn kind ( & self ) -> EntryKind {
78
- match self . 0 {
79
- 0o40000 => EntryKind :: Tree ,
80
- 0o120000 => EntryKind :: Link ,
81
- 0o160000 => EntryKind :: Commit ,
82
- blob_mode => {
83
- if blob_mode & 0o000100 == 0o000100 {
84
- EntryKind :: BlobExecutable
85
- } else {
86
- EntryKind :: Blob
87
- }
80
+ let etype = self . 0 & IFMT ;
81
+ if etype == 0o100000 {
82
+ if self . 0 & 0o000100 == 0o000100 {
83
+ EntryKind :: BlobExecutable
84
+ } else {
85
+ EntryKind :: Blob
88
86
}
87
+ } else if etype == EntryKind :: Link as u16 {
88
+ EntryKind :: Link
89
+ } else if etype == EntryKind :: Tree as u16 {
90
+ EntryKind :: Tree
91
+ } else {
92
+ EntryKind :: Commit
89
93
}
90
94
}
91
95
92
96
/// Return true if this entry mode represents a Tree/directory
93
97
pub const fn is_tree ( & self ) -> bool {
94
- self . 0 == EntryKind :: Tree as u16
98
+ self . 0 & IFMT == EntryKind :: Tree as u16
95
99
}
96
100
97
101
/// Return true if this entry mode represents the commit of a submodule.
98
102
pub const fn is_commit ( & self ) -> bool {
99
- self . 0 == EntryKind :: Commit as u16
103
+ self . 0 & IFMT == EntryKind :: Commit as u16
100
104
}
101
105
102
106
/// Return true if this entry mode represents a symbolic link
103
107
pub const fn is_link ( & self ) -> bool {
104
- self . 0 == EntryKind :: Link as u16
108
+ self . 0 & IFMT == EntryKind :: Link as u16
105
109
}
106
110
107
111
/// Return true if this entry mode represents anything BUT Tree/directory
108
112
pub const fn is_no_tree ( & self ) -> bool {
109
- self . 0 != EntryKind :: Tree as u16
113
+ self . 0 & IFMT != EntryKind :: Tree as u16
110
114
}
111
115
112
116
/// Return true if the entry is any kind of blob.
113
117
pub const fn is_blob ( & self ) -> bool {
114
- matches ! ( self . kind ( ) , EntryKind :: Blob | EntryKind :: BlobExecutable )
118
+ self . 0 & IFMT == 0o100000
115
119
}
116
120
117
121
/// Return true if the entry is an executable blob.
0 commit comments