diff options
Diffstat (limited to '')
-rw-r--r-- | vendor/gix-object/src/blob.rs | 6 | ||||
-rw-r--r-- | vendor/gix-object/src/commit/write.rs | 12 | ||||
-rw-r--r-- | vendor/gix-object/src/encode.rs | 2 | ||||
-rw-r--r-- | vendor/gix-object/src/lib.rs | 29 | ||||
-rw-r--r-- | vendor/gix-object/src/object/mod.rs | 34 | ||||
-rw-r--r-- | vendor/gix-object/src/tag/write.rs | 12 | ||||
-rw-r--r-- | vendor/gix-object/src/traits.rs | 4 | ||||
-rw-r--r-- | vendor/gix-object/src/tree/write.rs | 10 |
8 files changed, 67 insertions, 42 deletions
diff --git a/vendor/gix-object/src/blob.rs b/vendor/gix-object/src/blob.rs index d0a42092c..57db54758 100644 --- a/vendor/gix-object/src/blob.rs +++ b/vendor/gix-object/src/blob.rs @@ -12,8 +12,8 @@ impl<'a> crate::WriteTo for BlobRef<'a> { Kind::Blob } - fn size(&self) -> usize { - self.data.len() + fn size(&self) -> u64 { + self.data.len() as u64 } } @@ -27,7 +27,7 @@ impl crate::WriteTo for Blob { Kind::Blob } - fn size(&self) -> usize { + fn size(&self) -> u64 { self.to_ref().size() } } diff --git a/vendor/gix-object/src/commit/write.rs b/vendor/gix-object/src/commit/write.rs index 667d25763..efad2b6db 100644 --- a/vendor/gix-object/src/commit/write.rs +++ b/vendor/gix-object/src/commit/write.rs @@ -27,9 +27,9 @@ impl crate::WriteTo for Commit { Kind::Commit } - fn size(&self) -> usize { + fn size(&self) -> u64 { let hash_in_hex = self.tree.kind().len_in_hex(); - b"tree".len() + 1 /*space*/ + hash_in_hex + 1 /* nl */ + (b"tree".len() + 1 /*space*/ + hash_in_hex + 1 /* nl */ + self.parents.iter().count() * (b"parent".len() + 1 + hash_in_hex + 1) + b"author".len() + 1 /* space */ + self.author.size() + 1 /* nl */ + b"committer".len() + 1 /* space */ + self.committer.size() + 1 /* nl */ @@ -46,7 +46,7 @@ impl crate::WriteTo for Commit { }) .sum::<usize>() + 1 /* nl */ - + self.message.len() + + self.message.len()) as u64 } } @@ -73,9 +73,9 @@ impl<'a> crate::WriteTo for CommitRef<'a> { Kind::Commit } - fn size(&self) -> usize { + fn size(&self) -> u64 { let hash_in_hex = self.tree().kind().len_in_hex(); - b"tree".len() + 1 /* space */ + hash_in_hex + 1 /* nl */ + (b"tree".len() + 1 /* space */ + hash_in_hex + 1 /* nl */ + self.parents.iter().count() * (b"parent".len() + 1 /* space */ + hash_in_hex + 1 /* nl */) + b"author".len() + 1 /* space */ + self.author.size() + 1 /* nl */ + b"committer".len() + 1 /* space */ + self.committer.size() + 1 /* nl */ @@ -92,6 +92,6 @@ impl<'a> crate::WriteTo for CommitRef<'a> { }) .sum::<usize>() + 1 /* nl */ - + self.message.len() + + self.message.len()) as u64 } } diff --git a/vendor/gix-object/src/encode.rs b/vendor/gix-object/src/encode.rs index 3ba7db0b5..04a791948 100644 --- a/vendor/gix-object/src/encode.rs +++ b/vendor/gix-object/src/encode.rs @@ -19,7 +19,7 @@ macro_rules! check { }; } /// Generates a loose header buffer -pub fn loose_header(kind: crate::Kind, size: usize) -> smallvec::SmallVec<[u8; 28]> { +pub fn loose_header(kind: crate::Kind, size: u64) -> smallvec::SmallVec<[u8; 28]> { let mut v = smallvec::SmallVec::new(); check!(v.write_all(kind.as_bytes())); check!(v.write_all(SPACE)); diff --git a/vendor/gix-object/src/lib.rs b/vendor/gix-object/src/lib.rs index 56e0019fd..a07502917 100644 --- a/vendor/gix-object/src/lib.rs +++ b/vendor/gix-object/src/lib.rs @@ -98,7 +98,7 @@ pub struct CommitRef<'a> { pub extra_headers: Vec<(&'a BStr, Cow<'a, BStr>)>, } -/// Like [`CommitRef`][crate::CommitRef], but as `Iterator` to support (up to) entirely allocation free parsing. +/// Like [`CommitRef`], but as `Iterator` to support (up to) entirely allocation free parsing. /// It's particularly useful to traverse the commit graph without ever allocating arrays for parents. #[derive(Copy, Clone)] pub struct CommitRefIter<'a> { @@ -345,7 +345,7 @@ pub mod decode { /// ([`kind`](super::Kind), `size`, `consumed bytes`). /// /// `size` is the uncompressed size of the payload in bytes. - pub fn loose_header(input: &[u8]) -> Result<(super::Kind, usize, usize), LooseHeaderDecodeError> { + pub fn loose_header(input: &[u8]) -> Result<(super::Kind, u64, usize), LooseHeaderDecodeError> { use LooseHeaderDecodeError::*; let kind_end = input.find_byte(0x20).ok_or(InvalidHeader { message: "Expected '<type> <size>'", @@ -364,9 +364,10 @@ pub mod decode { } } -/// A standalone function to compute a hash of kind `hash_kind` for an object of `object_kind` and its `data`. +/// A function to compute a hash of kind `hash_kind` for an object of `object_kind` and its `data`. +#[doc(alias = "hash_object", alias = "git2")] pub fn compute_hash(hash_kind: gix_hash::Kind, object_kind: Kind, data: &[u8]) -> gix_hash::ObjectId { - let header = encode::loose_header(object_kind, data.len()); + let header = encode::loose_header(object_kind, data.len() as u64); let mut hasher = gix_features::hash::hasher(hash_kind); hasher.update(&header); @@ -374,3 +375,23 @@ pub fn compute_hash(hash_kind: gix_hash::Kind, object_kind: Kind, data: &[u8]) - hasher.digest().into() } + +/// A function to compute a hash of kind `hash_kind` for an object of `object_kind` and its data read from `stream` +/// which has to yield exactly `stream_len` bytes. +/// Use `progress` to learn about progress in bytes processed and `should_interrupt` to be able to abort the operation +/// if set to `true`. +#[doc(alias = "hash_file", alias = "git2")] +pub fn compute_stream_hash( + hash_kind: gix_hash::Kind, + object_kind: Kind, + stream: &mut dyn std::io::Read, + stream_len: u64, + progress: &mut dyn gix_features::progress::Progress, + should_interrupt: &std::sync::atomic::AtomicBool, +) -> std::io::Result<gix_hash::ObjectId> { + let header = encode::loose_header(object_kind, stream_len); + let mut hasher = gix_features::hash::hasher(hash_kind); + + hasher.update(&header); + gix_features::hash::bytes_with_hasher(stream, stream_len, hasher, progress, should_interrupt) +} diff --git a/vendor/gix-object/src/object/mod.rs b/vendor/gix-object/src/object/mod.rs index bebc1cc65..e7f775cd4 100644 --- a/vendor/gix-object/src/object/mod.rs +++ b/vendor/gix-object/src/object/mod.rs @@ -24,7 +24,7 @@ mod write { self.kind() } - fn size(&self) -> usize { + fn size(&self) -> u64 { use crate::ObjectRef::*; match self { Tree(v) => v.size(), @@ -52,7 +52,7 @@ mod write { self.kind() } - fn size(&self) -> usize { + fn size(&self) -> u64 { use crate::Object::*; match self { Tree(v) => v.size(), @@ -66,35 +66,35 @@ mod write { /// Convenient extraction of typed object. impl Object { - /// Turns this instance into a [`Blob`][Blob], panic otherwise. + /// Turns this instance into a [`Blob`], panic otherwise. pub fn into_blob(self) -> Blob { match self { Object::Blob(v) => v, _ => panic!("BUG: not a blob"), } } - /// Turns this instance into a [`Commit`][Commit] panic otherwise. + /// Turns this instance into a [`Commit`] panic otherwise. pub fn into_commit(self) -> Commit { match self { Object::Commit(v) => v, _ => panic!("BUG: not a commit"), } } - /// Turns this instance into a [`Tree`][Tree] panic otherwise. + /// Turns this instance into a [`Tree`] panic otherwise. pub fn into_tree(self) -> Tree { match self { Object::Tree(v) => v, _ => panic!("BUG: not a tree"), } } - /// Turns this instance into a [`Tag`][Tag] panic otherwise. + /// Turns this instance into a [`Tag`] panic otherwise. pub fn into_tag(self) -> Tag { match self { Object::Tag(v) => v, _ => panic!("BUG: not a tag"), } } - /// Turns this instance into a [`Blob`][Blob] if it is one. + /// Turns this instance into a [`Blob`] if it is one. #[allow(clippy::result_large_err)] pub fn try_into_blob(self) -> Result<Blob, Self> { match self { @@ -102,14 +102,14 @@ impl Object { _ => Err(self), } } - /// Turns this instance into a [`BlobRef`][BlobRef] if it is a blob. + /// Turns this instance into a [`BlobRef`] if it is a blob. pub fn try_into_blob_ref(&self) -> Option<BlobRef<'_>> { match self { Object::Blob(v) => Some(v.to_ref()), _ => None, } } - /// Turns this instance into a [`Commit`][Commit] if it is one. + /// Turns this instance into a [`Commit`] if it is one. #[allow(clippy::result_large_err)] pub fn try_into_commit(self) -> Result<Commit, Self> { match self { @@ -117,7 +117,7 @@ impl Object { _ => Err(self), } } - /// Turns this instance into a [`Tree`][Tree] if it is one. + /// Turns this instance into a [`Tree`] if it is one. #[allow(clippy::result_large_err)] pub fn try_into_tree(self) -> Result<Tree, Self> { match self { @@ -125,7 +125,7 @@ impl Object { _ => Err(self), } } - /// Turns this instance into a [`Tag`][Tag] if it is one. + /// Turns this instance into a [`Tag`] if it is one. #[allow(clippy::result_large_err)] pub fn try_into_tag(self) -> Result<Tag, Self> { match self { @@ -134,28 +134,28 @@ impl Object { } } - /// Returns a [`Blob`][Blob] if it is one. + /// Returns a [`Blob`] if it is one. pub fn as_blob(&self) -> Option<&Blob> { match self { Object::Blob(v) => Some(v), _ => None, } } - /// Returns a [`Commit`][Commit] if it is one. + /// Returns a [`Commit`] if it is one. pub fn as_commit(&self) -> Option<&Commit> { match self { Object::Commit(v) => Some(v), _ => None, } } - /// Returns a [`Tree`][Tree] if it is one. + /// Returns a [`Tree`] if it is one. pub fn as_tree(&self) -> Option<&Tree> { match self { Object::Tree(v) => Some(v), _ => None, } } - /// Returns a [`Tag`][Tag] if it is one. + /// Returns a [`Tag`] if it is one. pub fn as_tag(&self) -> Option<&Tag> { match self { Object::Tag(v) => Some(v), @@ -185,6 +185,8 @@ pub enum LooseDecodeError { InvalidHeader(#[from] LooseHeaderDecodeError), #[error(transparent)] InvalidContent(#[from] DecodeError), + #[error("Object sized {size} does not fit into memory - this can happen on 32 bit systems")] + OutOfMemory { size: u64 }, } impl<'a> ObjectRef<'a> { @@ -193,7 +195,7 @@ impl<'a> ObjectRef<'a> { let (kind, size, offset) = loose_header(data)?; let body = &data[offset..] - .get(..size) + .get(..size.try_into().map_err(|_| LooseDecodeError::OutOfMemory { size })?) .ok_or(LooseHeaderDecodeError::InvalidHeader { message: "object data was shorter than its size declared in the header", })?; diff --git a/vendor/gix-object/src/tag/write.rs b/vendor/gix-object/src/tag/write.rs index cee9e587c..dc8fd1ba3 100644 --- a/vendor/gix-object/src/tag/write.rs +++ b/vendor/gix-object/src/tag/write.rs @@ -44,8 +44,8 @@ impl crate::WriteTo for Tag { Kind::Tag } - fn size(&self) -> usize { - b"object".len() + 1 /* space */ + self.target.kind().len_in_hex() + 1 /* nl */ + fn size(&self) -> u64 { + (b"object".len() + 1 /* space */ + self.target.kind().len_in_hex() + 1 /* nl */ + b"type".len() + 1 /* space */ + self.target_kind.as_bytes().len() + 1 /* nl */ + b"tag".len() + 1 /* space */ + self.name.len() + 1 /* nl */ + self @@ -53,7 +53,7 @@ impl crate::WriteTo for Tag { .as_ref() .map_or(0, |t| b"tagger".len() + 1 /* space */ + t.size() + 1 /* nl */) + 1 /* nl */ + self.message.len() - + self.pgp_signature.as_ref().map_or(0, |m| 1 /* nl */ + m.len()) + + self.pgp_signature.as_ref().map_or(0, |m| 1 /* nl */ + m.len())) as u64 } } @@ -81,8 +81,8 @@ impl<'a> crate::WriteTo for TagRef<'a> { Kind::Tag } - fn size(&self) -> usize { - b"object".len() + 1 /* space */ + self.target().kind().len_in_hex() + 1 /* nl */ + fn size(&self) -> u64 { + (b"object".len() + 1 /* space */ + self.target().kind().len_in_hex() + 1 /* nl */ + b"type".len() + 1 /* space */ + self.target_kind.as_bytes().len() + 1 /* nl */ + b"tag".len() + 1 /* space */ + self.name.len() + 1 /* nl */ + self @@ -90,7 +90,7 @@ impl<'a> crate::WriteTo for TagRef<'a> { .as_ref() .map_or(0, |t| b"tagger".len() + 1 /* space */ + t.size() + 1 /* nl */) + 1 /* nl */ + self.message.len() - + self.pgp_signature.as_ref().map_or(0, |m| 1 /* nl */ + m.len()) + + self.pgp_signature.as_ref().map_or(0, |m| 1 /* nl */ + m.len())) as u64 } } diff --git a/vendor/gix-object/src/traits.rs b/vendor/gix-object/src/traits.rs index c0c4adee2..ce0463c98 100644 --- a/vendor/gix-object/src/traits.rs +++ b/vendor/gix-object/src/traits.rs @@ -17,7 +17,7 @@ pub trait WriteTo { /// the object, as such it's possible for [`size`](Self::size) to /// return a sensible value but [`write_to`](Self::write_to) to /// fail because the object was not actually valid in some way. - fn size(&self) -> usize; + fn size(&self) -> u64; /// Returns a loose object header based on the object's data fn loose_header(&self) -> smallvec::SmallVec<[u8; 28]> { @@ -37,7 +37,7 @@ where <T as WriteTo>::kind(self) } - fn size(&self) -> usize { + fn size(&self) -> u64 { <T as WriteTo>::size(self) } } diff --git a/vendor/gix-object/src/tree/write.rs b/vendor/gix-object/src/tree/write.rs index 91e1dc2e0..e1a82720f 100644 --- a/vendor/gix-object/src/tree/write.rs +++ b/vendor/gix-object/src/tree/write.rs @@ -57,10 +57,12 @@ impl crate::WriteTo for Tree { Kind::Tree } - fn size(&self) -> usize { + fn size(&self) -> u64 { self.entries .iter() - .map(|Entry { mode, filename, oid }| mode.as_bytes().len() + 1 + filename.len() + 1 + oid.as_bytes().len()) + .map(|Entry { mode, filename, oid }| { + (mode.as_bytes().len() + 1 + filename.len() + 1 + oid.as_bytes().len()) as u64 + }) .sum() } } @@ -100,11 +102,11 @@ impl<'a> crate::WriteTo for TreeRef<'a> { Kind::Tree } - fn size(&self) -> usize { + fn size(&self) -> u64 { self.entries .iter() .map(|EntryRef { mode, filename, oid }| { - mode.as_bytes().len() + 1 + filename.len() + 1 + oid.as_bytes().len() + (mode.as_bytes().len() + 1 + filename.len() + 1 + oid.as_bytes().len()) as u64 }) .sum() } |