summaryrefslogtreecommitdiffstats
path: root/vendor/gix-index/src/file/write.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gix-index/src/file/write.rs')
-rw-r--r--vendor/gix-index/src/file/write.rs27
1 files changed, 16 insertions, 11 deletions
diff --git a/vendor/gix-index/src/file/write.rs b/vendor/gix-index/src/file/write.rs
index 1e8afc07d..47a4cde96 100644
--- a/vendor/gix-index/src/file/write.rs
+++ b/vendor/gix-index/src/file/write.rs
@@ -22,23 +22,28 @@ impl File {
mut out: impl std::io::Write,
options: write::Options,
) -> std::io::Result<(Version, gix_hash::ObjectId)> {
- let mut hasher = hash::Write::new(&mut out, self.state.object_hash);
- let version = self.state.write_to(&mut hasher, options)?;
-
- let hash = hasher.hash.digest();
- out.write_all(&hash)?;
- Ok((version, gix_hash::ObjectId::from(hash)))
+ let (version, hash) = if options.skip_hash {
+ let out: &mut dyn std::io::Write = &mut out;
+ let version = self.state.write_to(out, options)?;
+ (version, self.state.object_hash.null())
+ } else {
+ let mut hasher = hash::Write::new(&mut out, self.state.object_hash);
+ let out: &mut dyn std::io::Write = &mut hasher;
+ let version = self.state.write_to(out, options)?;
+ (version, gix_hash::ObjectId::from(hasher.hash.digest()))
+ };
+ out.write_all(hash.as_slice())?;
+ Ok((version, hash))
}
/// Write ourselves to the path we were read from after acquiring a lock, using `options`.
///
/// Note that the hash produced will be stored which is why we need to be mutable.
pub fn write(&mut self, options: write::Options) -> Result<(), Error> {
- let mut lock = std::io::BufWriter::new(gix_lock::File::acquire_to_update_resource(
- &self.path,
- gix_lock::acquire::Fail::Immediately,
- None,
- )?);
+ let mut lock = std::io::BufWriter::with_capacity(
+ 64 * 1024,
+ gix_lock::File::acquire_to_update_resource(&self.path, gix_lock::acquire::Fail::Immediately, None)?,
+ );
let (version, digest) = self.write_to(&mut lock, options)?;
match lock.into_inner() {
Ok(lock) => lock.commit()?,