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 <prarit@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Prarit Bhargava committed
Oct 29, 2019 at 08:09 UTC
d8b8217c8a16944dc61a1553464efabc450a6680
5 files changed
+54
-5
Documentation/pretty-formats.txt
+6
@@ -163,6 +163,9 @@ The placeholders are:
163
'%ae':: author email
164
'%aE':: author email (respecting .mailmap, see linkgit:git-shortlog[1]
165
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])
169
'%ad':: author date (format respects --date= option)
170
'%aD':: author date, RFC2822 style
171
'%ar':: author date, relative
@@ -175,6 +178,9 @@ The placeholders are:
178
'%ce':: committer email
179
'%cE':: committer email (respecting .mailmap, see
180
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])
184
'%cd':: committer date (format respects --date= option)
185
'%cD':: committer date, RFC2822 style
186
'%cr':: committer date, relative
pretty.c
+8
-1
@@ -696,7 +696,7 @@ static size_t format_person_part(struct strbuf *sb, char part,
696
mail = s.mail_begin;
697
maillen = s.mail_end - s.mail_begin;
698
699
- if (part == 'N' || part == 'E') /* mailmap lookup */
699
+ if (part == 'N' || part == 'E' || part == 'L') /* mailmap lookup */
700
mailmap_name(&mail, &maillen, &name, &namelen);
701
if (part == 'n' || part == 'N') { /* name */
702
strbuf_add(sb, name, namelen);
@@ -706,6 +706,13 @@ static size_t format_person_part(struct strbuf *sb, char part,
706
strbuf_add(sb, mail, maillen);
707
return placeholder_len;
708
}
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
+ }
716
717
if (!s.date_begin)
718
goto skip;
t/t4203-mailmap.sh
+28
@@ -412,6 +412,34 @@ test_expect_success 'Log output (complex mapping)' '
412
test_cmp expect actual
413
'
414
415
+cat >expect << EOF
416
+Author email cto@coompany.xx has local-part cto
417
+Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
418
+
419
+Author email me@company.xx has local-part me
420
+Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
421
+
422
+Author email me@company.xx has local-part me
423
+Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
424
+
425
+Author email nick2@company.xx has local-part nick2
426
+Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
427
+
428
+Author email bugs@company.xx has local-part bugs
429
+Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
430
+
431
+Author email bugs@company.xx has local-part bugs
432
+Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
433
+
434
+Author email author@example.com 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
+
443
cat >expect << EOF
444
Author: CTO <cto@company.xx>
445
Author: Santa Claus <santa.claus@northpole.xx>
t/t6006-rev-list-format.sh
+6
-2
@@ -109,31 +109,35 @@ commit $head1
109
EOF
110
111
# 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
113
commit $head2
114
$GIT_AUTHOR_NAME
115
$GIT_AUTHOR_EMAIL
116
+$TEST_AUTHOR_LOCALNAME
117
Thu Apr 7 15:13:13 2005 -0700
118
Thu, 7 Apr 2005 15:13:13 -0700
119
1112911993
120
commit $head1
121
$GIT_AUTHOR_NAME
122
$GIT_AUTHOR_EMAIL
123
+$TEST_AUTHOR_LOCALNAME
124
Thu Apr 7 15:13:13 2005 -0700
125
Thu, 7 Apr 2005 15:13:13 -0700
126
1112911993
127
EOF
128
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
130
commit $head2
131
$GIT_COMMITTER_NAME
132
$GIT_COMMITTER_EMAIL
133
+$TEST_COMMITTER_LOCALNAME
134
Thu Apr 7 15:13:13 2005 -0700
135
Thu, 7 Apr 2005 15:13:13 -0700
136
1112911993
137
commit $head1
138
$GIT_COMMITTER_NAME
139
$GIT_COMMITTER_EMAIL
140
+$TEST_COMMITTER_LOCALNAME
141
Thu Apr 7 15:13:13 2005 -0700
142
Thu, 7 Apr 2005 15:13:13 -0700
143
1112911993
t/test-lib.sh
+6
-2
@@ -404,9 +404,13 @@ unset VISUAL EMAIL LANGUAGE COLUMNS $("$PERL_PATH" -e '
404
unset XDG_CACHE_HOME
405
unset XDG_CONFIG_HOME
406
unset GITPERLLIB
407
-GIT_AUTHOR_EMAIL=author@example.com
407
+TEST_AUTHOR_LOCALNAME=author
408
+TEST_AUTHOR_DOMAIN=example.com
409
+GIT_AUTHOR_EMAIL=${TEST_AUTHOR_LOCALNAME}@${TEST_AUTHOR_DOMAIN}
410
GIT_AUTHOR_NAME='A U Thor'
409
-GIT_COMMITTER_EMAIL=committer@example.com
411
+TEST_COMMITTER_LOCALNAME=committer
412
+TEST_COMMITTER_DOMAIN=example.com
413
+GIT_COMMITTER_EMAIL=${TEST_COMMITTER_LOCALNAME}@${TEST_COMMITTER_DOMAIN}
414
GIT_COMMITTER_NAME='C O Mitter'
415
GIT_MERGE_VERBOSITY=5
416
GIT_MERGE_AUTOEDIT=no