-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A new command to allow scripts to query the mailmap information. * es/check-mailmap: t4203: test check-mailmap command invocation builtin: add git-check-mailmap command
- Loading branch information
Showing
9 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
git-check-mailmap(1) | ||
==================== | ||
|
||
NAME | ||
---- | ||
git-check-mailmap - Show canonical names and email addresses of contacts | ||
|
||
|
||
SYNOPSIS | ||
-------- | ||
[verse] | ||
'git check-mailmap' [options] <contact>... | ||
|
||
|
||
DESCRIPTION | ||
----------- | ||
|
||
For each ``Name $$<user@host>$$'' or ``$$<user@host>$$'' from the command-line | ||
or standard input (when using `--stdin`), look up the person's canonical name | ||
and email address (see "Mapping Authors" below). If found, print them; | ||
otherwise print the input as-is. | ||
|
||
|
||
OPTIONS | ||
------- | ||
--stdin:: | ||
Read contacts, one per line, from the standard input after exhausting | ||
contacts provided on the command-line. | ||
|
||
|
||
OUTPUT | ||
------ | ||
|
||
For each contact, a single line is output, terminated by a newline. If the | ||
name is provided or known to the 'mailmap', ``Name $$<user@host>$$'' is | ||
printed; otherwise only ``$$<user@host>$$'' is printed. | ||
|
||
|
||
MAPPING AUTHORS | ||
--------------- | ||
|
||
include::mailmap.txt[] | ||
|
||
|
||
GIT | ||
--- | ||
Part of the linkgit:git[1] suite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "builtin.h" | ||
#include "mailmap.h" | ||
#include "parse-options.h" | ||
#include "string-list.h" | ||
|
||
static int use_stdin; | ||
static const char * const check_mailmap_usage[] = { | ||
N_("git check-mailmap [options] <contact>..."), | ||
NULL | ||
}; | ||
|
||
static const struct option check_mailmap_options[] = { | ||
OPT_BOOL(0, "stdin", &use_stdin, N_("also read contacts from stdin")), | ||
OPT_END() | ||
}; | ||
|
||
static void check_mailmap(struct string_list *mailmap, const char *contact) | ||
{ | ||
const char *name, *mail; | ||
size_t namelen, maillen; | ||
struct ident_split ident; | ||
|
||
if (split_ident_line(&ident, contact, strlen(contact))) | ||
die(_("unable to parse contact: %s"), contact); | ||
|
||
name = ident.name_begin; | ||
namelen = ident.name_end - ident.name_begin; | ||
mail = ident.mail_begin; | ||
maillen = ident.mail_end - ident.mail_begin; | ||
|
||
map_user(mailmap, &mail, &maillen, &name, &namelen); | ||
|
||
if (namelen) | ||
printf("%.*s ", (int)namelen, name); | ||
printf("<%.*s>\n", (int)maillen, mail); | ||
} | ||
|
||
int cmd_check_mailmap(int argc, const char **argv, const char *prefix) | ||
{ | ||
int i; | ||
struct string_list mailmap = STRING_LIST_INIT_NODUP; | ||
|
||
git_config(git_default_config, NULL); | ||
argc = parse_options(argc, argv, prefix, check_mailmap_options, | ||
check_mailmap_usage, 0); | ||
if (argc == 0 && !use_stdin) | ||
die(_("no contacts specified")); | ||
|
||
read_mailmap(&mailmap, NULL); | ||
|
||
for (i = 0; i < argc; ++i) | ||
check_mailmap(&mailmap, argv[i]); | ||
maybe_flush_or_die(stdout, "stdout"); | ||
|
||
if (use_stdin) { | ||
struct strbuf buf = STRBUF_INIT; | ||
while (strbuf_getline(&buf, stdin, '\n') != EOF) { | ||
check_mailmap(&mailmap, buf.buf); | ||
maybe_flush_or_die(stdout, "stdout"); | ||
} | ||
strbuf_release(&buf); | ||
} | ||
|
||
clear_mailmap(&mailmap); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,11 @@ fuzz_blame () { | |
} | ||
|
||
test_expect_success setup ' | ||
cat >contacts <<-\EOF && | ||
A U Thor <[email protected]> | ||
nick1 <[email protected]> | ||
EOF | ||
echo one >one && | ||
git add one && | ||
test_tick && | ||
|
@@ -23,6 +28,44 @@ test_expect_success setup ' | |
git commit --author "nick1 <[email protected]>" -m second | ||
' | ||
|
||
test_expect_success 'check-mailmap no arguments' ' | ||
test_must_fail git check-mailmap | ||
' | ||
|
||
test_expect_success 'check-mailmap arguments' ' | ||
cat >expect <<-\EOF && | ||
A U Thor <[email protected]> | ||
nick1 <[email protected]> | ||
EOF | ||
git check-mailmap \ | ||
"A U Thor <[email protected]>" \ | ||
"nick1 <[email protected]>" >actual && | ||
test_cmp expect actual | ||
' | ||
|
||
test_expect_success 'check-mailmap --stdin' ' | ||
cat >expect <<-\EOF && | ||
A U Thor <[email protected]> | ||
nick1 <[email protected]> | ||
EOF | ||
git check-mailmap --stdin <contacts >actual && | ||
test_cmp expect actual | ||
' | ||
|
||
test_expect_success 'check-mailmap --stdin arguments' ' | ||
cat >expect <<-\EOF && | ||
Internal Guy <[email protected]> | ||
EOF | ||
cat <contacts >>expect && | ||
git check-mailmap --stdin "Internal Guy <[email protected]>" \ | ||
<contacts >actual && | ||
test_cmp expect actual | ||
' | ||
|
||
test_expect_success 'check-mailmap bogus contact' ' | ||
test_must_fail git check-mailmap bogus | ||
' | ||
|
||
cat >expect <<\EOF | ||
A U Thor (1): | ||
initial | ||
|