From d8b8217c8a16944dc61a1553464efabc450a6680 Mon Sep 17 00:00:00 2001 From: Prarit Bhargava Date: Tue, 29 Oct 2019 08:09:14 -0400 Subject: [PATCH] pretty: add "%aL" etc. to show local-part of email addresses In many projects the number of contributors is low enough that users know each other and the full email address doesn't need to be displayed. Displaying only the author's username saves a lot of columns on the screen. Existing 'e/E' (as in "%ae" and "%aE") placeholders would show the author's address as "prarit@redhat.com", which would waste columns to show the same domain-part for all contributors when used in a project internal to redhat. Introduce 'l/L' placeholders that strip '@' and domain part from the e-mail address. Signed-off-by: Prarit Bhargava Signed-off-by: Junio C Hamano --- Documentation/pretty-formats.txt | 6 ++++++ pretty.c | 9 ++++++++- t/t4203-mailmap.sh | 28 ++++++++++++++++++++++++++++ t/t6006-rev-list-format.sh | 8 ++++++-- t/test-lib.sh | 8 ++++++-- 5 files changed, 54 insertions(+), 5 deletions(-) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index b87e2e83e6..31c6e8d2b8 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -163,6 +163,9 @@ The placeholders are: '%ae':: author email '%aE':: author email (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1]) +'%al':: author email local-part (the part before the '@' sign) +'%aL':: author local-part (see '%al') respecting .mailmap, see + linkgit:git-shortlog[1] or linkgit:git-blame[1]) '%ad':: author date (format respects --date= option) '%aD':: author date, RFC2822 style '%ar':: author date, relative @@ -175,6 +178,9 @@ The placeholders are: '%ce':: committer email '%cE':: committer email (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1]) +'%cl':: author email local-part (the part before the '@' sign) +'%cL':: author local-part (see '%cl') respecting .mailmap, see + linkgit:git-shortlog[1] or linkgit:git-blame[1]) '%cd':: committer date (format respects --date= option) '%cD':: committer date, RFC2822 style '%cr':: committer date, relative diff --git a/pretty.c b/pretty.c index b32f036953..93eb6e8370 100644 --- a/pretty.c +++ b/pretty.c @@ -696,7 +696,7 @@ static size_t format_person_part(struct strbuf *sb, char part, mail = s.mail_begin; maillen = s.mail_end - s.mail_begin; - if (part == 'N' || part == 'E') /* mailmap lookup */ + if (part == 'N' || part == 'E' || part == 'L') /* mailmap lookup */ mailmap_name(&mail, &maillen, &name, &namelen); if (part == 'n' || part == 'N') { /* name */ strbuf_add(sb, name, namelen); @@ -706,6 +706,13 @@ static size_t format_person_part(struct strbuf *sb, char part, strbuf_add(sb, mail, maillen); return placeholder_len; } + if (part == 'l' || part == 'L') { /* local-part */ + const char *at = memchr(mail, '@', maillen); + if (at) + maillen = at - mail; + strbuf_add(sb, mail, maillen); + return placeholder_len; + } if (!s.date_begin) goto skip; diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index e8f9c0f5bc..586c3a86b1 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -412,6 +412,34 @@ test_expect_success 'Log output (complex mapping)' ' test_cmp expect actual ' +cat >expect << EOF +Author email cto@coompany.xx has local-part cto +Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME + +Author email me@company.xx has local-part me +Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME + +Author email me@company.xx has local-part me +Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME + +Author email nick2@company.xx has local-part nick2 +Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME + +Author email bugs@company.xx has local-part bugs +Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME + +Author email bugs@company.xx has local-part bugs +Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME + +Author email author@example.com has local-part author +Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME +EOF + +test_expect_success 'Log output (local-part email address)' ' + git log --pretty=format:"Author email %ae has local-part %al%nCommitter email %ce has local-part %cl%n" >actual && + test_cmp expect actual +' + cat >expect << EOF Author: CTO Author: Santa Claus diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index 1f7d3f7acc..ebdc49c496 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -109,31 +109,35 @@ commit $head1 EOF # we don't test relative here -test_format author %an%n%ae%n%ad%n%aD%n%at <