Skip to content

Commit c22f63c

Browse files
committed
Merge branch 'pb/pretty-email-without-domain-part'
The custom format for "git log --format=<format>" learned the l/L placeholder that is similar to e/E that fills in the e-mail address, but only the local part on the left side of '@'. * pb/pretty-email-without-domain-part: pretty: add "%aL" etc. to show local-part of email addresses t4203: use test-lib.sh definitions t6006: use test-lib.sh definitions
2 parents 5731ca3 + d8b8217 commit c22f63c

File tree

5 files changed

+111
-62
lines changed

5 files changed

+111
-62
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: 75 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ fuzz_blame () {
1313
}
1414

1515
test_expect_success setup '
16-
cat >contacts <<-\EOF &&
17-
A U Thor <[email protected]>
16+
cat >contacts <<- EOF &&
17+
$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
1818
1919
EOF
2020
@@ -33,19 +33,19 @@ test_expect_success 'check-mailmap no arguments' '
3333
'
3434

3535
test_expect_success 'check-mailmap arguments' '
36-
cat >expect <<-\EOF &&
37-
A U Thor <[email protected]>
36+
cat >expect <<- EOF &&
37+
$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
3838
3939
EOF
4040
git check-mailmap \
41-
"A U Thor <[email protected]>" \
41+
"$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" \
4242
"nick1 <[email protected]>" >actual &&
4343
test_cmp expect actual
4444
'
4545

4646
test_expect_success 'check-mailmap --stdin' '
47-
cat >expect <<-\EOF &&
48-
A U Thor <[email protected]>
47+
cat >expect <<- EOF &&
48+
$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
4949
5050
EOF
5151
git check-mailmap --stdin <contacts >actual &&
@@ -66,8 +66,8 @@ test_expect_success 'check-mailmap bogus contact' '
6666
test_must_fail git check-mailmap bogus
6767
'
6868

69-
cat >expect <<\EOF
70-
A U Thor (1):
69+
cat >expect << EOF
70+
$GIT_AUTHOR_NAME (1):
7171
initial
7272
7373
nick1 (1):
@@ -90,7 +90,7 @@ nick1 (1):
9090
EOF
9191

9292
test_expect_success 'default .mailmap' '
93-
echo "Repo Guy <[email protected]>" > .mailmap &&
93+
echo "Repo Guy <$GIT_AUTHOR_EMAIL>" > .mailmap &&
9494
git shortlog HEAD >actual &&
9595
test_cmp expect actual
9696
'
@@ -122,7 +122,7 @@ Internal Guy (1):
122122
123123
EOF
124124
test_expect_success 'mailmap.file override' '
125-
echo "External Guy <[email protected]>" >> internal_mailmap/.mailmap &&
125+
echo "External Guy <$GIT_AUTHOR_EMAIL>" >> internal_mailmap/.mailmap &&
126126
git config mailmap.file internal_mailmap/.mailmap &&
127127
git shortlog HEAD >actual &&
128128
test_cmp expect actual
@@ -178,8 +178,8 @@ test_expect_success 'name entry after email entry, case-insensitive' '
178178
test_cmp expect actual
179179
'
180180

181-
cat >expect <<\EOF
182-
A U Thor (1):
181+
cat >expect << EOF
182+
$GIT_AUTHOR_NAME (1):
183183
initial
184184
185185
nick1 (1):
@@ -195,18 +195,18 @@ test_expect_success 'No mailmap files, but configured' '
195195
test_expect_success 'setup mailmap blob tests' '
196196
git checkout -b map &&
197197
test_when_finished "git checkout master" &&
198-
cat >just-bugs <<-\EOF &&
198+
cat >just-bugs <<- EOF &&
199199
Blob Guy <[email protected]>
200200
EOF
201-
cat >both <<-\EOF &&
202-
Blob Guy <[email protected]>
201+
cat >both <<- EOF &&
202+
Blob Guy <$GIT_AUTHOR_EMAIL>
203203
Blob Guy <[email protected]>
204204
EOF
205-
printf "Tricky Guy <[email protected]>" >no-newline &&
205+
printf "Tricky Guy <$GIT_AUTHOR_EMAIL>" >no-newline &&
206206
git add just-bugs both no-newline &&
207207
git commit -m "my mailmaps" &&
208-
echo "Repo Guy <[email protected]>" >.mailmap &&
209-
echo "Internal Guy <[email protected]>" >internal.map
208+
echo "Repo Guy <$GIT_AUTHOR_EMAIL>" >.mailmap &&
209+
echo "Internal Guy <$GIT_AUTHOR_EMAIL>" >internal.map
210210
'
211211

212212
test_expect_success 'mailmap.blob set' '
@@ -266,12 +266,12 @@ test_expect_success 'mailmap.blob defaults to off in non-bare repo' '
266266
git init non-bare &&
267267
(
268268
cd non-bare &&
269-
test_commit one .mailmap "Fake Name <[email protected]>" &&
269+
test_commit one .mailmap "Fake Name <$GIT_AUTHOR_EMAIL>" &&
270270
echo " 1 Fake Name" >expect &&
271271
git shortlog -ns HEAD >actual &&
272272
test_cmp expect actual &&
273273
rm .mailmap &&
274-
echo " 1 A U Thor" >expect &&
274+
echo " 1 $GIT_AUTHOR_NAME" >expect &&
275275
git shortlog -ns HEAD >actual &&
276276
test_cmp expect actual
277277
)
@@ -305,26 +305,26 @@ test_expect_success 'cleanup after mailmap.blob tests' '
305305
'
306306

307307
test_expect_success 'single-character name' '
308-
echo " 1 A <[email protected]>" >expect &&
308+
echo " 1 A <$GIT_AUTHOR_EMAIL>" >expect &&
309309
echo " 1 nick1 <[email protected]>" >>expect &&
310-
echo "A <[email protected]>" >.mailmap &&
310+
echo "A <$GIT_AUTHOR_EMAIL>" >.mailmap &&
311311
test_when_finished "rm .mailmap" &&
312312
git shortlog -es HEAD >actual &&
313313
test_cmp expect actual
314314
'
315315

316316
test_expect_success 'preserve canonical email case' '
317-
echo " 1 A U Thor <[email protected]>" >expect &&
317+
echo " 1 $GIT_AUTHOR_NAME <[email protected]>" >expect &&
318318
echo " 1 nick1 <[email protected]>" >>expect &&
319-
echo "<[email protected]> <[email protected]>" >.mailmap &&
319+
echo "<[email protected]> <$GIT_AUTHOR_EMAIL>" >.mailmap &&
320320
test_when_finished "rm .mailmap" &&
321321
git shortlog -es HEAD >actual &&
322322
test_cmp expect actual
323323
'
324324

325325
# Extended mailmap configurations should give us the following output for shortlog
326-
cat >expect <<\EOF
327-
A U Thor <[email protected]> (1):
326+
cat >expect << EOF
327+
$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> (1):
328328
initial
329329
330330
@@ -370,7 +370,7 @@ test_expect_success 'Shortlog output (complex mapping)' '
370370
git commit --author "CTO <[email protected]>" -m seventh &&
371371
372372
mkdir -p internal_mailmap &&
373-
echo "Committed <[email protected]>" > internal_mailmap/.mailmap &&
373+
echo "Committed <$GIT_COMMITTER_EMAIL>" > internal_mailmap/.mailmap &&
374374
echo "<[email protected]> <[email protected]>" >> internal_mailmap/.mailmap &&
375375
echo "Some Dude <[email protected]> nick1 <[email protected]>" >> internal_mailmap/.mailmap &&
376376
echo "Other Author <[email protected]> nick2 <[email protected]>" >> internal_mailmap/.mailmap &&
@@ -384,57 +384,85 @@ test_expect_success 'Shortlog output (complex mapping)' '
384384
'
385385

386386
# git log with --pretty format which uses the name and email mailmap placemarkers
387-
cat >expect <<\EOF
387+
cat >expect << EOF
388388
Author CTO <[email protected]> maps to CTO <[email protected]>
389-
Committer C O Mitter <[email protected]> maps to Committed <[email protected]>
389+
Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
390390
391391
Author claus <[email protected]> maps to Santa Claus <[email protected]>
392-
Committer C O Mitter <[email protected]> maps to Committed <[email protected]>
392+
Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
393393
394394
Author santa <[email protected]> maps to Santa Claus <[email protected]>
395-
Committer C O Mitter <[email protected]> maps to Committed <[email protected]>
395+
Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
396396
397397
Author nick2 <[email protected]> maps to Other Author <[email protected]>
398-
Committer C O Mitter <[email protected]> maps to Committed <[email protected]>
398+
Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
399399
400400
Author nick2 <[email protected]> maps to Other Author <[email protected]>
401-
Committer C O Mitter <[email protected]> maps to Committed <[email protected]>
401+
Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
402402
403403
Author nick1 <[email protected]> maps to Some Dude <[email protected]>
404-
Committer C O Mitter <[email protected]> maps to Committed <[email protected]>
404+
Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
405405
406-
Author A U Thor <[email protected]> maps to A U Thor <[email protected]>
407-
Committer C O Mitter <[email protected]> maps to Committed <[email protected]>
406+
Author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> maps to $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
407+
Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
408408
EOF
409409

410410
test_expect_success 'Log output (complex mapping)' '
411411
git log --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
412412
test_cmp expect actual
413413
'
414414

415-
cat >expect <<\EOF
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+
443+
cat >expect << EOF
416444
Author: CTO <[email protected]>
417445
Author: Santa Claus <[email protected]>
418446
Author: Santa Claus <[email protected]>
419447
Author: Other Author <[email protected]>
420448
Author: Other Author <[email protected]>
421449
Author: Some Dude <[email protected]>
422-
Author: A U Thor <[email protected]>
450+
Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
423451
EOF
424452

425453
test_expect_success 'Log output with --use-mailmap' '
426454
git log --use-mailmap | grep Author >actual &&
427455
test_cmp expect actual
428456
'
429457

430-
cat >expect <<\EOF
458+
cat >expect << EOF
431459
Author: CTO <[email protected]>
432460
Author: Santa Claus <[email protected]>
433461
Author: Santa Claus <[email protected]>
434462
Author: Other Author <[email protected]>
435463
Author: Other Author <[email protected]>
436464
Author: Some Dude <[email protected]>
437-
Author: A U Thor <[email protected]>
465+
Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
438466
EOF
439467

440468
test_expect_success 'Log output with log.mailmap' '
@@ -443,28 +471,28 @@ test_expect_success 'Log output with log.mailmap' '
443471
'
444472

445473
test_expect_success 'log.mailmap=false disables mailmap' '
446-
cat >expect <<-\EOF &&
474+
cat >expect <<- EOF &&
447475
Author: CTO <[email protected]>
448476
Author: claus <[email protected]>
449477
Author: santa <[email protected]>
450478
Author: nick2 <[email protected]>
451479
Author: nick2 <[email protected]>
452480
Author: nick1 <[email protected]>
453-
Author: A U Thor <[email protected]>
481+
Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
454482
EOF
455483
git -c log.mailmap=False log | grep Author > actual &&
456484
test_cmp expect actual
457485
'
458486

459487
test_expect_success '--no-use-mailmap disables mailmap' '
460-
cat >expect <<-\EOF &&
488+
cat >expect <<- EOF &&
461489
Author: CTO <[email protected]>
462490
Author: claus <[email protected]>
463491
Author: santa <[email protected]>
464492
Author: nick2 <[email protected]>
465493
Author: nick2 <[email protected]>
466494
Author: nick1 <[email protected]>
467-
Author: A U Thor <[email protected]>
495+
Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
468496
EOF
469497
git log --no-use-mailmap | grep Author > actual &&
470498
test_cmp expect actual
@@ -500,8 +528,8 @@ test_expect_success 'Only grep replaced author with --use-mailmap' '
500528
'
501529

502530
# git blame
503-
cat >expect <<\EOF
504-
^OBJI (A U Thor DATE 1) one
531+
cat >expect <<EOF
532+
^OBJI ($GIT_AUTHOR_NAME DATE 1) one
505533
OBJID (Some Dude DATE 2) two
506534
OBJID (Other Author DATE 3) three
507535
OBJID (Other Author DATE 4) four

0 commit comments

Comments
 (0)