pub struct Signature {
pub name: ByteString,
pub email: ByteString,
pub time: GitTime,
pub raw: Vec<u8>,
}Expand description
A typed parse-view of a git identity line (Name <email> <secs> <tz>) as
found on a commit’s author/committer or a tag’s tagger header.
This is a read-only lens over bytes that are stored and re-serialized
verbatim elsewhere (see Signature::raw). It exists so callers can read
the typed name/email/time of an identity without re-implementing git’s
ident-splitting rules, not as a storage format: the object model keeps the
original raw bytes as its source of truth, and round-tripping through this
view is byte-exact precisely because the raw line is retained alongside the
parsed fields (see Signature::to_ident_bytes).
Parse one with Signature::from_ident_line. The time’s timezone
preserves git’s distinction between +0000 (UTC) and -0000 (a sentinel git
writes to mean “timezone unknown”); see GitTime.
Fields§
§name: ByteStringThe identity’s name: the bytes before the < that opens the email,
with one trailing space (the separator) removed. May be empty.
email: ByteStringThe identity’s email: the bytes between the < and > delimiters. May
be empty.
time: GitTimeThe commit/authorship time and its timezone offset.
raw: Vec<u8>The exact original ident-line bytes this view was parsed from, retained
so Signature::to_ident_bytes can reproduce the input byte-for-byte
regardless of any non-canonical whitespace or formatting it contained.
Implementations§
Source§impl Signature
impl Signature
Sourcepub fn from_ident_line(line: &[u8]) -> Option<Self>
pub fn from_ident_line(line: &[u8]) -> Option<Self>
Parse a raw git identity line (Name <email> <unix-secs> <tz>) into a
typed view, returning None when the bytes do not form a well-formed
identity.
The splitting mirrors git’s own split_ident_line: the email is the run
of bytes between the last < and the first following >; the name is
everything before that < (one separating space is dropped); after the
> come a space, the decimal Unix timestamp, a space, and the timezone
token. The name and email may legitimately be empty, but a missing
</> pair, a non-numeric timestamp, or a malformed timezone token all
yield None rather than a lossy guess — this is a best-effort parse
that never panics. The original bytes are retained in
Signature::raw so the parsed view re-serializes byte-identically.
Sourcepub fn to_ident_bytes(&self) -> Vec<u8> ⓘ
pub fn to_ident_bytes(&self) -> Vec<u8> ⓘ
Reproduce the original identity-line bytes.
This returns Signature::raw verbatim, so for any line that
Signature::from_ident_line accepted, from_ident_line(line)? .to_ident_bytes() == line holds byte-for-byte — including the -0000
timezone and any non-canonical spacing the source contained.
Sourcepub fn to_canonical_ident_bytes(&self) -> Vec<u8> ⓘ
pub fn to_canonical_ident_bytes(&self) -> Vec<u8> ⓘ
Re-derive the canonical ident line from the parsed fields alone
(name <email> secs tz), ignoring Signature::raw.
For an identity in git’s canonical form this equals
Signature::to_ident_bytes; it differs only when the source line
carried non-canonical whitespace. Callers wanting byte-exact
reproduction should use Signature::to_ident_bytes; this is provided
for constructing a normalized line from typed parts.