File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 1
1
use std:: { convert:: TryInto , fmt, hash} ;
2
2
3
- use crate :: { ObjectId , SIZE_OF_SHA1_DIGEST } ;
3
+ use crate :: { Kind , ObjectId , SIZE_OF_SHA1_DIGEST } ;
4
4
5
5
/// A borrowed reference to a hash identifying objects.
6
6
///
@@ -137,6 +137,15 @@ impl oid {
137
137
hex_len : self . bytes . len ( ) * 2 ,
138
138
}
139
139
}
140
+
141
+ /// Returns `true` if this hash consists of all null bytes.
142
+ #[ inline]
143
+ #[ doc( alias = "is_zero" , alias = "git2" ) ]
144
+ pub fn is_null ( & self ) -> bool {
145
+ match self . kind ( ) {
146
+ Kind :: Sha1 => & self . bytes == oid:: null_sha1 ( ) . as_bytes ( ) ,
147
+ }
148
+ }
140
149
}
141
150
142
151
/// Sha1 specific methods
Original file line number Diff line number Diff line change @@ -13,3 +13,9 @@ mod to_hex_with_len {
13
13
) ;
14
14
}
15
15
}
16
+
17
+ #[ test]
18
+ fn is_null ( ) {
19
+ assert ! ( gix_hash:: Kind :: Sha1 . null( ) . is_null( ) ) ;
20
+ assert ! ( gix_hash:: Kind :: Sha1 . null( ) . as_ref( ) . is_null( ) ) ;
21
+ }
You can’t perform that action at this time.
0 commit comments