diff --git a/crates/radicle-cli/src/git/unified_diff.rs b/crates/radicle-cli/src/git/unified_diff.rs index e4686841..c8b91af2 100644 --- a/crates/radicle-cli/src/git/unified_diff.rs +++ b/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()))?; diff --git a/crates/radicle-node/src/test/handle.rs b/crates/radicle-node/src/test/handle.rs index c7f43e49..8c1ab590 100644 --- a/crates/radicle-node/src/test/handle.rs +++ b/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, }) } diff --git a/crates/radicle-oid/src/lib.rs b/crates/radicle-oid/src/lib.rs index be747b0c..3568ffa5 100644 --- a/crates/radicle-oid/src/lib.rs +++ b/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::() .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()); } } } diff --git a/crates/radicle/src/storage/refs.rs b/crates/radicle/src/storage/refs.rs index c7b6b3e9..08d69ce8 100644 --- a/crates/radicle/src/storage/refs.rs +++ b/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());