git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] pretty: Add "%aU"|"%au" option to output author's username
@ 2019-10-22 23:28 Prarit Bhargava
  2019-10-22 23:46 ` Junio C Hamano
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Prarit Bhargava @ 2019-10-22 23:28 UTC (permalink / raw)
  To: git; +Cc: Prarit Bhargava

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.
For example displaying "prarit" instead of "prarit@redhat.com" saves 11
columns.

Add a "%aU"|"%au" option that outputs the author's email username.

Also add tests for "%ae" and "%an".

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
---
 Documentation/pretty-formats.txt |  3 +++
 pretty.c                         |  5 +++++
 t/t4202-log.sh                   | 16 ++++++++++++++++
 3 files changed, 24 insertions(+)

diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index b87e2e83e6d0..479a15a8ab12 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])
+'%au':: author username
+'%aU':: author username (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
diff --git a/pretty.c b/pretty.c
index b32f0369531c..2a5b93022050 100644
--- a/pretty.c
+++ b/pretty.c
@@ -706,6 +706,11 @@ static size_t format_person_part(struct strbuf *sb, char part,
 		strbuf_add(sb, mail, maillen);
 		return placeholder_len;
 	}
+	if (part == 'u' || part == 'U') {	/* username */
+		maillen = strstr(s.mail_begin, "@") - s.mail_begin;
+		strbuf_add(sb, mail, maillen);
+		return placeholder_len;
+	}
 
 	if (!s.date_begin)
 		goto skip;
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index e803ba402e9e..2fee0c067197 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -1729,4 +1729,20 @@ test_expect_success 'log --end-of-options' '
        test_cmp expect actual
 '
 
+test_expect_success 'log pretty %an %ae %au' '
+	git checkout -b anaeau &&
+	test_commit anaeau_test anaeau_test_file &&
+	git log --pretty="%an" > actual &&
+	git log --pretty="%ae" >> actual &&
+	git log --pretty="%au" >> actual &&
+	git log > full &&
+	name=$(cat full | grep "^Author: " | awk -F "Author: " " { print \$2 } " | awk -F " <" " { print \$1 } ") &&
+	email=$(cat full | grep "^Author: " | awk -F "<" " { print \$2 } " | awk -F ">" " { print \$1 } ") &&
+	username=$(cat full | grep "^Author: " | awk -F "<" " { print \$2 } " | awk -F ">" " { print \$1 } " | awk -F "@" " { print \$1 } " ) &&
+	echo "${name}" > expect &&
+	echo "${email}" >> expect &&
+	echo "${username}" >> expect &&
+	test_cmp expect actual
+'
+
 test_done
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-10-24 12:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-22 23:28 [PATCH] pretty: Add "%aU"|"%au" option to output author's username Prarit Bhargava
2019-10-22 23:46 ` Junio C Hamano
2019-10-23 15:03   ` Prarit Bhargava
2019-10-22 23:48 ` brian m. carlson
2019-10-23 15:08   ` Prarit Bhargava
2019-10-24  2:29   ` Junio C Hamano
2019-10-24 12:43     ` Prarit Bhargava
2019-10-23  5:02 ` Jeff King
2019-10-23 15:58   ` Prarit Bhargava

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).