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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//! [Parse][parse()] .mailmap files as used in git repositories and remap names and emails
//! using an [accelerated data-structure][Snapshot].
//!
//! ## Examples
//!
//! ```
//! use gix_actor::SignatureRef;
//!
//! let input = b"
//! Joe R. Developer <joe@example.com> <bugs@example.com>
//! Jane Doe <jane@example.com> Jane <bugs@example.com>
//! ";
//!
//! let parsed = gix_mailmap::parse(input)
//! .collect::<Result<Vec<_>, _>>()
//! .unwrap();
//! assert_eq!(parsed.len(), 2);
//!
//! let snapshot = gix_mailmap::Snapshot::new(parsed);
//! let resolved = snapshot.resolve(
//! SignatureRef::from_bytes(b"Jane <bugs@example.com> 1711398853 +0800").unwrap(),
//! );
//!
//! assert_eq!(resolved.name, "Jane Doe");
//! assert_eq!(resolved.email, "jane@example.com");
//! ```
//! ## Feature Flags
use BStr;
///
/// Parse the given `buf` of bytes line by line into mapping [Entries][Entry].
///
/// Errors may occur per line, but it's up to the caller to stop iteration when
/// one is encountered.
/// Similar to [parse()], but will skip all lines that didn't parse correctly, silently squelching all errors.
///
/// A data-structure to efficiently store a list of entries for optimal, case-insensitive lookup by email and
/// optionally name to find mappings to new names and/or emails.
///
/// The memory layout is efficient, even though lots of small allocations are performed to store strings of emails and names.
///
/// ### Handling of invalid `SignatureRef::time`
///
/// As the `time` field in [`SignatureRef`](gix_actor::SignatureRef) as passed by the caller maybe invalid,
/// something that should be very rare but is possible, we decided to not expose this fallibility in the API.
/// Hence, the user may separately check for the correctness of `time`, which we replace with [`gix_date::Time::default()`]
/// in case of parse errors.
/// An typical entry of a mailmap, which always contains an `old_email` by which
/// the mapping is performed to replace the given `new_name` and `new_email`.
///
/// Optionally, `old_name` is also used for lookup.
///
/// Typically created by [parse()].