gix_mailmap/
entry.rs

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
use bstr::BStr;

use crate::Entry;

/// Access
impl<'a> Entry<'a> {
    /// The name to map to.
    pub fn new_name(&self) -> Option<&'a BStr> {
        self.new_name
    }
    /// The email map to.
    pub fn new_email(&self) -> Option<&'a BStr> {
        self.new_email
    }
    /// The name to look for and replace.
    pub fn old_name(&self) -> Option<&'a BStr> {
        self.old_name
    }
    /// The email to look for and replace.
    pub fn old_email(&self) -> &'a BStr {
        self.old_email
    }
}

/// Constructors indicating what kind of mapping is created.
///
/// Only these combinations of values are valid.
impl<'a> Entry<'a> {
    /// An entry that changes the name by an email.
    pub fn change_name_by_email(proper_name: impl Into<&'a BStr>, commit_email: impl Into<&'a BStr>) -> Self {
        Entry {
            new_name: Some(proper_name.into()),
            old_email: commit_email.into(),
            ..Default::default()
        }
    }
    /// An entry that changes the email by an email.
    pub fn change_email_by_email(proper_email: impl Into<&'a BStr>, commit_email: impl Into<&'a BStr>) -> Self {
        Entry {
            new_email: Some(proper_email.into()),
            old_email: commit_email.into(),
            ..Default::default()
        }
    }
    /// An entry that changes the email by a name and email.
    pub fn change_email_by_name_and_email(
        proper_email: impl Into<&'a BStr>,
        commit_name: impl Into<&'a BStr>,
        commit_email: impl Into<&'a BStr>,
    ) -> Self {
        Entry {
            new_email: Some(proper_email.into()),
            old_email: commit_email.into(),
            old_name: Some(commit_name.into()),
            ..Default::default()
        }
    }
    /// An entry that changes a name and the email by an email.
    pub fn change_name_and_email_by_email(
        proper_name: impl Into<&'a BStr>,
        proper_email: impl Into<&'a BStr>,
        commit_email: impl Into<&'a BStr>,
    ) -> Self {
        Entry {
            new_name: Some(proper_name.into()),
            new_email: Some(proper_email.into()),
            old_email: commit_email.into(),
            ..Default::default()
        }
    }
    /// An entry that changes a name and email by a name and email.
    pub fn change_name_and_email_by_name_and_email(
        proper_name: impl Into<&'a BStr>,
        proper_email: impl Into<&'a BStr>,
        commit_name: impl Into<&'a BStr>,
        commit_email: impl Into<&'a BStr>,
    ) -> Self {
        Entry {
            new_name: Some(proper_name.into()),
            new_email: Some(proper_email.into()),
            old_name: Some(commit_name.into()),
            old_email: commit_email.into(),
        }
    }
}