From 837b550238aa671a591ccf282dddeab29cadb206 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 18 May 2024 04:49:42 +0200 Subject: Merging upstream version 1.71.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/gix-odb/src/sink.rs | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'vendor/gix-odb/src/sink.rs') diff --git a/vendor/gix-odb/src/sink.rs b/vendor/gix-odb/src/sink.rs index 1befd6fdf..44a406151 100644 --- a/vendor/gix-odb/src/sink.rs +++ b/vendor/gix-odb/src/sink.rs @@ -30,7 +30,6 @@ impl crate::traits::Write for Sink { mut from: impl io::Read, ) -> Result { let mut size = size.try_into().expect("object size to fit into usize"); - use gix_features::hash::Sha1; let mut buf = [0u8; 8096]; let header = gix_object::encode::loose_header(kind, size); @@ -40,27 +39,24 @@ impl crate::traits::Write for Sink { } Ok(()) }; - match self.object_hash { - gix_hash::Kind::Sha1 => { - let mut hasher = Sha1::default(); - hasher.update(&header); - possibly_compress(&header)?; - while size != 0 { - let bytes = size.min(buf.len()); - from.read_exact(&mut buf[..bytes])?; - hasher.update(&buf[..bytes]); - possibly_compress(&buf[..bytes])?; - size -= bytes; - } - if let Some(compressor) = self.compressor.as_ref() { - let mut c = compressor.borrow_mut(); - c.flush()?; - c.reset(); - } + let mut hasher = gix_features::hash::hasher(self.object_hash); + hasher.update(&header); + possibly_compress(&header)?; - Ok(hasher.digest().into()) - } + while size != 0 { + let bytes = size.min(buf.len()); + from.read_exact(&mut buf[..bytes])?; + hasher.update(&buf[..bytes]); + possibly_compress(&buf[..bytes])?; + size -= bytes; + } + if let Some(compressor) = self.compressor.as_ref() { + let mut c = compressor.borrow_mut(); + c.flush()?; + c.reset(); } + + Ok(hasher.digest().into()) } } -- cgit v1.2.3