From dc0db358abe19481e475e10c32149b53370f1a1c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 05:57:31 +0200 Subject: Merging upstream version 1.72.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/gix-hash/src/kind.rs | 10 +++++----- vendor/gix-hash/src/lib.rs | 10 ++++++---- vendor/gix-hash/src/object_id.rs | 41 ++++++++++++++++++++++------------------ vendor/gix-hash/src/oid.rs | 8 ++++---- vendor/gix-hash/src/prefix.rs | 6 +++--- 5 files changed, 41 insertions(+), 34 deletions(-) (limited to 'vendor/gix-hash/src') diff --git a/vendor/gix-hash/src/kind.rs b/vendor/gix-hash/src/kind.rs index 902cf705d..ee8600b1b 100644 --- a/vendor/gix-hash/src/kind.rs +++ b/vendor/gix-hash/src/kind.rs @@ -57,14 +57,14 @@ impl Kind { [0u8; Kind::longest().len_in_bytes()] } - /// Returns the amount of ascii-characters needed to encode this has in hex. + /// Returns the amount of bytes needed to encode this instance as hexadecimal characters. #[inline] pub const fn len_in_hex(&self) -> usize { match self { Kind::Sha1 => 40, } } - /// Returns the amount of bytes taken up by the hash of the current kind. + /// Returns the amount of bytes taken up by the hash of this instance. #[inline] pub const fn len_in_bytes(&self) -> usize { match self { @@ -73,7 +73,7 @@ impl Kind { } /// Returns the kind of hash that would fit the given `hex_len`, or `None` if there is no fitting hash. - /// Note that 0 as `hex_len` fits always yields Sha1. + /// Note that `0` as `hex_len` up to 40 always yields `Sha1`. #[inline] pub const fn from_hex_len(hex_len: usize) -> Option { Some(match hex_len { @@ -98,7 +98,7 @@ impl Kind { } } - /// Create a null-id of our hash kind. + /// Create a shared null-id of our hash kind. #[inline] pub fn null_ref(&self) -> &'static oid { match self { @@ -106,7 +106,7 @@ impl Kind { } } - /// Create a null-id of our hash kind. + /// Create an owned null-id of our hash kind. #[inline] pub const fn null(&self) -> ObjectId { match self { diff --git a/vendor/gix-hash/src/lib.rs b/vendor/gix-hash/src/lib.rs index 49940f48e..f4a8d3f23 100644 --- a/vendor/gix-hash/src/lib.rs +++ b/vendor/gix-hash/src/lib.rs @@ -1,6 +1,6 @@ //! This crate provides types for identifying git objects using a hash digest. //! -//! These are provided in borrowed versions as well as owned ones. +//! These are provided in [borrowed versions][oid] as well as an [owned one][ObjectId]. //! ## Feature Flags #![cfg_attr( feature = "document-features", @@ -19,8 +19,10 @@ pub use object_id::{decode, ObjectId}; /// pub mod prefix; -/// An partial owned hash possibly identifying an object uniquely, -/// whose non-prefix bytes are zeroed. +/// An partial, owned hash possibly identifying an object uniquely, whose non-prefix bytes are zeroed. +/// +/// An example would `0000000000000000000000000000000032bd3242`, where `32bd3242` is the prefix, +/// which would be able to match all hashes that *start with* `32bd3242`. #[derive(PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Copy, Debug)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Prefix { @@ -31,7 +33,7 @@ pub struct Prefix { /// The size of a SHA1 hash digest in bytes. const SIZE_OF_SHA1_DIGEST: usize = 20; -/// Denotes the kind of function to produce a `Id`. +/// Denotes the kind of function to produce a [`ObjectId`]. #[derive(Default, PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum Kind { diff --git a/vendor/gix-hash/src/object_id.rs b/vendor/gix-hash/src/object_id.rs index 2d9bcef33..8bf19a744 100644 --- a/vendor/gix-hash/src/object_id.rs +++ b/vendor/gix-hash/src/object_id.rs @@ -1,14 +1,13 @@ use std::{ borrow::Borrow, convert::TryInto, - fmt, hash::{Hash, Hasher}, ops::Deref, }; use crate::{borrowed::oid, Kind, SIZE_OF_SHA1_DIGEST}; -/// An owned hash identifying objects, most commonly Sha1 +/// An owned hash identifying objects, most commonly `Sha1` #[derive(PartialEq, Eq, Ord, PartialOrd, Clone, Copy)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum ObjectId { @@ -77,11 +76,11 @@ pub mod decode { /// Access and conversion impl ObjectId { - /// Returns the kind of hash used in this `Id`. + /// Returns the kind of hash used in this instance. #[inline] - pub fn kind(&self) -> crate::Kind { + pub fn kind(&self) -> Kind { match self { - ObjectId::Sha1(_) => crate::Kind::Sha1, + ObjectId::Sha1(_) => Kind::Sha1, } } /// Return the raw byte slice representing this hash. @@ -119,7 +118,15 @@ impl ObjectId { } } - /// Returns true if this hash consists of all null bytes. + /// Returns an instances whose bytes are all zero. + #[inline] + pub const fn null(kind: Kind) -> ObjectId { + match kind { + Kind::Sha1 => Self::null_sha1(), + } + } + + /// Returns `true` if this hash consists of all null bytes. #[inline] pub fn is_null(&self) -> bool { match self { @@ -133,12 +140,10 @@ impl ObjectId { self == &Self::empty_blob(self.kind()) } - /// Returns an Digest representing a hash with whose memory is zeroed. + /// Returns `true` if this hash is equal to an empty tree. #[inline] - pub const fn null(kind: crate::Kind) -> ObjectId { - match kind { - crate::Kind::Sha1 => Self::null_sha1(), - } + pub fn is_empty_tree(&self) -> bool { + self == &Self::empty_tree(self.kind()) } } @@ -194,10 +199,10 @@ impl From<&[u8]> for ObjectId { } } -impl From<&crate::oid> for ObjectId { +impl From<&oid> for ObjectId { fn from(v: &oid) -> Self { match v.kind() { - crate::Kind::Sha1 => ObjectId::from_20_bytes(v.as_bytes()), + Kind::Sha1 => ObjectId::from_20_bytes(v.as_bytes()), } } } @@ -210,25 +215,25 @@ impl Deref for ObjectId { } } -impl AsRef for ObjectId { +impl AsRef for ObjectId { fn as_ref(&self) -> &oid { oid::from_bytes_unchecked(self.as_slice()) } } -impl Borrow for ObjectId { +impl Borrow for ObjectId { fn borrow(&self) -> &oid { self.as_ref() } } -impl fmt::Display for ObjectId { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { +impl std::fmt::Display for ObjectId { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.to_hex()) } } -impl PartialEq<&crate::oid> for ObjectId { +impl PartialEq<&oid> for ObjectId { fn eq(&self, other: &&oid) -> bool { self.as_ref() == *other } diff --git a/vendor/gix-hash/src/oid.rs b/vendor/gix-hash/src/oid.rs index 20d4fb4b6..45380caff 100644 --- a/vendor/gix-hash/src/oid.rs +++ b/vendor/gix-hash/src/oid.rs @@ -11,7 +11,7 @@ use crate::{ObjectId, SIZE_OF_SHA1_DIGEST}; /// internal `bytes` slice length (a fat pointer, pointing to data and its length in bytes) /// to encode additional information. Before accessing or returning the bytes, a new adjusted /// slice will be constructed, while the high bits will be used to help resolving the -/// hash `[`kind()`][oid::kind()]`. +/// hash [`kind()`][oid::kind()]. /// We expect to have quite a few bits available for such 'conflict resolution' as most hashes aren't longer /// than 64 bytes. #[derive(PartialEq, Eq, Ord, PartialOrd)] @@ -102,13 +102,13 @@ impl oid { /// Access impl oid { - /// The kind of hash used for this Digest. + /// The kind of hash used for this instance. #[inline] pub fn kind(&self) -> crate::Kind { crate::Kind::from_len_in_bytes(self.bytes.len()) } - /// The first byte of the hash, commonly used to partition a set of `Id`s. + /// The first byte of the hash, commonly used to partition a set of object ids. #[inline] pub fn first_byte(&self) -> u8 { self.bytes[0] @@ -206,7 +206,7 @@ impl PartialEq for &oid { /// Manually created from a version that uses a slice, and we forcefully try to convert it into a borrowed array of the desired size /// Could be improved by fitting this into serde. -/// Unfortunately the serde::Deserialize derive wouldn't work for borrowed arrays. +/// Unfortunately the `serde::Deserialize` derive wouldn't work for borrowed arrays. #[cfg(feature = "serde")] impl<'de: 'a, 'a> serde::Deserialize<'de> for &'a oid { fn deserialize(deserializer: D) -> Result>::Error> diff --git a/vendor/gix-hash/src/prefix.rs b/vendor/gix-hash/src/prefix.rs index a8b55922e..166b3c3e7 100644 --- a/vendor/gix-hash/src/prefix.rs +++ b/vendor/gix-hash/src/prefix.rs @@ -2,7 +2,7 @@ use std::{cmp::Ordering, convert::TryFrom}; use crate::{oid, ObjectId, Prefix}; -/// The error returned by [Prefix::new()]. +/// The error returned by [`Prefix::new()`]. #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] pub enum Error { @@ -17,7 +17,7 @@ pub enum Error { /// pub mod from_hex { - /// The error returned by [Prefix::from_hex][super::Prefix::from_hex()]. + /// The error returned by [`Prefix::from_hex`][super::Prefix::from_hex()]. #[derive(Debug, Eq, PartialEq, thiserror::Error)] #[allow(missing_docs)] pub enum Error { @@ -110,7 +110,7 @@ impl Prefix { let mut buf = [0u8; crate::Kind::longest().len_in_hex()]; buf[..value.len()].copy_from_slice(value.as_bytes()); buf[value.len()] = b'0'; - Vec::from_hex(&buf[..value.len() + 1]) + Vec::from_hex(&buf[..=value.len()]) } .map_err(|e| match e { hex::FromHexError::InvalidHexCharacter { c, index } => from_hex::Error::Invalid { c, index }, -- cgit v1.2.3