|
21 | 21 | GIT_BEGIN_DECL |
22 | 22 |
|
23 | 23 | /** |
24 | | - * A single entry parsed from a mailmap. |
25 | | - */ |
26 | | -typedef struct git_mailmap_entry { |
27 | | - unsigned int version; |
28 | | - |
29 | | - const char *real_name; /**< the real name (may be NULL) */ |
30 | | - const char *real_email; /**< the real email (may be NULL) */ |
31 | | - const char *replace_name; /**< the name to replace (may be NULL) */ |
32 | | - const char *replace_email; /**< the email to replace */ |
33 | | -} git_mailmap_entry; |
34 | | - |
35 | | -#define GIT_MAILMAP_ENTRY_VERSION 1 |
36 | | -#define GIT_MAILMAP_ENTRY_INIT {GIT_MAILMAP_ENTRY_VERSION} |
37 | | - |
38 | | -/** |
39 | | - * Create a mailmap object by parsing a mailmap file. Malformed entries in the |
40 | | - * mailmap are ignored. |
| 24 | + * Allocate a new mailmap object. |
41 | 25 | * |
42 | | - * The mailmap must be freed with 'git_mailmap_free'. |
| 26 | + * This object is empty, so you'll have to add a mailmap file before you can do |
| 27 | + * anything with it. The mailmap must be freed with 'git_mailmap_free'. |
43 | 28 | * |
44 | | - * @param out pointer to store the mailmap |
45 | | - * @param buffer buffer to parse the mailmap from |
46 | | - * @return 0 on success, otherwise an error code |
| 29 | + * @param out pointer to store the new mailmap |
| 30 | + * @return 0 on success, or an error code |
47 | 31 | */ |
48 | | -GIT_EXTERN(int) git_mailmap_from_buffer(git_mailmap **out, git_buf *buffer); |
| 32 | +GIT_EXTERN(int) git_mailmap_new(git_mailmap **out); |
49 | 33 |
|
50 | 34 | /** |
51 | | - * Create a mailmap object from the given repository. Malformed entries in the |
52 | | - * mailmap are ignored. |
53 | | - * |
54 | | - * If the repository is not bare, the repository's working directory root will |
55 | | - * be checked for the '.mailmap' file to be parsed. |
56 | | - * |
57 | | - * If the repository is bare, the repository's HEAD commit's tree root will be |
58 | | - * searched for the '.mailmap' file to be parsed. |
59 | | - * |
60 | | - * The mailmap must be freed with 'git_mailmap_free'. |
| 35 | + * Free the mailmap and its associated memory. |
61 | 36 | * |
62 | | - * @param out pointer to store the mailmap |
63 | | - * @param repo repository to find the .mailmap in |
64 | | - * @return 0 on success; GIT_ENOTFOUND if .mailmap could not be found, |
65 | | - * otherwise an error code. |
| 37 | + * @param mm the mailmap to free |
66 | 38 | */ |
67 | | -GIT_EXTERN(int) git_mailmap_from_repo(git_mailmap **out, git_repository *repo); |
| 39 | +GIT_EXTERN(void) git_mailmap_free(git_mailmap *mm); |
68 | 40 |
|
69 | 41 | /** |
70 | | - * Free a mailmap created by 'git_mailmap_from_buffer' or |
71 | | - * 'git_mailmap_from_repo'. |
| 42 | + * Add a single entry to the given mailmap object. If the entry already exists, |
| 43 | + * it will be replaced with the new entry. |
| 44 | + * |
| 45 | + * @param mm mailmap to add the entry to |
| 46 | + * @param real_name the real name to use, or NULL |
| 47 | + * @param real_email the real email to use, or NULL |
| 48 | + * @param replace_name the name to replace, or NULL |
| 49 | + * @param replace_email the email to replace |
| 50 | + * @return 0 if it was added, EEXISTS if it replaced an entry, or an error code |
72 | 51 | */ |
73 | | -GIT_EXTERN(void) git_mailmap_free(git_mailmap *mailmap); |
| 52 | +GIT_EXTERN(int) git_mailmap_add_entry( |
| 53 | + git_mailmap *mm, const char *real_name, const char *real_email, |
| 54 | + const char *replace_name, const char *replace_email); |
74 | 55 |
|
75 | 56 | /** |
76 | | - * Resolve a name and email to the corresponding real name and email. |
| 57 | + * Parse mailmap entries from a buffer. |
77 | 58 | * |
78 | | - * The lifetime of the string results is tied to the `mailmap`, `name`, and |
79 | | - * `email` parameters. |
80 | | - * |
81 | | - * @param name_out either 'name', or the real name to use. |
82 | | - * You should NOT free this value. |
83 | | - * @param email_out either 'email' or the real email to use, |
84 | | - * You should NOT free this value. |
85 | | - * @param mailmap the mailmap to perform the lookup in. (may be NULL) |
86 | | - * @param name the name to resolve. |
87 | | - * @param email the email to resolve. |
88 | | - * @return 0 on success, otherwise an error code. |
| 59 | + * @param mm mailmap to add the entries to |
| 60 | + * @param buf the buffer to read the mailmap file from |
| 61 | + * @return 0 on success, or an error code |
89 | 62 | */ |
90 | | -GIT_EXTERN(int) git_mailmap_resolve( |
91 | | - const char **name_out, const char **email_out, |
92 | | - const git_mailmap *mailmap, const char *name, const char *email); |
| 63 | +GIT_EXTERN(int) git_mailmap_add_buffer(git_mailmap *mm, const git_buf *buf); |
93 | 64 |
|
94 | 65 | /** |
95 | | - * Get the number of mailmap entries in this mailmap. |
| 66 | + * Create a new mailmap instance containing a single mailmap file |
| 67 | + * |
| 68 | + * This method is a simple utility wrapper for the following sequence |
| 69 | + * of calls: |
| 70 | + * - git_mailmap_new |
| 71 | + * - git_mailmap_add_buffer |
| 72 | + * |
| 73 | + * @param out pointer to store the new mailmap |
| 74 | + * @param buf buffer to parse the mailmap from |
| 75 | + * @return 0 on success, or an error code |
96 | 76 | */ |
97 | | -GIT_EXTERN(size_t) git_mailmap_entry_count(const git_mailmap *mailmap); |
| 77 | +GIT_EXTERN(int) git_mailmap_from_buffer(git_mailmap **out, const git_buf *buf); |
98 | 78 |
|
99 | 79 | /** |
100 | | - * Lookup a mailmap entry by index. |
| 80 | + * Create a new mailmap instance from a repository, loading mailmap files based |
| 81 | + * on the repository's configuration. |
101 | 82 | * |
102 | | - * Do not free the mailmap entry, it is owned by the mailmap. |
| 83 | + * Mailmaps are loaded in the following order: |
| 84 | + * 1. '.mailmap' in the root of the repository's working directory, if present. |
| 85 | + * 2. The blob object identified by the 'mailmap.blob' config entry, if set. |
| 86 | + * [NOTE: 'mailmap.blob' defaults to 'HEAD:.mailmap' in bare repositories] |
| 87 | + * 3. The path in the 'mailmap.file' config entry, if set. |
103 | 88 | * |
104 | | - * @return the mailmap entry at index, or NULL if it cannot be found. |
| 89 | + * @param out pointer to store the new mailmap |
| 90 | + * @param repo repository to load mailmap information from |
| 91 | + * @return 0 on success, or an error code |
105 | 92 | */ |
106 | | -GIT_EXTERN(const git_mailmap_entry *) git_mailmap_entry_byindex( |
107 | | - const git_mailmap *mailmap, size_t idx); |
| 93 | +GIT_EXTERN(int) git_mailmap_from_repository( |
| 94 | + git_mailmap **out, git_repository *repo); |
108 | 95 |
|
109 | 96 | /** |
110 | | - * Lookup a mailmap entry by name/email pair. |
| 97 | + * Resolve a name and email to the corresponding real name and email. |
111 | 98 | * |
112 | | - * Do not free the mailmap entry, it is owned by the mailmap. |
| 99 | + * The lifetime of the strings are tied to `mm`, `name`, and `email` parameters. |
113 | 100 | * |
114 | | - * @param mailmap the mailmap to perform the lookup in. (may be NULL) |
115 | | - * @param name the name to perform the lookup with. |
116 | | - * @param email the email to perform the lookup with. |
117 | | - * @return the corresponding mailmap entry, or NULL if it cannot be found. |
| 101 | + * @param real_name pointer to store the real name |
| 102 | + * @param real_email pointer to store the real email |
| 103 | + * @param mm the mailmap to perform a lookup with (may be NULL) |
| 104 | + * @param name the name to look up |
| 105 | + * @param email the email to look up |
| 106 | + * @return 0 on success, or an error code |
118 | 107 | */ |
119 | | -GIT_EXTERN(const git_mailmap_entry *) git_mailmap_entry_lookup( |
120 | | - const git_mailmap *mailmap, const char *name, const char *email); |
| 108 | +GIT_EXTERN(int) git_mailmap_resolve( |
| 109 | + const char **real_name, const char **real_email, |
| 110 | + const git_mailmap *mm, const char *name, const char *email); |
121 | 111 |
|
122 | 112 | /** @} */ |
123 | 113 | GIT_END_DECL |
|
0 commit comments