gix_mailmap/snapshot/
signature.rsuse std::borrow::Cow;
use bstr::{BStr, BString, ByteSlice};
#[derive(Default, PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Signature<'a> {
pub name: Cow<'a, BStr>,
pub email: Cow<'a, BStr>,
pub time: gix_date::Time,
}
impl<'a> From<Signature<'a>> for gix_actor::Signature {
fn from(s: Signature<'a>) -> Self {
gix_actor::Signature {
name: s.name.into_owned(),
email: s.email.into_owned(),
time: s.time,
}
}
}
impl<'a> From<gix_actor::SignatureRef<'a>> for Signature<'a> {
fn from(s: gix_actor::SignatureRef<'a>) -> Self {
Signature {
name: s.name.into(),
email: s.email.into(),
time: s.time,
}
}
}
pub struct ResolvedSignature<'a> {
pub name: Option<&'a BStr>,
pub email: Option<&'a BStr>,
}
impl<'a> ResolvedSignature<'a> {
pub(crate) fn try_new(
new_email: Option<&'a BString>,
matched_email: &'a BStr,
current_email: &'_ BStr,
new_name: Option<&'a BString>,
) -> Option<Self> {
let new_email = new_email
.map(|n| n.as_bstr())
.or_else(|| (matched_email != current_email).then_some(matched_email));
match (new_email, new_name) {
(None, None) => None,
(new_email, new_name) => Some(ResolvedSignature {
email: new_email.map(|v| v.as_bstr()),
name: new_name.map(|v| v.as_bstr()),
}),
}
}
}