Skip to content

Commit 772c434

Browse files
authored
Merge pull request #2165 from GitoxideLabs/copilot/fix-ceb7b1a4-93f5-4da1-a4f2-4290c8f594eb
Add `Kind::empty_blob()` and `Kind::empty_tree()` methods to gix-hash
2 parents 42f8db5 + 41c40ad commit 772c434

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

gix-hash/src/kind.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,16 @@ impl Kind {
113113
Kind::Sha1 => ObjectId::null_sha1(),
114114
}
115115
}
116+
117+
/// The hash of an empty blob.
118+
#[inline]
119+
pub const fn empty_blob(&self) -> ObjectId {
120+
ObjectId::empty_blob(*self)
121+
}
122+
123+
/// The hash of an empty tree.
124+
#[inline]
125+
pub const fn empty_tree(&self) -> ObjectId {
126+
ObjectId::empty_tree(*self)
127+
}
116128
}

gix-hash/tests/hash/kind.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use gix_hash::{Kind, ObjectId};
2+
13
mod from_hex_len {
24
use gix_hash::Kind;
35

@@ -14,3 +16,15 @@ mod from_hex_len {
1416
assert_eq!(Kind::from_hex_len(65), None);
1517
}
1618
}
19+
20+
#[test]
21+
fn empty_blob() {
22+
let sha1 = Kind::Sha1;
23+
assert_eq!(sha1.empty_blob(), ObjectId::empty_blob(sha1));
24+
}
25+
26+
#[test]
27+
fn empty_tree() {
28+
let sha1 = Kind::Sha1;
29+
assert_eq!(sha1.empty_tree(), ObjectId::empty_tree(sha1));
30+
}

0 commit comments

Comments
 (0)