diff --git a/gix-hash/src/kind.rs b/gix-hash/src/kind.rs index 5c7a0316b8d..de787b417fd 100644 --- a/gix-hash/src/kind.rs +++ b/gix-hash/src/kind.rs @@ -113,4 +113,16 @@ impl Kind { Kind::Sha1 => ObjectId::null_sha1(), } } + + /// The hash of an empty blob. + #[inline] + pub const fn empty_blob(&self) -> ObjectId { + ObjectId::empty_blob(*self) + } + + /// The hash of an empty tree. + #[inline] + pub const fn empty_tree(&self) -> ObjectId { + ObjectId::empty_tree(*self) + } } diff --git a/gix-hash/tests/hash/kind.rs b/gix-hash/tests/hash/kind.rs index 300a679fd2c..ec5bf3f1737 100644 --- a/gix-hash/tests/hash/kind.rs +++ b/gix-hash/tests/hash/kind.rs @@ -1,3 +1,5 @@ +use gix_hash::{Kind, ObjectId}; + mod from_hex_len { use gix_hash::Kind; @@ -14,3 +16,15 @@ mod from_hex_len { assert_eq!(Kind::from_hex_len(65), None); } } + +#[test] +fn empty_blob() { + let sha1 = Kind::Sha1; + assert_eq!(sha1.empty_blob(), ObjectId::empty_blob(sha1)); +} + +#[test] +fn empty_tree() { + let sha1 = Kind::Sha1; + assert_eq!(sha1.empty_tree(), ObjectId::empty_tree(sha1)); +}