@@ -14,7 +14,15 @@ pub struct ResolvedSignature<'a> {
14
14
}
15
15
16
16
impl < ' a > ResolvedSignature < ' a > {
17
- fn try_new ( new_email : Option < & ' a BString > , new_name : Option < & ' a BString > ) -> Option < Self > {
17
+ fn try_new (
18
+ new_email : Option < & ' a BString > ,
19
+ matched_email : & ' a BStr ,
20
+ current_email : & ' _ BStr ,
21
+ new_name : Option < & ' a BString > ,
22
+ ) -> Option < Self > {
23
+ let new_email = new_email
24
+ . map ( |n| n. as_bstr ( ) )
25
+ . or_else ( || ( matched_email != current_email) . then ( || matched_email) ) ;
18
26
match ( new_email, new_name) {
19
27
( None , None ) => None ,
20
28
( new_email, new_name) => Some ( ResolvedSignature {
@@ -244,6 +252,10 @@ impl Snapshot {
244
252
/// Try to resolve `signature` by its contained email and name and provide resolved/mapped names as reference.
245
253
/// Return `None` if no such mapping was found.
246
254
///
255
+ /// Note that opposed to what git seems to do, we also normalize the case of email addresses to match the one
256
+ /// given in the mailmap. That is, if `Alex@example.com` is the current email, it will be matched and replaced with
257
+ /// `alex@example.com`. This leads to better mapping results and saves entries in the mailmap.
258
+ ///
247
259
/// This is the fastest possible lookup as there is no allocation.
248
260
pub fn try_resolve_ref < ' a > ( & ' a self , signature : git_actor:: SignatureRef < ' _ > ) -> Option < ResolvedSignature < ' a > > {
249
261
let email: EncodedStringRef < ' _ > = signature. email . into ( ) ;
@@ -257,10 +269,20 @@ impl Snapshot {
257
269
258
270
match entry. entries_by_old_name . binary_search_by ( |e| e. old_name . cmp_ref ( name) ) {
259
271
Ok ( pos) => {
260
- let entry = & entry. entries_by_old_name [ pos] ;
261
- ResolvedSignature :: try_new ( entry. new_email . as_ref ( ) , entry. new_name . as_ref ( ) )
272
+ let name_entry = & entry. entries_by_old_name [ pos] ;
273
+ ResolvedSignature :: try_new (
274
+ name_entry. new_email . as_ref ( ) ,
275
+ entry. old_email . as_bstr ( ) ,
276
+ signature. email ,
277
+ name_entry. new_name . as_ref ( ) ,
278
+ )
262
279
}
263
- Err ( _) => ResolvedSignature :: try_new ( entry. new_email . as_ref ( ) , entry. new_name . as_ref ( ) ) ,
280
+ Err ( _) => ResolvedSignature :: try_new (
281
+ entry. new_email . as_ref ( ) ,
282
+ entry. old_email . as_bstr ( ) ,
283
+ signature. email ,
284
+ entry. new_name . as_ref ( ) ,
285
+ ) ,
264
286
}
265
287
}
266
288
0 commit comments