Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
radicle: Avoid comparison with `ZERO_SHA1`
Lorenz Leutgeb committed 2 days ago
commit 4c605c0671376c6d2c552ea068e7a5db368d3fe1
parent ecca50a
2 files changed +6 -1
modified crates/radicle-oid/src/lib.rs
@@ -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 {
modified crates/radicle/src/storage/refs.rs
@@ -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());