Skip to content

Commit 57cfeab

Browse files
committed
mailmap: Switch mailmap parsing to use the git_parse module
1 parent aa3a24a commit 57cfeab

File tree

8 files changed

+206
-315
lines changed

8 files changed

+206
-315
lines changed

include/git2/mailmap.h

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "common.h"
1111
#include "types.h"
12+
#include "buffer.h"
1213

1314
/**
1415
* @file git2/mailmap.h
@@ -35,22 +36,20 @@ typedef struct git_mailmap_entry {
3536
#define GIT_MAILMAP_ENTRY_INIT {GIT_MAILMAP_ENTRY_VERSION}
3637

3738
/**
38-
* Create a mailmap object by parsing a mailmap file.
39+
* Create a mailmap object by parsing a mailmap file. Malformed entries in the
40+
* mailmap are ignored.
3941
*
4042
* The mailmap must be freed with 'git_mailmap_free'.
4143
*
4244
* @param out pointer to store the mailmap
43-
* @param data raw data buffer to parse
44-
* @param size size of the raw data buffer
45-
* @return 0 on success
45+
* @param buffer buffer to parse the mailmap from
46+
* @return 0 on success, otherwise an error code
4647
*/
47-
GIT_EXTERN(int) git_mailmap_parse(
48-
git_mailmap **out,
49-
const char *data,
50-
size_t size);
48+
GIT_EXTERN(int) git_mailmap_from_buffer(git_mailmap **out, git_buf *buffer);
5149

5250
/**
53-
* Create a mailmap object from the given repository.
51+
* Create a mailmap object from the given repository. Malformed entries in the
52+
* mailmap are ignored.
5453
*
5554
* If the repository is not bare, the repository's working directory root will
5655
* be checked for the '.mailmap' file to be parsed.
@@ -62,20 +61,23 @@ GIT_EXTERN(int) git_mailmap_parse(
6261
*
6362
* @param out pointer to store the mailmap
6463
* @param repo repository to find the .mailmap in
65-
* @return 0 on success; GIT_ENOTFOUND if .mailmap could not be found.
64+
* @return 0 on success; GIT_ENOTFOUND if .mailmap could not be found,
65+
* otherwise an error code.
6666
*/
67-
GIT_EXTERN(int) git_mailmap_from_repo(
68-
git_mailmap **out,
69-
git_repository *repo);
67+
GIT_EXTERN(int) git_mailmap_from_repo(git_mailmap **out, git_repository *repo);
7068

7169
/**
72-
* Free a mailmap created by 'git_mailmap_parse' or 'git_mailmap_from_repo'.
70+
* Free a mailmap created by 'git_mailmap_from_buffer' or
71+
* 'git_mailmap_from_repo'.
7372
*/
7473
GIT_EXTERN(void) git_mailmap_free(git_mailmap *mailmap);
7574

7675
/**
7776
* Resolve a name and email to the corresponding real name and email.
7877
*
78+
* The lifetime of the string results is tied to the `mailmap`, `name`, and
79+
* `email` parameters.
80+
*
7981
* @param name_out either 'name', or the real name to use.
8082
* You should NOT free this value.
8183
* @param email_out either 'email' or the real email to use,
@@ -85,11 +87,8 @@ GIT_EXTERN(void) git_mailmap_free(git_mailmap *mailmap);
8587
* @param email the email to resolve.
8688
*/
8789
GIT_EXTERN(void) git_mailmap_resolve(
88-
const char **name_out,
89-
const char **email_out,
90-
const git_mailmap *mailmap,
91-
const char *name,
92-
const char *email);
90+
const char **name_out, const char **email_out,
91+
const git_mailmap *mailmap, const char *name, const char *email);
9392

9493
/**
9594
* Get the number of mailmap entries in this mailmap.
@@ -104,8 +103,7 @@ GIT_EXTERN(size_t) git_mailmap_entry_count(const git_mailmap *mailmap);
104103
* @return the mailmap entry at index, or NULL if it cannot be found.
105104
*/
106105
GIT_EXTERN(const git_mailmap_entry *) git_mailmap_entry_byindex(
107-
const git_mailmap *mailmap,
108-
size_t idx);
106+
const git_mailmap *mailmap, size_t idx);
109107

110108
/**
111109
* Lookup a mailmap entry by name/email pair.
@@ -118,9 +116,7 @@ GIT_EXTERN(const git_mailmap_entry *) git_mailmap_entry_byindex(
118116
* @return the corresponding mailmap entry, or NULL if it cannot be found.
119117
*/
120118
GIT_EXTERN(const git_mailmap_entry *) git_mailmap_entry_lookup(
121-
const git_mailmap *mailmap,
122-
const char *name,
123-
const char *email);
119+
const git_mailmap *mailmap, const char *name, const char *email);
124120

125121
/** @} */
126122
GIT_END_DECL

src/blame.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ typedef struct git_blame__entry {
6767
struct git_blame {
6868
char *path;
6969
git_repository *repository;
70+
git_mailmap *mailmap;
7071
git_blame_options options;
7172

7273
git_vector hunks;
@@ -84,8 +85,6 @@ struct git_blame {
8485
int num_lines;
8586
const char *final_buf;
8687
git_off_t final_buf_size;
87-
88-
git_mailmap *mailmap;
8988
};
9089

9190
git_blame *git_blame__alloc(

0 commit comments

Comments
 (0)