diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2018-06-18 10:13:11 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-06-18 10:13:11 +0100 |
| commit | 96882f201a21ce2a07678b84cf1df0afa41402f9 (patch) | |
| tree | 447bd4a4edab034d9c88c8b4e9b93ccb126aa250 /include/git2 | |
| parent | 0ecf0e3397502d61787b4e45c3d27fb55b6f9d04 (diff) | |
| parent | f98131be911df5e4c47e51ac92e6e7de79e30219 (diff) | |
| download | libgit2-96882f201a21ce2a07678b84cf1df0afa41402f9.tar.gz | |
Merge pull request #4586 from emilio/mailmap
Add mailmap support.
Diffstat (limited to 'include/git2')
| -rw-r--r-- | include/git2/blame.h | 10 | ||||
| -rw-r--r-- | include/git2/commit.h | 28 | ||||
| -rw-r--r-- | include/git2/mailmap.h | 115 | ||||
| -rw-r--r-- | include/git2/types.h | 3 |
4 files changed, 156 insertions, 0 deletions
diff --git a/include/git2/blame.h b/include/git2/blame.h index 34cb69916..cc9131718 100644 --- a/include/git2/blame.h +++ b/include/git2/blame.h @@ -43,6 +43,10 @@ typedef enum { /** Restrict the search of commits to those reachable following only the * first parents. */ GIT_BLAME_FIRST_PARENT = (1<<4), + /** Use mailmap file to map author and committer names and email addresses + * to canonical real names and email addresses. The mailmap will be read + * from the working directory, or HEAD in a bare repository. */ + GIT_BLAME_USE_MAILMAP = (1<<5), } git_blame_flag_t; /** @@ -108,6 +112,9 @@ GIT_EXTERN(int) git_blame_init_options( * changed. * - `final_start_line_number` is the 1-based line number where this hunk * begins, in the final version of the file + * - `final_signature` is the author of `final_commit_id`. If + * `GIT_BLAME_USE_MAILMAP` has been specified, it will contain the canonical + * real name and email address. * - `orig_commit_id` is the OID of the commit where this hunk was found. This * will usually be the same as `final_commit_id`, except when * `GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES` has been specified. @@ -116,6 +123,9 @@ GIT_EXTERN(int) git_blame_init_options( * - `orig_start_line_number` is the 1-based line number where this hunk begins * in the file named by `orig_path` in the commit specified by * `orig_commit_id`. + * - `orig_signature` is the author of `orig_commit_id`. If + * `GIT_BLAME_USE_MAILMAP` has been specified, it will contain the canonical + * real name and email address. * - `boundary` is 1 iff the hunk has been tracked to a boundary commit (the * root, or the commit specified in git_blame_options.oldest_commit) */ diff --git a/include/git2/commit.h b/include/git2/commit.h index 692b3bdd9..50f2fc963 100644 --- a/include/git2/commit.h +++ b/include/git2/commit.h @@ -173,6 +173,34 @@ GIT_EXTERN(const git_signature *) git_commit_committer(const git_commit *commit) GIT_EXTERN(const git_signature *) git_commit_author(const git_commit *commit); /** + * Get the committer of a commit, using the mailmap to map names and email + * addresses to canonical real names and email addresses. + * + * Call `git_signature_free` to free the signature. + * + * @param out a pointer to store the resolved signature. + * @param commit a previously loaded commit. + * @param mailmap the mailmap to resolve with. (may be NULL) + * @return 0 or an error code + */ +GIT_EXTERN(int) git_commit_committer_with_mailmap( + git_signature **out, const git_commit *commit, const git_mailmap *mailmap); + +/** + * Get the author of a commit, using the mailmap to map names and email + * addresses to canonical real names and email addresses. + * + * Call `git_signature_free` to free the signature. + * + * @param out a pointer to store the resolved signature. + * @param commit a previously loaded commit. + * @param mailmap the mailmap to resolve with. (may be NULL) + * @return 0 or an error code + */ +GIT_EXTERN(int) git_commit_author_with_mailmap( + git_signature **out, const git_commit *commit, const git_mailmap *mailmap); + +/** * Get the full raw text of the commit header. * * @param commit a previously loaded commit diff --git a/include/git2/mailmap.h b/include/git2/mailmap.h new file mode 100644 index 000000000..7c3f60fcc --- /dev/null +++ b/include/git2/mailmap.h @@ -0,0 +1,115 @@ +/* + * Copyright (C) the libgit2 contributors. All rights reserved. + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ +#ifndef INCLUDE_git_mailmap_h__ +#define INCLUDE_git_mailmap_h__ + +#include "common.h" +#include "types.h" +#include "buffer.h" + +/** + * @file git2/mailmap.h + * @brief Mailmap parsing routines + * @defgroup git_mailmap Git mailmap routines + * @ingroup Git + * @{ + */ +GIT_BEGIN_DECL + +/** + * Allocate a new mailmap object. + * + * This object is empty, so you'll have to add a mailmap file before you can do + * anything with it. The mailmap must be freed with 'git_mailmap_free'. + * + * @param out pointer to store the new mailmap + * @return 0 on success, or an error code + */ +GIT_EXTERN(int) git_mailmap_new(git_mailmap **out); + +/** + * Free the mailmap and its associated memory. + * + * @param mm the mailmap to free + */ +GIT_EXTERN(void) git_mailmap_free(git_mailmap *mm); + +/** + * Add a single entry to the given mailmap object. If the entry already exists, + * it will be replaced with the new entry. + * + * @param mm mailmap to add the entry to + * @param real_name the real name to use, or NULL + * @param real_email the real email to use, or NULL + * @param replace_name the name to replace, or NULL + * @param replace_email the email to replace + * @return 0 on success, or an error code + */ +GIT_EXTERN(int) git_mailmap_add_entry( + git_mailmap *mm, const char *real_name, const char *real_email, + const char *replace_name, const char *replace_email); + +/** + * Create a new mailmap instance containing a single mailmap file + * + * @param out pointer to store the new mailmap + * @param buf buffer to parse the mailmap from + * @param len the length of the input buffer + * @return 0 on success, or an error code + */ +GIT_EXTERN(int) git_mailmap_from_buffer( + git_mailmap **out, const char *buf, size_t len); + +/** + * Create a new mailmap instance from a repository, loading mailmap files based + * on the repository's configuration. + * + * Mailmaps are loaded in the following order: + * 1. '.mailmap' in the root of the repository's working directory, if present. + * 2. The blob object identified by the 'mailmap.blob' config entry, if set. + * [NOTE: 'mailmap.blob' defaults to 'HEAD:.mailmap' in bare repositories] + * 3. The path in the 'mailmap.file' config entry, if set. + * + * @param out pointer to store the new mailmap + * @param repo repository to load mailmap information from + * @return 0 on success, or an error code + */ +GIT_EXTERN(int) git_mailmap_from_repository( + git_mailmap **out, git_repository *repo); + +/** + * Resolve a name and email to the corresponding real name and email. + * + * The lifetime of the strings are tied to `mm`, `name`, and `email` parameters. + * + * @param real_name pointer to store the real name + * @param real_email pointer to store the real email + * @param mm the mailmap to perform a lookup with (may be NULL) + * @param name the name to look up + * @param email the email to look up + * @return 0 on success, or an error code + */ +GIT_EXTERN(int) git_mailmap_resolve( + const char **real_name, const char **real_email, + const git_mailmap *mm, const char *name, const char *email); + +/** + * Resolve a signature to use real names and emails with a mailmap. + * + * Call `git_signature_free()` to free the data. + * + * @param out new signature + * @param mm mailmap to resolve with + * @param sig signature to resolve + * @return 0 or an error code + */ +GIT_EXTERN(int) git_mailmap_resolve_signature( + git_signature **out, const git_mailmap *mm, const git_signature *sig); + +/** @} */ +GIT_END_DECL +#endif diff --git a/include/git2/types.h b/include/git2/types.h index 67e5bd155..607a62a5a 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -434,6 +434,9 @@ struct git_writestream { void (*free)(git_writestream *stream); }; +/** Representation of .mailmap file state. */ +typedef struct git_mailmap git_mailmap; + /** @} */ GIT_END_DECL |
