1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use std::borrow::Cow;
use bstr::{BStr, BString, ByteSlice};
#[derive(Default, PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
pub struct Signature<'a> {
pub name: Cow<'a, BStr>,
pub email: Cow<'a, BStr>,
pub time: git_actor::Time,
}
impl<'a> From<Signature<'a>> for git_actor::Signature {
fn from(s: Signature<'a>) -> Self {
git_actor::Signature {
name: s.name.into_owned(),
email: s.email.into_owned(),
time: s.time,
}
}
}
impl<'a> From<git_actor::SignatureRef<'a>> for Signature<'a> {
fn from(s: git_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(|| 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()),
}),
}
}
}