Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
oid: `const ZERO_SHA1` instead of `fn sha1_zero`
Lorenz Leutgeb committed 2 days ago
commit f65175397f12b1c5626862e450a324b6361b4a31
parent aa177b0
4 files changed +10 -12
modified crates/radicle-cli/src/git/unified_diff.rs
@@ -336,7 +336,7 @@ impl Encode for FileHeader {
                w.meta(format!("new file mode {:o}", u32::from(new.mode.clone())))?;
                w.meta(format!(
                    "index {}..{}",
-
                    term::format::oid(git::Oid::sha1_zero()),
+
                    term::format::oid(git::Oid::ZERO_SHA1),
                    term::format::oid(*new.oid),
                ))?;

@@ -358,7 +358,7 @@ impl Encode for FileHeader {
                w.meta(format!(
                    "index {}..{}",
                    term::format::oid(*old.oid),
-
                    term::format::oid(git::Oid::sha1_zero())
+
                    term::format::oid(git::Oid::ZERO_SHA1)
                ))?;

                w.meta(format!("--- a/{}", path.display()))?;
modified crates/radicle-node/src/test/handle.rs
@@ -118,7 +118,7 @@ impl radicle::node::Handle for Handle {

        Ok(RefsAt {
            remote: self.nid()?,
-
            at: Oid::sha1_zero(),
+
            at: Oid::ZERO_SHA1,
        })
    }

modified crates/radicle-oid/src/lib.rs
@@ -87,6 +87,8 @@ pub enum Oid {
// for forwards compatibility: What if another hash with digests of the same
// length becomes popular?
impl Oid {
+
    pub const ZERO_SHA1: Self = Self::Sha1([0u8; SHA1_DIGEST_LEN]);
+

    pub fn from_sha1(digest: [u8; SHA1_DIGEST_LEN]) -> Self {
        Self::Sha1(digest)
    }
@@ -96,10 +98,6 @@ impl Oid {
            Oid::Sha1(digest) => Some(*digest),
        }
    }
-

-
    pub fn sha1_zero() -> Self {
-
        Self::Sha1([0u8; SHA1_DIGEST_LEN])
-
    }
}

/// Interaction with zero.
@@ -230,7 +228,7 @@ pub mod str {
                "0000000000000000000000000000000000000000"
                    .parse::<Oid>()
                    .unwrap(),
-
                Oid::sha1_zero()
+
                Oid::ZERO_SHA1
            );
        }

@@ -319,7 +317,7 @@ mod fmt {
        #[test]
        fn zero() {
            assert_eq!(
-
                Oid::sha1_zero().to_string(),
+
                Oid::ZERO_SHA1.to_string(),
                "0000000000000000000000000000000000000000"
            );
        }
@@ -404,7 +402,7 @@ mod gix {

        #[test]
        fn zero() {
-
            assert!(Oid::sha1_zero() == Other::null(Kind::Sha1));
+
            assert!(Oid::ZERO_SHA1 == Other::null(Kind::Sha1));
        }
    }
}
@@ -451,7 +449,7 @@ mod git2 {

        #[test]
        fn zero() {
-
            assert!(Oid::sha1_zero() == Other::zero());
+
            assert!(Oid::ZERO_SHA1 == Other::zero());
        }
    }
}
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::sha1_zero());
+
            debug_assert_ne!(oid, &Oid::ZERO_SHA1);
            debug_assert_ne!(name, &SIGREFS_BRANCH.to_ref_string());

            buf.push_str(&oid.to_string());