Skip to content

Commit 7aedb14

Browse files
Add shortcut for empty blob in serializer
1 parent 7ab841d commit 7aedb14

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

josh-core/src/filter/persist.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,22 @@ struct InMemoryBuilder {
6161

6262
impl InMemoryBuilder {
6363
fn new() -> Self {
64-
Self {
65-
pending_writes: HashMap::new(),
66-
}
64+
// Add an empty blob because we use a shortcut for them below
65+
// in write_blob
66+
let mut pending_writes = HashMap::new();
67+
pending_writes.insert(
68+
gix_hash::ObjectId::empty_blob(gix_hash::Kind::Sha1),
69+
(gix_object::Kind::Blob, Vec::new()),
70+
);
71+
72+
Self { pending_writes }
6773
}
6874

6975
fn write_blob(&mut self, data: &[u8]) -> gix_hash::ObjectId {
76+
if data.is_empty() {
77+
return gix_hash::ObjectId::empty_blob(gix_hash::Kind::Sha1);
78+
}
79+
7080
let hash = gix_object::compute_hash(gix_hash::Kind::Sha1, gix_object::Kind::Blob, data)
7181
.expect("failed to compute hash");
7282
self.pending_writes

0 commit comments

Comments
 (0)