summaryrefslogtreecommitdiffstats
path: root/vendor/gix-odb/src/sink.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:42 +0000
commit837b550238aa671a591ccf282dddeab29cadb206 (patch)
tree914b6b8862bace72bd3245ca184d374b08d8a672 /vendor/gix-odb/src/sink.rs
parentAdding debian version 1.70.0+dfsg2-1. (diff)
downloadrustc-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.rs36
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())
}
}