Skip to content

Commit d8b8217

Browse files
praritgitster
authored andcommitted
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 "[email protected]", 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 45e206f commit d8b8217

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

Documentation/pretty-formats.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ The placeholders are:
163163
'%ae':: author email
164164
'%aE':: author email (respecting .mailmap, see linkgit:git-shortlog[1]
165165
or linkgit:git-blame[1])
166+
'%al':: author email local-part (the part before the '@' sign)
167+
'%aL':: author local-part (see '%al') respecting .mailmap, see
168+
linkgit:git-shortlog[1] or linkgit:git-blame[1])
166169
'%ad':: author date (format respects --date= option)
167170
'%aD':: author date, RFC2822 style
168171
'%ar':: author date, relative
@@ -175,6 +178,9 @@ The placeholders are:
175178
'%ce':: committer email
176179
'%cE':: committer email (respecting .mailmap, see
177180
linkgit:git-shortlog[1] or linkgit:git-blame[1])
181+
'%cl':: author email local-part (the part before the '@' sign)
182+
'%cL':: author local-part (see '%cl') respecting .mailmap, see
183+
linkgit:git-shortlog[1] or linkgit:git-blame[1])
178184
'%cd':: committer date (format respects --date= option)
179185
'%cD':: committer date, RFC2822 style
180186
'%cr':: committer date, relative

pretty.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ static size_t format_person_part(struct strbuf *sb, char part,
696696
mail = s.mail_begin;
697697
maillen = s.mail_end - s.mail_begin;
698698

699-
if (part == 'N' || part == 'E') /* mailmap lookup */
699+
if (part == 'N' || part == 'E' || part == 'L') /* mailmap lookup */
700700
mailmap_name(&mail, &maillen, &name, &namelen);
701701
if (part == 'n' || part == 'N') { /* name */
702702
strbuf_add(sb, name, namelen);
@@ -706,6 +706,13 @@ static size_t format_person_part(struct strbuf *sb, char part,
706706
strbuf_add(sb, mail, maillen);
707707
return placeholder_len;
708708
}
709+
if (part == 'l' || part == 'L') { /* local-part */
710+
const char *at = memchr(mail, '@', maillen);
711+
if (at)
712+
maillen = at - mail;
713+
strbuf_add(sb, mail, maillen);
714+
return placeholder_len;
715+
}
709716

710717
if (!s.date_begin)
711718
goto skip;

t/t4203-mailmap.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,34 @@ test_expect_success 'Log output (complex mapping)' '
412412
test_cmp expect actual
413413
'
414414

415+
cat >expect << EOF
416+
Author email [email protected] has local-part cto
417+
Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
418+
419+
Author email [email protected] has local-part me
420+
Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
421+
422+
Author email [email protected] has local-part me
423+
Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
424+
425+
Author email [email protected] has local-part nick2
426+
Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
427+
428+
Author email [email protected] has local-part bugs
429+
Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
430+
431+
Author email [email protected] has local-part bugs
432+
Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
433+
434+
Author email [email protected] has local-part author
435+
Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
436+
EOF
437+
438+
test_expect_success 'Log output (local-part email address)' '
439+
git log --pretty=format:"Author email %ae has local-part %al%nCommitter email %ce has local-part %cl%n" >actual &&
440+
test_cmp expect actual
441+
'
442+
415443
cat >expect << EOF
416444
Author: CTO <[email protected]>
417445
Author: Santa Claus <[email protected]>

t/t6006-rev-list-format.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,31 +109,35 @@ commit $head1
109109
EOF
110110

111111
# we don't test relative here
112-
test_format author %an%n%ae%n%ad%n%aD%n%at <<EOF
112+
test_format author %an%n%ae%n%al%n%ad%n%aD%n%at <<EOF
113113
commit $head2
114114
$GIT_AUTHOR_NAME
115115
$GIT_AUTHOR_EMAIL
116+
$TEST_AUTHOR_LOCALNAME
116117
Thu Apr 7 15:13:13 2005 -0700
117118
Thu, 7 Apr 2005 15:13:13 -0700
118119
1112911993
119120
commit $head1
120121
$GIT_AUTHOR_NAME
121122
$GIT_AUTHOR_EMAIL
123+
$TEST_AUTHOR_LOCALNAME
122124
Thu Apr 7 15:13:13 2005 -0700
123125
Thu, 7 Apr 2005 15:13:13 -0700
124126
1112911993
125127
EOF
126128

127-
test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<EOF
129+
test_format committer %cn%n%ce%n%cl%n%cd%n%cD%n%ct <<EOF
128130
commit $head2
129131
$GIT_COMMITTER_NAME
130132
$GIT_COMMITTER_EMAIL
133+
$TEST_COMMITTER_LOCALNAME
131134
Thu Apr 7 15:13:13 2005 -0700
132135
Thu, 7 Apr 2005 15:13:13 -0700
133136
1112911993
134137
commit $head1
135138
$GIT_COMMITTER_NAME
136139
$GIT_COMMITTER_EMAIL
140+
$TEST_COMMITTER_LOCALNAME
137141
Thu Apr 7 15:13:13 2005 -0700
138142
Thu, 7 Apr 2005 15:13:13 -0700
139143
1112911993

t/test-lib.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,13 @@ unset VISUAL EMAIL LANGUAGE COLUMNS $("$PERL_PATH" -e '
404404
unset XDG_CACHE_HOME
405405
unset XDG_CONFIG_HOME
406406
unset GITPERLLIB
407-
407+
TEST_AUTHOR_LOCALNAME=author
408+
TEST_AUTHOR_DOMAIN=example.com
409+
GIT_AUTHOR_EMAIL=${TEST_AUTHOR_LOCALNAME}@${TEST_AUTHOR_DOMAIN}
408410
GIT_AUTHOR_NAME='A U Thor'
409-
411+
TEST_COMMITTER_LOCALNAME=committer
412+
TEST_COMMITTER_DOMAIN=example.com
413+
GIT_COMMITTER_EMAIL=${TEST_COMMITTER_LOCALNAME}@${TEST_COMMITTER_DOMAIN}
410414
GIT_COMMITTER_NAME='C O Mitter'
411415
GIT_MERGE_VERBOSITY=5
412416
GIT_MERGE_AUTOEDIT=no

0 commit comments

Comments
 (0)