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-object/src | |
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-object/src')
-rw-r--r-- | vendor/gix-object/src/commit/message/body.rs | 4 | ||||
-rw-r--r-- | vendor/gix-object/src/commit/mod.rs | 4 | ||||
-rw-r--r-- | vendor/gix-object/src/commit/ref_iter.rs | 13 | ||||
-rw-r--r-- | vendor/gix-object/src/data.rs | 6 | ||||
-rw-r--r-- | vendor/gix-object/src/lib.rs | 41 | ||||
-rw-r--r-- | vendor/gix-object/src/tag/ref_iter.rs | 9 | ||||
-rw-r--r-- | vendor/gix-object/src/tree/mod.rs | 8 |
7 files changed, 42 insertions, 43 deletions
diff --git a/vendor/gix-object/src/commit/message/body.rs b/vendor/gix-object/src/commit/message/body.rs index 27175a477..855f031be 100644 --- a/vendor/gix-object/src/commit/message/body.rs +++ b/vendor/gix-object/src/commit/message/body.rs @@ -22,10 +22,10 @@ pub struct Trailers<'a> { /// A trailer as parsed from the commit message body. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct TrailerRef<'a> { /// The name of the trailer, like "Signed-off-by", up to the separator ": " - #[cfg_attr(feature = "serde1", serde(borrow))] + #[cfg_attr(feature = "serde", serde(borrow))] pub token: &'a BStr, /// The value right after the separator ": ", with leading and trailing whitespace trimmed. /// Note that multi-line values aren't currently supported. diff --git a/vendor/gix-object/src/commit/mod.rs b/vendor/gix-object/src/commit/mod.rs index 94e8e6ec0..9e135df28 100644 --- a/vendor/gix-object/src/commit/mod.rs +++ b/vendor/gix-object/src/commit/mod.rs @@ -10,10 +10,10 @@ pub mod message; /// /// Titles can have any amount of whitespace #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct MessageRef<'a> { /// The title of the commit, as separated from the body with two consecutive newlines. The newlines are not included. - #[cfg_attr(feature = "serde1", serde(borrow))] + #[cfg_attr(feature = "serde", serde(borrow))] pub title: &'a BStr, /// All bytes not consumed by the title, excluding the separating newlines. /// diff --git a/vendor/gix-object/src/commit/ref_iter.rs b/vendor/gix-object/src/commit/ref_iter.rs index d502bea73..313f90945 100644 --- a/vendor/gix-object/src/commit/ref_iter.rs +++ b/vendor/gix-object/src/commit/ref_iter.rs @@ -17,22 +17,19 @@ pub(crate) enum SignatureKind { Committer, } -#[derive(Copy, Clone)] +#[derive(Default, Copy, Clone)] pub(crate) enum State { + #[default] Tree, Parents, - Signature { of: SignatureKind }, + Signature { + of: SignatureKind, + }, Encoding, ExtraHeaders, Message, } -impl Default for State { - fn default() -> Self { - State::Tree - } -} - impl<'a> CommitRefIter<'a> { /// Create a commit iterator from data. pub fn from_bytes(data: &'a [u8]) -> CommitRefIter<'a> { diff --git a/vendor/gix-object/src/data.rs b/vendor/gix-object/src/data.rs index abf5e1377..e66360357 100644 --- a/vendor/gix-object/src/data.rs +++ b/vendor/gix-object/src/data.rs @@ -69,11 +69,7 @@ pub mod verify { /// hash of `self`. pub fn verify_checksum(&self, desired: impl AsRef<gix_hash::oid>) -> Result<(), Error> { let desired = desired.as_ref(); - let mut hasher = gix_features::hash::hasher(desired.kind()); - hasher.update(&crate::encode::loose_header(self.kind, self.data.len())); - hasher.update(self.data); - - let actual_id = gix_hash::ObjectId::from(hasher.digest()); + let actual_id = crate::compute_hash(desired.kind(), self.kind, self.data); if desired != actual_id { return Err(Error::ChecksumMismatch { desired: desired.into(), diff --git a/vendor/gix-object/src/lib.rs b/vendor/gix-object/src/lib.rs index 80273af9f..5f6f9d33a 100644 --- a/vendor/gix-object/src/lib.rs +++ b/vendor/gix-object/src/lib.rs @@ -38,7 +38,7 @@ pub(crate) mod parse; pub mod kind; /// The four types of objects that git differentiates. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)] #[allow(missing_docs)] pub enum Kind { @@ -49,7 +49,7 @@ pub enum Kind { } /// A chunk of any [`data`][BlobRef::data]. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct BlobRef<'a> { /// The bytes themselves. pub data: &'a [u8], @@ -57,7 +57,7 @@ pub struct BlobRef<'a> { /// A mutable chunk of any [`data`][Blob::data]. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Blob { /// The data itself. pub data: Vec<u8>, @@ -68,12 +68,12 @@ pub struct Blob { /// A commit encapsulates information about a point in time at which the state of the repository is recorded, usually after a /// change which is documented in the commit `message`. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct CommitRef<'a> { /// HEX hash of tree object we point to. Usually 40 bytes long. /// /// Use [`tree()`][CommitRef::tree()] to obtain a decoded version of it. - #[cfg_attr(feature = "serde1", serde(borrow))] + #[cfg_attr(feature = "serde", serde(borrow))] pub tree: &'a BStr, /// HEX hash of each parent commit. Empty for first commit in repository. pub parents: SmallVec<[&'a BStr; 1]>, @@ -106,7 +106,7 @@ pub struct CommitRefIter<'a> { /// A mutable git commit, representing an annotated state of a working tree along with a reference to its historical commits. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Commit { /// The hash of recorded working tree state. pub tree: gix_hash::ObjectId, @@ -130,10 +130,10 @@ pub struct Commit { /// Represents a git tag, commonly indicating a software release. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct TagRef<'a> { /// The hash in hexadecimal being the object this tag points to. Use [`target()`][TagRef::target()] to obtain a byte representation. - #[cfg_attr(feature = "serde1", serde(borrow))] + #[cfg_attr(feature = "serde", serde(borrow))] pub target: &'a BStr, /// The kind of object that `target` points to. pub target_kind: Kind, @@ -157,7 +157,7 @@ pub struct TagRefIter<'a> { /// A mutable git tag. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Tag { /// The hash this tag is pointing to. pub target: gix_hash::ObjectId, @@ -181,10 +181,10 @@ pub struct Tag { /// /// An `ObjectRef` is representing [`Trees`][TreeRef], [`Blobs`][BlobRef], [`Commits`][CommitRef], or [`Tags`][TagRef]. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[allow(missing_docs)] pub enum ObjectRef<'a> { - #[cfg_attr(feature = "serde1", serde(borrow))] + #[cfg_attr(feature = "serde", serde(borrow))] Tree(TreeRef<'a>), Blob(BlobRef<'a>), Commit(CommitRef<'a>), @@ -200,7 +200,7 @@ pub enum ObjectRef<'a> { /// /// An `Object` is representing [`Trees`][Tree], [`Blobs`][Blob], [`Commits`][Commit] or [`Tags`][Tag]. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[allow(clippy::large_enum_variant, missing_docs)] pub enum Object { Tree(Tree), @@ -210,10 +210,10 @@ pub enum Object { } /// A directory snapshot containing files (blobs), directories (trees) and submodules (commits). #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct TreeRef<'a> { /// The directories and files contained in this tree. - #[cfg_attr(feature = "serde1", serde(borrow))] + #[cfg_attr(feature = "serde", serde(borrow))] pub entries: Vec<tree::EntryRef<'a>>, } @@ -226,7 +226,7 @@ pub struct TreeRefIter<'a> { /// A mutable Tree, containing other trees, blobs or commits. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Tree { /// The directories and files contained in this tree. They must be and remain sorted by [`filename`][tree::Entry::filename]. pub entries: Vec<tree::Entry>, @@ -375,3 +375,14 @@ pub mod decode { Ok((kind, size, size_end + 1)) } } + +/// A standalone function to compute a hash of kind `hash_kind` for an object of `object_kind` and its `data`. +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 mut hasher = gix_features::hash::hasher(hash_kind); + hasher.update(&header); + hasher.update(data); + + hasher.digest().into() +} diff --git a/vendor/gix-object/src/tag/ref_iter.rs b/vendor/gix-object/src/tag/ref_iter.rs index f9409ebbe..1138016b5 100644 --- a/vendor/gix-object/src/tag/ref_iter.rs +++ b/vendor/gix-object/src/tag/ref_iter.rs @@ -9,8 +9,9 @@ use nom::{ use crate::{bstr::ByteSlice, parse, parse::NL, tag::decode, Kind, TagRefIter}; -#[derive(Copy, Clone)] +#[derive(Default, Copy, Clone)] pub(crate) enum State { + #[default] Target, TargetKind, Name, @@ -18,12 +19,6 @@ pub(crate) enum State { Message, } -impl Default for State { - fn default() -> Self { - State::Target - } -} - impl<'a> TagRefIter<'a> { /// Create a tag iterator from data. pub fn from_bytes(data: &'a [u8]) -> TagRefIter<'a> { diff --git a/vendor/gix-object/src/tree/mod.rs b/vendor/gix-object/src/tree/mod.rs index 688689c08..be723e1b8 100644 --- a/vendor/gix-object/src/tree/mod.rs +++ b/vendor/gix-object/src/tree/mod.rs @@ -14,7 +14,7 @@ pub mod write; /// Used in [mutable::Entry][crate::tree::Entry] and [EntryRef]. #[derive(Clone, Copy, PartialEq, Eq, Debug, Ord, PartialOrd, Hash)] #[repr(u16)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum EntryMode { /// A tree, or directory Tree = 0o040000u16, @@ -64,7 +64,7 @@ impl EntryMode { /// An element of a [`TreeRef`][crate::TreeRef::entries]. #[derive(PartialEq, Eq, Debug, Hash, Clone)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct EntryRef<'a> { /// The kind of object to which `oid` is pointing. pub mode: tree::EntryMode, @@ -73,7 +73,7 @@ pub struct EntryRef<'a> { /// The id of the object representing the entry. // TODO: figure out how these should be called. id or oid? It's inconsistent around the codebase. // Answer: make it 'id', as in `git2` - #[cfg_attr(feature = "serde1", serde(borrow))] + #[cfg_attr(feature = "serde", serde(borrow))] pub oid: &'a gix_hash::oid, } @@ -94,7 +94,7 @@ impl<'a> Ord for EntryRef<'a> { /// An entry in a [`Tree`][crate::Tree], similar to an entry in a directory. #[derive(PartialEq, Eq, Debug, Hash, Clone)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Entry { /// The kind of object to which `oid` is pointing to. pub mode: EntryMode, |