From 96461ace776d6b351b313d4f2697f2d95b9e196e Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 25 Aug 2021 16:41:46 +0800 Subject: [PATCH 1/3] [actor #173] rename immutable::Signature to SignatureRef! --- git-actor/src/immutable/mod.rs | 31 ---- git-actor/src/immutable/signature.rs | 157 ------------------ git-actor/src/lib.rs | 25 ++- git-actor/src/signature.rs | 29 +++- git-actor/src/signature_ref/decode.rs | 154 +++++++++++++++++ git-actor/src/signature_ref/mod.rs | 14 ++ git-actor/src/types.rs | 17 +- git-actor/tests/actor.rs | 2 +- git-actor/tests/mutable/mod.rs | 1 - .../signature.rs => signature/mod.rs} | 18 +- git-config/src/file/git_config.rs | 2 +- git-object/src/commit.rs | 2 +- git-object/src/immutable/commit/iter.rs | 8 +- git-object/src/immutable/commit/mod.rs | 4 +- git-object/src/immutable/object.rs | 6 +- git-object/src/immutable/parse.rs | 4 +- git-object/src/immutable/tag.rs | 6 +- git-object/src/lib.rs | 2 +- git-object/src/mutable/mod.rs | 4 +- git-object/src/types.rs | 2 +- git-object/tests/immutable/mod.rs | 8 +- git-object/tests/immutable/tag.rs | 2 +- git-odb/tests/odb/store/loose/mod.rs | 4 +- git-pack/src/data/object.rs | 4 +- git-ref/src/lib.rs | 2 +- git-ref/src/store/file/log/line.rs | 6 +- git-ref/src/store/file/log/mod.rs | 2 +- git-repository/src/easy/mod.rs | 2 +- git-traverse/src/tree/recorder.rs | 2 +- 29 files changed, 258 insertions(+), 262 deletions(-) delete mode 100644 git-actor/src/immutable/mod.rs delete mode 100644 git-actor/src/immutable/signature.rs create mode 100644 git-actor/src/signature_ref/decode.rs create mode 100644 git-actor/src/signature_ref/mod.rs delete mode 100644 git-actor/tests/mutable/mod.rs rename git-actor/tests/{mutable/signature.rs => signature/mod.rs} (81%) diff --git a/git-actor/src/immutable/mod.rs b/git-actor/src/immutable/mod.rs deleted file mode 100644 index 8c6c24b9348..00000000000 --- a/git-actor/src/immutable/mod.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! -use bstr::BStr; - -use crate::Time; - -/// A signature is created by an actor at a certain time. -/// -/// Note that this is not a cryptographical signature. -#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] -pub struct Signature<'a> { - /// The actor's name. - #[cfg_attr(feature = "serde1", serde(borrow))] - pub name: &'a BStr, - /// The actor's email. - pub email: &'a BStr, - /// The time stamp at which the signature was performed. - pub time: Time, -} - -impl<'a> Signature<'a> { - /// Deserialize a signature from the given `data`. - pub fn from_bytes + nom::error::ContextError<&'a [u8]>>( - data: &'a [u8], - ) -> Result, nom::Err> { - signature::decode(data).map(|(_, t)| t) - } -} - -/// -pub mod signature; diff --git a/git-actor/src/immutable/signature.rs b/git-actor/src/immutable/signature.rs deleted file mode 100644 index 36f1434366c..00000000000 --- a/git-actor/src/immutable/signature.rs +++ /dev/null @@ -1,157 +0,0 @@ -mod decode { - use bstr::ByteSlice; - use btoi::btoi; - use nom::{ - branch::alt, - bytes::complete::{tag, take, take_until, take_while_m_n}, - character::is_digit, - error::{context, ContextError, ParseError}, - sequence::{terminated, tuple}, - IResult, - }; - - use crate::{immutable::Signature, Sign, Time}; - - const SPACE: &[u8] = b" "; - - /// Parse a signature from the bytes input `i` using `nom`. - pub fn signature<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>( - i: &'a [u8], - ) -> IResult<&'a [u8], Signature<'a>, E> { - let (i, (name, email, time, tzsign, hours, minutes)) = context( - " <> <+|->", - tuple(( - context("", terminated(take_until(&b" <"[..]), take(2usize))), - context("", terminated(take_until(&b"> "[..]), take(2usize))), - context("", |i| { - terminated(take_until(SPACE), take(1usize))(i).and_then(|(i, v)| { - btoi::(v) - .map(|v| (i, v)) - .map_err(|_| nom::Err::Error(E::from_error_kind(i, nom::error::ErrorKind::MapRes))) - }) - }), - context("+|-", alt((tag(b"-"), tag(b"+")))), - context("HH", |i| { - take_while_m_n(2usize, 2, is_digit)(i).and_then(|(i, v)| { - btoi::(v) - .map(|v| (i, v)) - .map_err(|_| nom::Err::Error(E::from_error_kind(i, nom::error::ErrorKind::MapRes))) - }) - }), - context("MM", |i| { - take_while_m_n(2usize, 2, is_digit)(i).and_then(|(i, v)| { - btoi::(v) - .map(|v| (i, v)) - .map_err(|_| nom::Err::Error(E::from_error_kind(i, nom::error::ErrorKind::MapRes))) - }) - }), - )), - )(i)?; - - debug_assert!(tzsign[0] == b'-' || tzsign[0] == b'+', "parser assure it's +|- only"); - let sign = if tzsign[0] == b'-' { Sign::Minus } else { Sign::Plus }; // - let offset = (hours * 3600 + minutes * 60) * if sign == Sign::Minus { -1 } else { 1 }; - - Ok(( - i, - Signature { - name: name.as_bstr(), - email: email.as_bstr(), - time: Time { time, offset, sign }, - }, - )) - } - - #[cfg(test)] - mod tests { - mod parse_signature { - use bstr::ByteSlice; - use git_testtools::to_bstr_err; - use nom::IResult; - - use crate::{ - immutable::{signature, Signature}, - Sign, Time, - }; - - fn decode(i: &[u8]) -> IResult<&[u8], Signature<'_>, nom::error::VerboseError<&[u8]>> { - signature::decode(i) - } - - fn signature( - name: &'static str, - email: &'static str, - time: u32, - sign: Sign, - offset: i32, - ) -> Signature<'static> { - Signature { - name: name.as_bytes().as_bstr(), - email: email.as_bytes().as_bstr(), - time: Time { time, offset, sign }, - } - } - - #[test] - fn tz_minus() { - assert_eq!( - decode(b"Sebastian Thiel 1528473343 -0230") - .expect("parse to work") - .1, - signature("Sebastian Thiel", "byronimo@gmail.com", 1528473343, Sign::Minus, -9000) - ); - } - - #[test] - fn tz_plus() { - assert_eq!( - decode(b"Sebastian Thiel 1528473343 +0230") - .expect("parse to work") - .1, - signature("Sebastian Thiel", "byronimo@gmail.com", 1528473343, Sign::Plus, 9000) - ); - } - - #[test] - fn negative_offset_0000() { - assert_eq!( - decode(b"Sebastian Thiel 1528473343 -0000") - .expect("parse to work") - .1, - signature("Sebastian Thiel", "byronimo@gmail.com", 1528473343, Sign::Minus, 0) - ); - } - - #[test] - fn empty_name_and_email() { - assert_eq!( - decode(b" <> 12345 -1215").expect("parse to work").1, - signature("", "", 12345, Sign::Minus, -44100) - ); - } - - #[test] - fn invalid_signature() { - assert_eq!( - decode(b"hello < 12345 -1215") - .map_err(to_bstr_err) - .expect_err("parse fails as > is missing") - .to_string(), - "Parse error:\nTakeUntil at: 12345 -1215\nin section '', at: 12345 -1215\nin section ' <> <+|->', at: hello < 12345 -1215\n" - ); - } - - #[test] - fn invalid_time() { - assert_eq!( - decode(b"hello <> abc -1215") - .map_err(to_bstr_err) - .expect_err("parse fails as > is missing") - .to_string(), - "Parse error:\nMapRes at: -1215\nin section '', at: abc -1215\nin section ' <> <+|->', at: hello <> abc -1215\n" - ); - } - } - } -} -pub use decode::signature as decode; diff --git a/git-actor/src/lib.rs b/git-actor/src/lib.rs index fabe9a46985..84e79e306dd 100644 --- a/git-actor/src/lib.rs +++ b/git-actor/src/lib.rs @@ -1,10 +1,12 @@ -//! This crate provides ways of identifying an actor within the git repository both in shared/immutable and mutable variants. +//! This crate provides ways of identifying an actor within the git repository both in shared/signature_ref and mutable variants. #![forbid(unsafe_code)] #![deny(rust_2018_idioms, missing_docs)] -use bstr::BString; +use bstr::{BStr, BString}; -pub mod immutable; -mod signature; +/// +pub mod signature; +/// +pub mod signature_ref; const SPACE: &[u8; 1] = b" "; @@ -22,6 +24,21 @@ pub struct Signature { pub time: Time, } +/// A immutable signature is created by an actor at a certain time. +/// +/// Note that this is not a cryptographical signature. +#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] +#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +pub struct SignatureRef<'a> { + /// The actor's name. + #[cfg_attr(feature = "serde1", serde(borrow))] + pub name: &'a BStr, + /// The actor's email. + pub email: &'a BStr, + /// The time stamp at which the signature was performed. + pub time: Time, +} + /// Indicates if a number is positive or negative for use in [`Time`]. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)] #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] diff --git a/git-actor/src/signature.rs b/git-actor/src/signature.rs index e299de8713e..b7f0aa1e974 100644 --- a/git-actor/src/signature.rs +++ b/git-actor/src/signature.rs @@ -1,9 +1,24 @@ mod convert { - use crate::{immutable, Signature}; + use crate::{Sign, Signature, SignatureRef, Time}; - impl From> for Signature { - fn from(other: immutable::Signature<'_>) -> Signature { - let immutable::Signature { name, email, time } = other; + impl Signature { + /// An empty signature, similar to 'null'. + pub fn empty() -> Self { + Signature { + name: Default::default(), + email: Default::default(), + time: Time { + time: 0, + offset: 0, + sign: Sign::Plus, + }, + } + } + } + + impl From> for Signature { + fn from(other: SignatureRef<'_>) -> Signature { + let SignatureRef { name, email, time } = other; Signature { name: name.to_owned(), email: email.to_owned(), @@ -13,9 +28,9 @@ mod convert { } impl Signature { - /// Borrow this instance as immutable - pub fn borrow(&self) -> immutable::Signature<'_> { - immutable::Signature { + /// Borrow this instance as signature_ref + pub fn borrow(&self) -> SignatureRef<'_> { + SignatureRef { name: self.name.as_ref(), email: self.email.as_ref(), time: self.time, diff --git a/git-actor/src/signature_ref/decode.rs b/git-actor/src/signature_ref/decode.rs new file mode 100644 index 00000000000..0b03876565e --- /dev/null +++ b/git-actor/src/signature_ref/decode.rs @@ -0,0 +1,154 @@ +use bstr::ByteSlice; +use btoi::btoi; +use nom::{ + branch::alt, + bytes::complete::{tag, take, take_until, take_while_m_n}, + character::is_digit, + error::{context, ContextError, ParseError}, + sequence::{terminated, tuple}, + IResult, +}; + +use crate::{Sign, SignatureRef, Time}; + +const SPACE: &[u8] = b" "; + +/// Parse a signature from the bytes input `i` using `nom`. +pub fn decode<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>( + i: &'a [u8], +) -> IResult<&'a [u8], SignatureRef<'a>, E> { + let (i, (name, email, time, tzsign, hours, minutes)) = context( + " <> <+|->", + tuple(( + context("", terminated(take_until(&b" <"[..]), take(2usize))), + context("", terminated(take_until(&b"> "[..]), take(2usize))), + context("", |i| { + terminated(take_until(SPACE), take(1usize))(i).and_then(|(i, v)| { + btoi::(v) + .map(|v| (i, v)) + .map_err(|_| nom::Err::Error(E::from_error_kind(i, nom::error::ErrorKind::MapRes))) + }) + }), + context("+|-", alt((tag(b"-"), tag(b"+")))), + context("HH", |i| { + take_while_m_n(2usize, 2, is_digit)(i).and_then(|(i, v)| { + btoi::(v) + .map(|v| (i, v)) + .map_err(|_| nom::Err::Error(E::from_error_kind(i, nom::error::ErrorKind::MapRes))) + }) + }), + context("MM", |i| { + take_while_m_n(2usize, 2, is_digit)(i).and_then(|(i, v)| { + btoi::(v) + .map(|v| (i, v)) + .map_err(|_| nom::Err::Error(E::from_error_kind(i, nom::error::ErrorKind::MapRes))) + }) + }), + )), + )(i)?; + + debug_assert!(tzsign[0] == b'-' || tzsign[0] == b'+', "parser assure it's +|- only"); + let sign = if tzsign[0] == b'-' { Sign::Minus } else { Sign::Plus }; // + let offset = (hours * 3600 + minutes * 60) * if sign == Sign::Minus { -1 } else { 1 }; + + Ok(( + i, + SignatureRef { + name: name.as_bstr(), + email: email.as_bstr(), + time: Time { time, offset, sign }, + }, + )) +} + +#[cfg(test)] +mod tests { + mod parse_signature { + use bstr::ByteSlice; + use git_testtools::to_bstr_err; + use nom::IResult; + + use crate::{ + signature_ref::{self, SignatureRef}, + Sign, Time, + }; + + fn decode(i: &[u8]) -> IResult<&[u8], SignatureRef<'_>, nom::error::VerboseError<&[u8]>> { + signature_ref::decode(i) + } + + fn signature( + name: &'static str, + email: &'static str, + time: u32, + sign: Sign, + offset: i32, + ) -> SignatureRef<'static> { + SignatureRef { + name: name.as_bytes().as_bstr(), + email: email.as_bytes().as_bstr(), + time: Time { time, offset, sign }, + } + } + + #[test] + fn tz_minus() { + assert_eq!( + decode(b"Sebastian Thiel 1528473343 -0230") + .expect("parse to work") + .1, + signature("Sebastian Thiel", "byronimo@gmail.com", 1528473343, Sign::Minus, -9000) + ); + } + + #[test] + fn tz_plus() { + assert_eq!( + decode(b"Sebastian Thiel 1528473343 +0230") + .expect("parse to work") + .1, + signature("Sebastian Thiel", "byronimo@gmail.com", 1528473343, Sign::Plus, 9000) + ); + } + + #[test] + fn negative_offset_0000() { + assert_eq!( + decode(b"Sebastian Thiel 1528473343 -0000") + .expect("parse to work") + .1, + signature("Sebastian Thiel", "byronimo@gmail.com", 1528473343, Sign::Minus, 0) + ); + } + + #[test] + fn empty_name_and_email() { + assert_eq!( + decode(b" <> 12345 -1215").expect("parse to work").1, + signature("", "", 12345, Sign::Minus, -44100) + ); + } + + #[test] + fn invalid_signature() { + assert_eq!( + decode(b"hello < 12345 -1215") + .map_err(to_bstr_err) + .expect_err("parse fails as > is missing") + .to_string(), + "Parse error:\nTakeUntil at: 12345 -1215\nin section '', at: 12345 -1215\nin section ' <> <+|->', at: hello < 12345 -1215\n" + ); + } + + #[test] + fn invalid_time() { + assert_eq!( + decode(b"hello <> abc -1215") + .map_err(to_bstr_err) + .expect_err("parse fails as > is missing") + .to_string(), + "Parse error:\nMapRes at: -1215\nin section '', at: abc -1215\nin section ' <> <+|->', at: hello <> abc -1215\n" + ); + } + } +} diff --git a/git-actor/src/signature_ref/mod.rs b/git-actor/src/signature_ref/mod.rs new file mode 100644 index 00000000000..0d0a3e4c239 --- /dev/null +++ b/git-actor/src/signature_ref/mod.rs @@ -0,0 +1,14 @@ +use crate::SignatureRef; + +impl<'a> SignatureRef<'a> { + /// Deserialize a signature from the given `data`. + pub fn from_bytes + nom::error::ContextError<&'a [u8]>>( + data: &'a [u8], + ) -> Result, nom::Err> { + decode(data).map(|(_, t)| t) + } +} + +/// +mod decode; +pub use decode::decode; diff --git a/git-actor/src/types.rs b/git-actor/src/types.rs index ef7eba49038..39a52df9901 100644 --- a/git-actor/src/types.rs +++ b/git-actor/src/types.rs @@ -1,21 +1,6 @@ use std::io; -use crate::{Sign, Signature, Time, SPACE}; - -impl Signature { - /// An empty signature, similar to 'null'. - pub fn empty() -> Self { - Signature { - name: Default::default(), - email: Default::default(), - time: Time { - time: 0, - offset: 0, - sign: Sign::Plus, - }, - } - } -} +use crate::{Sign, Time, SPACE}; impl Time { /// Serialize this instance to `out` in a format suitable for use in header fields of serialized git commits or tags. diff --git a/git-actor/tests/actor.rs b/git-actor/tests/actor.rs index 4d106249501..89d6b6d6b97 100644 --- a/git-actor/tests/actor.rs +++ b/git-actor/tests/actor.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -mod mutable; +mod signature; pub use git_testtools::hex_to_id; diff --git a/git-actor/tests/mutable/mod.rs b/git-actor/tests/mutable/mod.rs deleted file mode 100644 index 699cf71aa00..00000000000 --- a/git-actor/tests/mutable/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod signature; diff --git a/git-actor/tests/mutable/signature.rs b/git-actor/tests/signature/mod.rs similarity index 81% rename from git-actor/tests/mutable/signature.rs rename to git-actor/tests/signature/mod.rs index 4884ea41075..2782b93baa3 100644 --- a/git-actor/tests/mutable/signature.rs +++ b/git-actor/tests/signature/mod.rs @@ -97,14 +97,14 @@ use git_actor::Signature; #[test] fn round_trip() -> Result<(), Box> { for input in &[ - &b"Sebastian Thiel 1 -0030"[..], - ".. ☺️Sebastian 王知明 Thiel🙌 .. 1528473343 +0230".as_bytes(), - ".. whitespace \t is explicitly allowed - unicode aware trimming must be done elsewhere 1528473343 +0230".as_bytes(), - ] { - let signature: Signature = git_actor::immutable::Signature::from_bytes::<()>(input)?.into(); - let mut output = Vec::new(); - signature.write_to(&mut output)?; - assert_eq!(output.as_bstr(), input.as_bstr()); - } + &b"Sebastian Thiel 1 -0030"[..], + ".. ☺️Sebastian 王知明 Thiel🙌 .. 1528473343 +0230".as_bytes(), + ".. whitespace \t is explicitly allowed - unicode aware trimming must be done elsewhere 1528473343 +0230".as_bytes(), + ] { + let signature: Signature = git_actor::SignatureRef::from_bytes::<()>(input)?.into(); + let mut output = Vec::new(); + signature.write_to(&mut output)?; + assert_eq!(output.as_bstr(), input.as_bstr()); + } Ok(()) } diff --git a/git-config/src/file/git_config.rs b/git-config/src/file/git_config.rs index 46345f0b51b..2a1d6644553 100644 --- a/git-config/src/file/git_config.rs +++ b/git-config/src/file/git_config.rs @@ -306,7 +306,7 @@ impl<'event> GitConfig<'event> { .map_err(|_| GitConfigError::FailedConversion) } - /// Returns an immutable section reference. + /// Returns an signature_ref section reference. /// /// # Errors /// diff --git a/git-object/src/commit.rs b/git-object/src/commit.rs index d932c07eda5..5c5ba36bdb0 100644 --- a/git-object/src/commit.rs +++ b/git-object/src/commit.rs @@ -2,7 +2,7 @@ use bstr::{BStr, ByteSlice}; use crate::immutable; -/// An iterator over extra headers in [owned][crate::mutable::Commit] and [borrowed][immutable::Commit] commits. +/// An iterator over extra headers in [owned][crate::mutable::Commit] and [borrowed][signature_ref::Commit] commits. pub struct ExtraHeaders { inner: I, } diff --git a/git-object/src/immutable/commit/iter.rs b/git-object/src/immutable/commit/iter.rs index 1b090a29f84..37134bb3754 100644 --- a/git-object/src/immutable/commit/iter.rs +++ b/git-object/src/immutable/commit/iter.rs @@ -35,7 +35,7 @@ impl Default for State { } } -/// Like [`immutable::Commit`][super::Commit], but as `Iterator` to support (up to) entirely allocation free parsing. +/// Like [`signature_ref::Commit`][super::Commit], 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. pub struct Iter<'a> { data: &'a [u8], @@ -67,7 +67,7 @@ impl<'a> Iter<'a> { /// Errors are coerced into options, hiding whether there was an error or not. The caller knows if there was an error or not /// if not exactly two signatures were iterable. /// Errors are not the common case - if an error needs to be detectable, use this instance as iterator. - pub fn signatures(&'a mut self) -> impl Iterator> + 'a { + pub fn signatures(&'a mut self) -> impl Iterator> + 'a { self.filter_map(Result::ok) .skip_while(|t| !matches!(t, Token::Author { .. } | Token::Committer { .. })) .filter_map(|t| match t { @@ -208,11 +208,11 @@ pub enum Token<'a> { }, /// A person who authored the content of the commit. Author { - signature: git_actor::immutable::Signature<'a>, + signature: git_actor::SignatureRef<'a>, }, /// A person who committed the authors work to the repository. Committer { - signature: git_actor::immutable::Signature<'a>, + signature: git_actor::SignatureRef<'a>, }, Encoding(&'a BStr), ExtraHeader((&'a BStr, Cow<'a, BStr>)), diff --git a/git-object/src/immutable/commit/mod.rs b/git-object/src/immutable/commit/mod.rs index ced543b2efb..f5498e69a99 100644 --- a/git-object/src/immutable/commit/mod.rs +++ b/git-object/src/immutable/commit/mod.rs @@ -24,12 +24,12 @@ pub struct Commit<'a> { /// HEX hash of each parent commit. Empty for first commit in repository. pub parents: SmallVec<[&'a BStr; 2]>, /// Who wrote this commit. - pub author: git_actor::immutable::Signature<'a>, + pub author: git_actor::SignatureRef<'a>, /// Who committed this commit. /// /// This may be different from the `author` in case the author couldn't write to the repository themselves and /// is commonly encountered with contributed commits. - pub committer: git_actor::immutable::Signature<'a>, + pub committer: git_actor::SignatureRef<'a>, /// The name of the message encoding, otherwise [UTF-8 should be assumed](https://github.com/git/git/blob/e67fbf927dfdf13d0b21dc6ea15dc3c7ef448ea0/commit.c#L1493:L1493). pub encoding: Option<&'a BStr>, /// The commit message documenting the change. diff --git a/git-object/src/immutable/object.rs b/git-object/src/immutable/object.rs index ce7da44cf85..ffb25d7f626 100644 --- a/git-object/src/immutable/object.rs +++ b/git-object/src/immutable/object.rs @@ -4,7 +4,7 @@ use crate::{ Kind, }; -/// An immutable object representing [`Trees`][Tree], [`Blobs`][Blob], [`Commits`][Commit], or [`Tags`][Tag]. +/// An signature_ref object 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))] #[allow(missing_docs)] @@ -27,14 +27,14 @@ impl<'a> Object<'a> { }) } - /// Convert the immutable object into a mutable version, consuming the source in the process. + /// Convert the signature_ref object into a mutable version, consuming the source in the process. /// /// Note that this is an expensive operation. pub fn into_mutable(self) -> crate::mutable::Object { self.into() } - /// Convert this immutable object into its mutable counterpart. + /// Convert this signature_ref object into its mutable counterpart. /// /// Note that this is an expensive operation. pub fn to_mutable(&self) -> crate::mutable::Object { diff --git a/git-object/src/immutable/parse.rs b/git-object/src/immutable/parse.rs index b161585cfdc..a73147d494c 100644 --- a/git-object/src/immutable/parse.rs +++ b/git-object/src/immutable/parse.rs @@ -76,6 +76,6 @@ pub fn hex_hash<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], & pub(crate) fn signature<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>( i: &'a [u8], -) -> IResult<&'a [u8], git_actor::immutable::Signature<'a>, E> { - git_actor::immutable::signature::decode(i) +) -> IResult<&'a [u8], git_actor::SignatureRef<'a>, E> { + git_actor::signature_ref::decode(i) } diff --git a/git-object/src/immutable/tag.rs b/git-object/src/immutable/tag.rs index 9d7f704c6d5..70d7c42fa49 100644 --- a/git-object/src/immutable/tag.rs +++ b/git-object/src/immutable/tag.rs @@ -12,7 +12,7 @@ pub struct Tag<'a> { /// The name of the tag, e.g. "v1.0". pub name: &'a BStr, /// The author of the tag. - pub tagger: Option>, + pub tagger: Option>, /// The message describing this release. pub message: &'a BStr, /// A cryptographic signature over the entire content of the serialized tag object thus far. @@ -158,7 +158,7 @@ pub mod iter { } } - /// Like [`immutable::Tag`][super::Tag], but as `Iterator` to support entirely allocation free parsing. + /// Like [`signature_ref::Tag`][super::Tag], but as `Iterator` to support entirely allocation free parsing. /// It's particularly useful to dereference only the target chain. pub struct Iter<'a> { data: &'a [u8], @@ -269,7 +269,7 @@ pub mod iter { }, TargetKind(Kind), Name(&'a BStr), - Tagger(Option>), + Tagger(Option>), Body { message: &'a BStr, pgp_signature: Option<&'a BStr>, diff --git a/git-object/src/lib.rs b/git-object/src/lib.rs index ea719bc4a17..b6fab6fce7a 100644 --- a/git-object/src/lib.rs +++ b/git-object/src/lib.rs @@ -1,4 +1,4 @@ -//! This crate provides types for [read-only git objects][immutable::Object] backed by bytes provided in git's serialization format +//! This crate provides types for [read-only git objects][signature_ref::Object] backed by bytes provided in git's serialization format //! as well as [mutable versions][mutable::Object] of these. The latter can be serialized into git's serialization format for objects. #![forbid(unsafe_code)] #![deny(rust_2018_idioms, missing_docs)] diff --git a/git-object/src/mutable/mod.rs b/git-object/src/mutable/mod.rs index a685298ac95..2e99a939eec 100644 --- a/git-object/src/mutable/mod.rs +++ b/git-object/src/mutable/mod.rs @@ -1,8 +1,8 @@ //! Mutable objects with each field being separately allocated and changeable. //! //! Mutable objects are Commits, Trees, Blobs and Tags that can be changed and serialized. -//! They either created using object [construction][Object] or by [deserializing existing objects][crate::immutable::Object::from_bytes()] -//! and converting these [into mutable copies][crate::immutable::Object::into_mutable()] for adjustments. +//! They either created using object [construction][Object] or by [deserializing existing objects][crate::signature_ref::Object::from_bytes()] +//! and converting these [into mutable copies][crate::signature_ref::Object::into_mutable()] for adjustments. const NL: &[u8; 1] = b"\n"; const SPACE: &[u8; 1] = b" "; diff --git a/git-object/src/types.rs b/git-object/src/types.rs index 451c5b99add..35eaaec5809 100644 --- a/git-object/src/types.rs +++ b/git-object/src/types.rs @@ -56,7 +56,7 @@ impl fmt::Display for Kind { pub mod tree { /// The mode of items storable in a tree, similar to the file mode on a unix file system. /// - /// Used in [mutable::Entry][crate::mutable::tree::Entry] and [immutable::Entry][crate::immutable::tree::Entry]. + /// Used in [mutable::Entry][crate::mutable::tree::Entry] and [signature_ref::Entry][crate::signature_ref::tree::Entry]. #[derive(Clone, Copy, PartialEq, Eq, Debug, Ord, PartialOrd, Hash)] #[repr(u16)] #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] diff --git a/git-object/tests/immutable/mod.rs b/git-object/tests/immutable/mod.rs index 8c62c0b06c6..28da23c8be9 100644 --- a/git-object/tests/immutable/mod.rs +++ b/git-object/tests/immutable/mod.rs @@ -23,9 +23,9 @@ fn fixture_bytes(kind: &str, path: &str) -> Vec { fixup(super::fixture_bytes(PathBuf::from(kind).join(path).to_str().unwrap())) } -fn signature(time: u32) -> git_actor::immutable::Signature<'static> { +fn signature(time: u32) -> git_actor::SignatureRef<'static> { use git_object::bstr::ByteSlice; - git_actor::immutable::Signature { + git_actor::SignatureRef { name: b"Sebastian Thiel".as_bstr(), email: b"sebastian.thiel@icloud.com".as_bstr(), time: Time { @@ -36,9 +36,9 @@ fn signature(time: u32) -> git_actor::immutable::Signature<'static> { } } -fn linus_signature(time: u32) -> git_actor::immutable::Signature<'static> { +fn linus_signature(time: u32) -> git_actor::SignatureRef<'static> { use git_object::bstr::ByteSlice; - git_actor::immutable::Signature { + git_actor::SignatureRef { name: b"Linus Torvalds".as_bstr(), email: b"torvalds@linux-foundation.org".as_bstr(), time: Time { diff --git a/git-object/tests/immutable/tag.rs b/git-object/tests/immutable/tag.rs index 8a5889ea970..76aa22633c9 100644 --- a/git-object/tests/immutable/tag.rs +++ b/git-object/tests/immutable/tag.rs @@ -231,7 +231,7 @@ cjHJZXWmV4CcRfmLsXzU8s2cR9A0DBvOxhPD1TlKC2JhBFXigjuL9U4Rbq9tdegB -----END PGP SIGNATURE-----" .as_bstr(), ), - tagger: Some(git_actor::immutable::Signature { + tagger: Some(git_actor::SignatureRef { name: b"Sebastian Thiel".as_bstr(), email: b"byronimo@gmail.com".as_bstr(), time: git_actor::Time { diff --git a/git-odb/tests/odb/store/loose/mod.rs b/git-odb/tests/odb/store/loose/mod.rs index 0980c426d39..3ab417213a5 100644 --- a/git-odb/tests/odb/store/loose/mod.rs +++ b/git-odb/tests/odb/store/loose/mod.rs @@ -3,8 +3,8 @@ use git_object::bstr::ByteSlice; pub mod backend; -fn signature(time: u32) -> git_actor::immutable::Signature<'static> { - git_actor::immutable::Signature { +fn signature(time: u32) -> git_actor::SignatureRef<'static> { + git_actor::SignatureRef { name: b"Sebastian Thiel".as_bstr(), email: b"byronimo@gmail.com".as_bstr(), time: Time { diff --git a/git-pack/src/data/object.rs b/git-pack/src/data/object.rs index fe1433e6c18..505a51a4998 100644 --- a/git-pack/src/data/object.rs +++ b/git-pack/src/data/object.rs @@ -22,11 +22,11 @@ impl<'a> Object<'a> { pack_location: None, } } - /// Decodes the data in the backing slice into a [`git_object::immutable::Object`], allowing to access all of its data + /// Decodes the data in the backing slice into a [`git_object::signature_ref::Object`], allowing to access all of its data /// conveniently. The cost of parsing an object is negligible. /// /// **Note** that [mutable, decoded objects][git_object::mutable::Object] can be created from a [`crate::data::Object`] - /// using [`git_object::immutable::Object::into_mutable()`]. + /// using [`git_object::signature_ref::Object::into_mutable()`]. pub fn decode(&self) -> Result, immutable::object::decode::Error> { Ok(match self.kind { git_object::Kind::Tree => immutable::Object::Tree(immutable::Tree::from_bytes(self.data)?), diff --git a/git-ref/src/lib.rs b/git-ref/src/lib.rs index e668ddb4e41..90ddbaba0a0 100644 --- a/git-ref/src/lib.rs +++ b/git-ref/src/lib.rs @@ -55,7 +55,7 @@ pub enum Kind { Symbolic, } -/// Denotes a ref target, equivalent to [`Kind`], but with immutable data. +/// Denotes a ref target, equivalent to [`Kind`], but with signature_ref data. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)] pub enum Target<'a> { /// A ref that points to an object id diff --git a/git-ref/src/store/file/log/line.rs b/git-ref/src/store/file/log/line.rs index b1de53f9584..13864919d33 100644 --- a/git-ref/src/store/file/log/line.rs +++ b/git-ref/src/store/file/log/line.rs @@ -80,7 +80,7 @@ pub mod decode { tuple(( context("", terminated(hex_hash, tag(b" "))), context("", terminated(hex_hash, tag(b" "))), - context(" <> ", git_actor::immutable::signature::decode), + context(" <> ", git_actor::signature_ref::decode), opt(tag(b"\t")), context("", message), )), @@ -164,7 +164,7 @@ pub mod decode { Line { previous_oid: NULL_SHA1.as_bstr(), new_oid: NULL_SHA1.as_bstr(), - signature: git_actor::immutable::Signature { + signature: git_actor::SignatureRef { name: b"name".as_bstr(), email: b"foo@example.com".as_bstr(), time: Time { @@ -190,7 +190,7 @@ pub mod decode { let actual = Line { previous_oid: b"a5828ae6b52137b913b978e16cd2334482eb4c1f".as_bstr(), new_oid: b"89b43f80a514aee58b662ad606e6352e03eaeee4".as_bstr(), - signature: git_actor::immutable::Signature { + signature: git_actor::SignatureRef { name: b"Sebastian Thiel".as_bstr(), email: b"foo@example.com".as_bstr(), time: Time { diff --git a/git-ref/src/store/file/log/mod.rs b/git-ref/src/store/file/log/mod.rs index 03a07076633..5cf4951ca5b 100644 --- a/git-ref/src/store/file/log/mod.rs +++ b/git-ref/src/store/file/log/mod.rs @@ -13,7 +13,7 @@ pub struct Line<'a> { pub new_oid: &'a BStr, /// The signature of the currently configured committer. #[cfg_attr(feature = "serde1", serde(borrow))] - pub signature: git_actor::immutable::Signature<'a>, + pub signature: git_actor::SignatureRef<'a>, /// The message providing details about the operation performed in this log line. pub message: &'a BStr, } diff --git a/git-repository/src/easy/mod.rs b/git-repository/src/easy/mod.rs index 5253d3e0922..4c1af267f10 100644 --- a/git-repository/src/easy/mod.rs +++ b/git-repository/src/easy/mod.rs @@ -112,7 +112,7 @@ pub struct State { /// A utility trait to represent access to a repository. /// -/// It provides immutable and possibly mutable access. Both types of access are validated at runtime, which may fail +/// It provides signature_ref and possibly mutable access. Both types of access are validated at runtime, which may fail /// or may block, depending on the implementation. /// /// Furthermore it provides access to additional state for use with the [`Repository`]. It is designed for thread-local diff --git a/git-traverse/src/tree/recorder.rs b/git-traverse/src/tree/recorder.rs index 09e00d00b0f..d86e044acc3 100644 --- a/git-traverse/src/tree/recorder.rs +++ b/git-traverse/src/tree/recorder.rs @@ -9,7 +9,7 @@ use git_object::{ use crate::tree::{visit, visit::Action}; /// An owned entry as observed by a call to [`visit_(tree|nontree)(…)`][visit::Visit::visit_tree()], enhanced with the full path to it. -/// Otherwise similar to [`immutable::tree::Entry`][git_object::immutable::tree::Entry]. +/// Otherwise similar to [`signature_ref::tree::Entry`][git_object::signature_ref::tree::Entry]. #[derive(Clone, Debug, PartialEq, Eq)] pub struct Entry { /// The kind of entry, similar to entries in a unix directory tree. From 08a18498d62f1d5bdabbb4712b08f3d17d63e16c Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 25 Aug 2021 16:44:29 +0800 Subject: [PATCH 2/3] [actor #173] refactor --- git-actor/src/lib.rs | 2 +- git-actor/src/signature.rs | 2 +- git-actor/src/{types.rs => time.rs} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename git-actor/src/{types.rs => time.rs} (100%) diff --git a/git-actor/src/lib.rs b/git-actor/src/lib.rs index 84e79e306dd..ceeb42bb635 100644 --- a/git-actor/src/lib.rs +++ b/git-actor/src/lib.rs @@ -60,4 +60,4 @@ pub struct Time { pub sign: Sign, } -mod types; +mod time; diff --git a/git-actor/src/signature.rs b/git-actor/src/signature.rs index b7f0aa1e974..16cdebdef30 100644 --- a/git-actor/src/signature.rs +++ b/git-actor/src/signature.rs @@ -29,7 +29,7 @@ mod convert { impl Signature { /// Borrow this instance as signature_ref - pub fn borrow(&self) -> SignatureRef<'_> { + pub fn to_ref(&self) -> SignatureRef<'_> { SignatureRef { name: self.name.as_ref(), email: self.email.as_ref(), diff --git a/git-actor/src/types.rs b/git-actor/src/time.rs similarity index 100% rename from git-actor/src/types.rs rename to git-actor/src/time.rs From 2d7956a22511d73b767e443dac21b60e93f286dd Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 25 Aug 2021 16:49:48 +0800 Subject: [PATCH 3/3] [actor #173] fix docs --- git-object/src/commit.rs | 2 +- git-object/src/lib.rs | 2 +- git-object/src/mutable/mod.rs | 4 ++-- git-object/src/types.rs | 2 +- git-pack/src/data/object.rs | 4 ++-- git-traverse/src/tree/recorder.rs | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/git-object/src/commit.rs b/git-object/src/commit.rs index 5c5ba36bdb0..d932c07eda5 100644 --- a/git-object/src/commit.rs +++ b/git-object/src/commit.rs @@ -2,7 +2,7 @@ use bstr::{BStr, ByteSlice}; use crate::immutable; -/// An iterator over extra headers in [owned][crate::mutable::Commit] and [borrowed][signature_ref::Commit] commits. +/// An iterator over extra headers in [owned][crate::mutable::Commit] and [borrowed][immutable::Commit] commits. pub struct ExtraHeaders { inner: I, } diff --git a/git-object/src/lib.rs b/git-object/src/lib.rs index b6fab6fce7a..ea719bc4a17 100644 --- a/git-object/src/lib.rs +++ b/git-object/src/lib.rs @@ -1,4 +1,4 @@ -//! This crate provides types for [read-only git objects][signature_ref::Object] backed by bytes provided in git's serialization format +//! This crate provides types for [read-only git objects][immutable::Object] backed by bytes provided in git's serialization format //! as well as [mutable versions][mutable::Object] of these. The latter can be serialized into git's serialization format for objects. #![forbid(unsafe_code)] #![deny(rust_2018_idioms, missing_docs)] diff --git a/git-object/src/mutable/mod.rs b/git-object/src/mutable/mod.rs index 2e99a939eec..a685298ac95 100644 --- a/git-object/src/mutable/mod.rs +++ b/git-object/src/mutable/mod.rs @@ -1,8 +1,8 @@ //! Mutable objects with each field being separately allocated and changeable. //! //! Mutable objects are Commits, Trees, Blobs and Tags that can be changed and serialized. -//! They either created using object [construction][Object] or by [deserializing existing objects][crate::signature_ref::Object::from_bytes()] -//! and converting these [into mutable copies][crate::signature_ref::Object::into_mutable()] for adjustments. +//! They either created using object [construction][Object] or by [deserializing existing objects][crate::immutable::Object::from_bytes()] +//! and converting these [into mutable copies][crate::immutable::Object::into_mutable()] for adjustments. const NL: &[u8; 1] = b"\n"; const SPACE: &[u8; 1] = b" "; diff --git a/git-object/src/types.rs b/git-object/src/types.rs index 35eaaec5809..af87e3da92a 100644 --- a/git-object/src/types.rs +++ b/git-object/src/types.rs @@ -56,7 +56,7 @@ impl fmt::Display for Kind { pub mod tree { /// The mode of items storable in a tree, similar to the file mode on a unix file system. /// - /// Used in [mutable::Entry][crate::mutable::tree::Entry] and [signature_ref::Entry][crate::signature_ref::tree::Entry]. + /// Used in [mutable::Entry][crate::mutable::tree::Entry] and [signature_ref::Entry][crate::immutable::tree::Entry]. #[derive(Clone, Copy, PartialEq, Eq, Debug, Ord, PartialOrd, Hash)] #[repr(u16)] #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] diff --git a/git-pack/src/data/object.rs b/git-pack/src/data/object.rs index 505a51a4998..fe1433e6c18 100644 --- a/git-pack/src/data/object.rs +++ b/git-pack/src/data/object.rs @@ -22,11 +22,11 @@ impl<'a> Object<'a> { pack_location: None, } } - /// Decodes the data in the backing slice into a [`git_object::signature_ref::Object`], allowing to access all of its data + /// Decodes the data in the backing slice into a [`git_object::immutable::Object`], allowing to access all of its data /// conveniently. The cost of parsing an object is negligible. /// /// **Note** that [mutable, decoded objects][git_object::mutable::Object] can be created from a [`crate::data::Object`] - /// using [`git_object::signature_ref::Object::into_mutable()`]. + /// using [`git_object::immutable::Object::into_mutable()`]. pub fn decode(&self) -> Result, immutable::object::decode::Error> { Ok(match self.kind { git_object::Kind::Tree => immutable::Object::Tree(immutable::Tree::from_bytes(self.data)?), diff --git a/git-traverse/src/tree/recorder.rs b/git-traverse/src/tree/recorder.rs index d86e044acc3..1273c4767d3 100644 --- a/git-traverse/src/tree/recorder.rs +++ b/git-traverse/src/tree/recorder.rs @@ -9,7 +9,7 @@ use git_object::{ use crate::tree::{visit, visit::Action}; /// An owned entry as observed by a call to [`visit_(tree|nontree)(…)`][visit::Visit::visit_tree()], enhanced with the full path to it. -/// Otherwise similar to [`signature_ref::tree::Entry`][git_object::signature_ref::tree::Entry]. +/// Otherwise similar to [`signature_ref::tree::Entry`][git_object::immutable::tree::Entry]. #[derive(Clone, Debug, PartialEq, Eq)] pub struct Entry { /// The kind of entry, similar to entries in a unix directory tree.