radicle: Avoid comparison with `ZERO_SHA1`
When the underlying hash function is not important, but only the fact whether the OID is the zero sentinel, use `Oid::is_zero`. This is more flexible, as it is forward compatible with the SHA-256 object format.
This commit is contained in:
parent
ecca50a5f9
commit
4c605c0671
|
|
@ -87,6 +87,11 @@ pub enum Oid {
|
|||
// for forwards compatibility: What if another hash with digests of the same
|
||||
// length becomes popular?
|
||||
impl Oid {
|
||||
/// A SHA-1 object identifier with all digest bytes set to zero.
|
||||
/// This is sometimes used as a sentinel value to indicate the absence of
|
||||
/// an object.
|
||||
/// To compare whether an object identifier is zero, prefer the method
|
||||
/// [`Oid::is_zero`] over checking equality with this constant.
|
||||
pub const ZERO_SHA1: Self = Self::Sha1([0u8; SHA1_DIGEST_LEN]);
|
||||
|
||||
pub fn from_sha1(digest: [u8; SHA1_DIGEST_LEN]) -> Self {
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ impl Refs {
|
|||
let mut buf = String::new();
|
||||
|
||||
for (name, oid) in self.0.iter() {
|
||||
debug_assert_ne!(oid, &Oid::ZERO_SHA1);
|
||||
debug_assert!(!oid.is_zero());
|
||||
debug_assert_ne!(name, &SIGREFS_BRANCH.to_ref_string());
|
||||
|
||||
buf.push_str(&oid.to_string());
|
||||
|
|
|
|||
Loading…
Reference in New Issue