pub struct Signature {
pub name: String,
pub email: String,
pub time: OffsetDateTime,
}Expand description
Parsed author or committer identity from a full header or reflog identity line.
Fields§
§name: StringDisplay name (may be empty).
email: StringEmail address inside <…>.
time: OffsetDateTimeTimestamp with the recorded ±HHMM offset preserved.
Implementations§
Source§impl Signature
impl Signature
Sourcepub fn new(
name: impl Into<String>,
email: impl Into<String>,
time: OffsetDateTime,
) -> Result<Self, SignatureError>
pub fn new( name: impl Into<String>, email: impl Into<String>, time: OffsetDateTime, ) -> Result<Self, SignatureError>
Build a signature for writing into a commit or tag.
§Parameters
name: display name (may be empty).email: address written inside<…>(may be empty).time: timestamp; its UTC offset becomes the±HHMMfield.
§Errors
See Self::validate.
§Examples
use grit_lib::ident::Signature;
use time::{OffsetDateTime, UtcOffset};
let time = OffsetDateTime::from_unix_timestamp(1_700_000_000)?
.to_offset(UtcOffset::from_hms(-8, 0, 0)?);
let sig = Signature::new("Ada Lovelace", "ada@example.com", time)?;
assert_eq!(sig.header_line(), "Ada Lovelace <ada@example.com> 1700000000 -0800");
assert!(Signature::new("Ada <x>", "ada@example.com", time).is_err());Sourcepub fn validate(&self) -> Result<(), SignatureError>
pub fn validate(&self) -> Result<(), SignatureError>
Check that Self::header_line yields an identity line git fsck accepts.
§Errors
SignatureError::ForbiddenCharacterwhen the name or email contains<,>, or a control character other than tab.SignatureError::BeforeEpochwhen the time is before 1970-01-01 UTC.SignatureError::SubMinuteOffsetwhen the UTC offset has a seconds component, which the±HHMMfield cannot represent.
Sourcepub fn reflog_name_email(&self) -> String
pub fn reflog_name_email(&self) -> String
Name <email> for a reflog identity column; the timestamp is taken from
crate::refs::store::ReflogUpdate::time when the entry is formatted.
Sourcepub fn header_line(&self) -> String
pub fn header_line(&self) -> String
Render as a header payload: Name <email> <unix-seconds> <±HHMM>.
The result is what follows author / committer / tagger in an object.
It is only fsck-clean when Self::validate succeeds.
Sourcepub fn format_rfc3339(&self) -> Option<String>
pub fn format_rfc3339(&self) -> Option<String>
Format Self::time as RFC 3339 (includes the original offset).
Trait Implementations§
impl Eq for Signature
Source§impl FromStr for Signature
impl FromStr for Signature
Source§fn from_str(line: &str) -> Result<Self, Self::Err>
fn from_str(line: &str) -> Result<Self, Self::Err>
Parse a full header identity line (Name <email> <unix-seconds> <±HHMM>).
§Errors
SignatureError::Malformed when the line does not have exactly one <email>, has a
missing, non-numeric, or overflowing date, or has text after the ±HHMM timezone;
otherwise the Signature::validate errors.