Skip to content

Commit 4139c67

Browse files
committed
feat: add Oid::is_null() - previously it was only available on ObjectId.
1 parent 089659c commit 4139c67

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

gix-hash/src/oid.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{convert::TryInto, fmt, hash};
22

3-
use crate::{ObjectId, SIZE_OF_SHA1_DIGEST};
3+
use crate::{Kind, ObjectId, SIZE_OF_SHA1_DIGEST};
44

55
/// A borrowed reference to a hash identifying objects.
66
///
@@ -137,6 +137,15 @@ impl oid {
137137
hex_len: self.bytes.len() * 2,
138138
}
139139
}
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+
}
140149
}
141150

142151
/// Sha1 specific methods

gix-hash/tests/oid/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ mod to_hex_with_len {
1313
);
1414
}
1515
}
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+
}

0 commit comments

Comments
 (0)