@@ -4,8 +4,11 @@ use git_actor::SignatureRef;
44use std:: cmp:: Ordering ;
55use std:: ops:: Deref ;
66
7+ /// A resolved signature with borrowed fields for a mapped `name` and/or `email`.
78pub struct ResolvedSignature < ' a > {
9+ /// The mapped name.
810 pub name : Option < & ' a BStr > ,
11+ /// The mapped email.
912 pub email : Option < & ' a BStr > ,
1013}
1114
@@ -165,16 +168,24 @@ impl<'a> From<crate::Entry<'a>> for EmailEntry {
165168}
166169
167170impl Snapshot {
171+ /// Create a new snapshot from the given bytes buffer, ignoring all parse errors that may occour on a line-by-line basis.
172+ ///
173+ /// This is similar to what git does.
168174 pub fn from_bytes ( buf : & [ u8 ] ) -> Self {
169175 Self :: new ( crate :: parse_ignore_errors ( buf) )
170176 }
171177
178+ /// Create a new instance from `entries`.
179+ ///
180+ /// These can be obtained using [crate::parse()].
172181 pub fn new < ' a > ( entries : impl IntoIterator < Item = crate :: Entry < ' a > > ) -> Self {
173182 let mut snapshot = Self :: default ( ) ;
174183 snapshot. merge ( entries) ;
175184 snapshot
176185 }
177186
187+ /// Merge the given `entries` into this instance, possibly overwriting existing mappings with
188+ /// new ones should they collide.
178189 pub fn merge < ' a > ( & mut self , entries : impl IntoIterator < Item = crate :: Entry < ' a > > ) -> & mut Self {
179190 for entry in entries {
180191 let old_email: EncodedStringRef < ' _ > = entry. old_email . into ( ) ;
@@ -195,6 +206,10 @@ impl Snapshot {
195206 self
196207 }
197208
209+ /// Try to resolve `signature` by its contained email and name and provide resolved/mapped names as reference.
210+ /// Return `None` if no such mapping was found.
211+ ///
212+ /// This is the fastest possible lookup as there is no allocation.
198213 pub fn try_resolve_ref < ' a > ( & ' a self , signature : & git_actor:: SignatureRef < ' _ > ) -> Option < ResolvedSignature < ' a > > {
199214 let email: EncodedStringRef < ' _ > = signature. email . into ( ) ;
200215 let pos = self
@@ -214,11 +229,19 @@ impl Snapshot {
214229 }
215230 }
216231
232+ /// Try to resolve `signature` by its contained email and name and provide resolved/mapped names as owned signature,
233+ /// with the mapped name and/or email replaced accordingly.
234+ ///
235+ /// Return `None` if no such mapping was found.
217236 pub fn try_resolve ( & self , signature : & git_actor:: SignatureRef < ' _ > ) -> Option < git_actor:: Signature > {
218237 let new = self . try_resolve_ref ( signature) ?;
219238 enriched_signature ( signature, new)
220239 }
221240
241+ /// Like [`try_resolve()`][Snapshot::try_resolve()], but always returns an owned signature, which might be a copy
242+ /// of `signature` if no mapping was found.
243+ ///
244+ /// Note that this method will always allocate.
222245 pub fn resolve ( & self , signature : & git_actor:: SignatureRef < ' _ > ) -> git_actor:: Signature {
223246 self . try_resolve ( signature) . unwrap_or_else ( || signature. to_owned ( ) )
224247 }
0 commit comments