diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:42 +0000 |
commit | 837b550238aa671a591ccf282dddeab29cadb206 (patch) | |
tree | 914b6b8862bace72bd3245ca184d374b08d8a672 /vendor/gix-odb/src/sink.rs | |
parent | Adding debian version 1.70.0+dfsg2-1. (diff) | |
download | rustc-837b550238aa671a591ccf282dddeab29cadb206.tar.xz rustc-837b550238aa671a591ccf282dddeab29cadb206.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-odb/src/sink.rs')
-rw-r--r-- | vendor/gix-odb/src/sink.rs | 36 |
1 files changed, 16 insertions, 20 deletions
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<gix_hash::ObjectId, Self::Error> { 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()) } } |