git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Liam Beguin <liambeguin@gmail.com>
To: git@vger.kernel.org
Cc: Liam Beguin <liambeguin@gmail.com>
Subject: [PATCH 2/2] pretty: add '%aA' to show domain-part of email addresses
Date: Thu, 26 Oct 2023 19:16:05 -0400	[thread overview]
Message-ID: <20231026-pretty-email-domain-v1-2-5d6bfa6615c0@gmail.com> (raw)
In-Reply-To: <20231026-pretty-email-domain-v1-0-5d6bfa6615c0@gmail.com>

Many reports use the email domain to keep track of organizations
contributing to projects.
Add support for formatting the domain-part of a contributor's address so
that this can be done using git itself, with something like:

	git shortlog -sn --group=format:%aA v2.41.0..v2.42.0

Signed-off-by: Liam Beguin <liambeguin@gmail.com>
---
 Documentation/pretty-formats.txt |  6 ++++++
 pretty.c                         | 13 ++++++++++++-
 t/t4203-mailmap.sh               | 28 ++++++++++++++++++++++++++++
 t/t6006-rev-list-format.sh       |  6 ++++--
 4 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index a22f6fceecdd..72102a681c3a 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -195,6 +195,9 @@ The placeholders are:
 '%al':: author email local-part (the part before the '@' sign)
 '%aL':: author email local-part (see '%al') respecting .mailmap, see
 	linkgit:git-shortlog[1] or linkgit:git-blame[1])
+'%aa':: author email domain-part (the part after the '@' sign)
+'%aA':: author email domain-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
@@ -213,6 +216,9 @@ The placeholders are:
 '%cl':: committer email local-part (the part before the '@' sign)
 '%cL':: committer email local-part (see '%cl') respecting .mailmap, see
 	linkgit:git-shortlog[1] or linkgit:git-blame[1])
+'%ca':: committer email domain-part (the part before the '@' sign)
+'%cA':: committer email domain-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 cf964b060cd1..4f5d081589ea 100644
--- a/pretty.c
+++ b/pretty.c
@@ -791,7 +791,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' || part == 'L') /* mailmap lookup */
+	if (part == 'N' || part == 'E' || part == 'L' || part == 'A') /* mailmap lookup */
 		mailmap_name(&mail, &maillen, &name, &namelen);
 	if (part == 'n' || part == 'N') {	/* name */
 		strbuf_add(sb, name, namelen);
@@ -808,6 +808,17 @@ static size_t format_person_part(struct strbuf *sb, char part,
 		strbuf_add(sb, mail, maillen);
 		return placeholder_len;
 	}
+	if (part == 'a' || part == 'A') {	/* domain-part */
+		const char *at = memchr(mail, '@', maillen);
+		if (at) {
+			at += 1;
+			maillen -= at - mail;
+			strbuf_add(sb, at, maillen);
+		} else {
+			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 2016132f5161..35bf7bb05bea 100755
--- a/t/t4203-mailmap.sh
+++ b/t/t4203-mailmap.sh
@@ -624,6 +624,34 @@ test_expect_success 'Log output (local-part email address)' '
 	test_cmp expect actual
 '
 
+test_expect_success 'Log output (domain-part email address)' '
+	cat >expect <<-EOF &&
+	Author email cto@coompany.xx has domain-part coompany.xx
+	Committer email $GIT_COMMITTER_EMAIL has domain-part $TEST_COMMITTER_DOMAIN
+
+	Author email me@company.xx has domain-part company.xx
+	Committer email $GIT_COMMITTER_EMAIL has domain-part $TEST_COMMITTER_DOMAIN
+
+	Author email me@company.xx has domain-part company.xx
+	Committer email $GIT_COMMITTER_EMAIL has domain-part $TEST_COMMITTER_DOMAIN
+
+	Author email nick2@company.xx has domain-part company.xx
+	Committer email $GIT_COMMITTER_EMAIL has domain-part $TEST_COMMITTER_DOMAIN
+
+	Author email bugs@company.xx has domain-part company.xx
+	Committer email $GIT_COMMITTER_EMAIL has domain-part $TEST_COMMITTER_DOMAIN
+
+	Author email bugs@company.xx has domain-part company.xx
+	Committer email $GIT_COMMITTER_EMAIL has domain-part $TEST_COMMITTER_DOMAIN
+
+	Author email author@example.com has domain-part example.com
+	Committer email $GIT_COMMITTER_EMAIL has domain-part $TEST_COMMITTER_DOMAIN
+	EOF
+
+	git log --pretty=format:"Author email %ae has domain-part %aa%nCommitter email %ce has domain-part %ca%n" >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'Log output with --use-mailmap' '
 	test_config mailmap.file complex.map &&
 
diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh
index 573eb97a0f7f..34c686becf2d 100755
--- a/t/t6006-rev-list-format.sh
+++ b/t/t6006-rev-list-format.sh
@@ -163,11 +163,12 @@ commit $head1
 EOF
 
 # we don't test relative here
-test_format author %an%n%ae%n%al%n%ad%n%aD%n%at <<EOF
+test_format author %an%n%ae%n%al%aa%n%ad%n%aD%n%at <<EOF
 commit $head2
 $GIT_AUTHOR_NAME
 $GIT_AUTHOR_EMAIL
 $TEST_AUTHOR_LOCALNAME
+$TEST_AUTHOR_DOMAIN
 Thu Apr 7 15:13:13 2005 -0700
 Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
@@ -180,11 +181,12 @@ Thu, 7 Apr 2005 15:13:13 -0700
 1112911993
 EOF
 
-test_format committer %cn%n%ce%n%cl%n%cd%n%cD%n%ct <<EOF
+test_format committer %cn%n%ce%n%cl%ca%n%cd%n%cD%n%ct <<EOF
 commit $head2
 $GIT_COMMITTER_NAME
 $GIT_COMMITTER_EMAIL
 $TEST_COMMITTER_LOCALNAME
+$TEST_COMMITTER_DOMAIN
 Thu Apr 7 15:13:13 2005 -0700
 Thu, 7 Apr 2005 15:13:13 -0700
 1112911993

-- 
2.39.0



  parent reply	other threads:[~2023-10-26 23:16 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-26 23:16 [PATCH 0/2] pretty: add %aA to show domain-part of email addresses Liam Beguin
2023-10-26 23:16 ` [PATCH 1/2] doc: pretty-formats: add missing word Liam Beguin
2023-10-26 23:16 ` Liam Beguin [this message]
2023-10-27 18:40   ` [PATCH 2/2] pretty: add '%aA' to show domain-part of email addresses Kousik Sanagavarapu
2023-10-28  0:12     ` Junio C Hamano
2023-10-28  2:13       ` Jeff King
2023-10-28  3:22         ` Liam Beguin
2023-10-28  6:58           ` Andy Koppe
2023-10-28  7:02             ` Andy Koppe
2023-10-30  9:10             ` Jeff King
2023-11-01 19:06               ` Liam Beguin
2023-10-29 23:53         ` Junio C Hamano
2023-11-20 20:21           ` Junio C Hamano
2023-12-10 21:07             ` Liam Beguin
2023-10-28  2:20     ` Liam Beguin
2023-10-28 15:27       ` Oswald Buddenhagen
2023-10-28 21:11         ` Andy Koppe
2023-11-03  8:22     ` Andy Koppe
2023-11-03 17:20       ` Kousik Sanagavarapu
2023-11-04  1:54       ` Junio C Hamano
2023-11-04  9:51         ` Andy Koppe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231026-pretty-email-domain-v1-2-5d6bfa6615c0@gmail.com \
    --to=liambeguin@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).