pretty: add "%aL"|"%al|%cL|%cl" option to output local-part of email addresses
PATCH v2 1/1 pretty: add "%aL"|"%al|%cL|%cl" option to output 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. For example displaying "prarit" instead of "[email protected]" saves 11 columns.
Add a "%aL"|"%al|%cL|%cl" option that output the local-part of an email address.
Also add tests for "%ae","%an", "%ce", and "%cn".
Changes in v2:
- Changed option to 'L' based on https://www.ietf.org/rfc/rfc2822.txt
definition of 'local-part' of email addresses.
- added additional information to documentation for %cL and %cl
- added mailmap output test
- modified code to use mailmap output for "L" option
- modified code to check if email address field has '@' symbol
- modified tests based on input from Peff
--- Documentation/pretty-formats.txt | 10 ++++++++++ pretty.c | 9 ++++++++- t/t4202-log.sh | 30 ++++++++++++++++++++++++++++++ t/test-lib.sh | 10 ++++++++-- 4 files changed, 56 insertions(+), 3 deletions(-)
Documentation/pretty-formats.txt +10 -0
@@ -163,6 +163,11 @@ The placeholders are: '%ae':: author email '%aE':: author email (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1]) +'%al':: author local-part (the portion of the email address preceding the '@' + symbol) +'%aL':: author local-part (the portion of the email address preceding the '@' + symbol, 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
@@ -175,6 +180,11 @@ The placeholders are: '%ce':: committer email '%cE':: committer email (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1]) +'%cl':: author local-part (the portion of the email address preceding the '@' + symbol) +'%cL':: author local-part (the portion of the email address preceding the '@' + symbol, 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
pretty.c +8 -1
@@ -696,7 +696,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' )/* mailmap lookup */ +if (part =='N' || part =='E' || part =='L' )/* mailmap lookup */ mailmap_name (&mail, &maillen, &name, &namelen);if (part =='n' || part =='N' ) {/* name */ strbuf_add (sb, name, namelen);
@@ -706,6 +706,13 @@ static size_t format_person_part(struct strbuf *sb, char part,strbuf_add (sb, mail, maillen);return placeholder_len; } +if (part =='l' || part =='L' ) {/* local-part */ +const char *at =memchr (mail,'@' , maillen); +if (at) + maillen = at - mail; +strbuf_add (sb, mail, maillen); +return placeholder_len; + }if (!s.date_begin) goto skip;
t/t4202-log.sh +30 -0
@@ -1729,4 +1729,34 @@ test_expect_success 'log --end-of-options' ' test_cmp expect actual ' +test_expect_success 'log pretty %an %ae %al %aN %aE %aL' ' + git checkout -b anaeal && + test_commit anaeal_test anaeal_test_file && + git log --pretty="%an%n%ae%n%al%n%aN%n%aE%n%aL" -1 > actual && + { + echo "${GIT_AUTHOR_NAME}" && + echo "${GIT_AUTHOR_EMAIL}" && + echo "${TEST_AUTHOR_LOCALNAME}" + echo "${GIT_AUTHOR_NAME}" && + echo "${GIT_AUTHOR_EMAIL}" && + echo "${TEST_AUTHOR_LOCALNAME}" + } > expect && + test_cmp expect actual +' + +test_expect_success 'log pretty %cn %ce %cl %cN %cE %cL' ' + git checkout -b cncecl && + test_commit cncecl_test cncecl_test_file && + git log --pretty="%cn%n%ce%n%cl%n%cN%n%cE%n%cL" -1 > actual && + { + echo "${GIT_COMMITTER_NAME}" && + echo "${GIT_COMMITTER_EMAIL}" && + echo "${TEST_COMMITTER_LOCALNAME}" + echo "${GIT_COMMITTER_NAME}" && + echo "${GIT_COMMITTER_EMAIL}" && + echo "${TEST_COMMITTER_LOCALNAME}" + } > expect && + test_cmp expect actual +' + test_done
t/test-lib.sh +8 -2
@@ -404,14 +404,20 @@ unset VISUAL EMAIL LANGUAGE COLUMNS $("$PERL_PATH" -e ' unset XDG_CACHE_HOME unset XDG_CONFIG_HOME unset GITPERLLIB [email protected] +TEST_AUTHOR_LOCALNAME=author +TEST_AUTHOR_DOMAIN=example.com +GIT_AUTHOR_EMAIL=${TEST_AUTHOR_LOCALNAME}@${TEST_AUTHOR_DOMAIN} GIT_AUTHOR_NAME='A U Thor' [email protected] +TEST_COMMITTER_LOCALNAME=committer +TEST_COMMITTER_DOMAIN=example.com +GIT_COMMITTER_EMAIL=${TEST_COMMITTER_LOCALNAME}@${TEST_COMMITTER_DOMAIN} GIT_COMMITTER_NAME='C O Mitter' GIT_MERGE_VERBOSITY=5 GIT_MERGE_AUTOEDIT=no export GIT_MERGE_VERBOSITY GIT_MERGE_AUTOEDIT +export TEST_AUTHOR_LOCALNAME TEST_AUTHOR_DOMAIN export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME +export TEST_COMMITTER_LOCALNAME TEST_COMMITTER_DOMAIN export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME export EDITOR
Signature · 1 line
2.21.0
Quoted 10 lines · 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 "[email protected]" saves 11 columns.
Add a "%aL"|"%al|%cL|%cl" option that output the local-part of an email address.
Also add tests for "%ae","%an", "%ce", and "%cn".
Thanks, this is looking better, but I think there are still a few minor bits to address.
Quoted 8 lines
Changes in v2:
- Changed option to 'L' based on https://www.ietf.org/rfc/rfc2822.txt
definition of 'local-part' of email addresses.
- added additional information to documentation for %cL and %cl
- added mailmap output test
- modified code to use mailmap output for "L" option
- modified code to check if email address field has '@' symbol
- modified tests based on input from Peff
This change list is very welcome, but it should generally go after the "---", so that it's not part of the commit message (i.e., it is for people reading this email and reviewing now, but people reading "git log" later would not know or care about v1).
Quoted 4 lines
Signed-off-by Prarit Bhargava <[email protected]>Cc Junio C Hamano <[email protected]>Cc brian m. carlson <[email protected]>Cc Jeff King <[email protected]>
Likewise we do not generally use "cc:" trailers in this project.
Documentation/pretty-formats.txt The placeholders are: · line 167
Quoted 10 lines
Documentation/pretty-formats.txt +2
-0@@ -163,6 +163,11 @@ The placeholders are: '%ae':: author email '%aE':: author email (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1]) +'%al':: author local-part (the portion of the email address preceding the '@' + symbol)
I'm not sure if it is worth saying something like "preceding the @ symbol, or the whole address if no @ symbol". It's a pretty rare case, I'd think, and it does clutter up the wording. So just a thought.
Documentation/pretty-formats.txt The placeholders are: · line 170
Quoted 3 lines
Documentation/pretty-formats.txt +3
-0+'%aL':: author local-part (the portion of the email address preceding the '@' + symbol, respecting .mailmap, see linkgit:git-shortlog[1] or + linkgit:git-blame[1])
This description gets pretty long. I wonder if we can simplify by referring to earlier formats, which would also make clear to the user the relationship between the formats. Perhaps:
'%aL':: author local-part (see '%al'), respecting .mailmap (see '%aE')
And ditto for %cL.
pretty.c static size_t format_person_part(struct strbuf *sb, char part, · line 699
Quoted 10 lines
pretty.c +1
-1@@ -696,7 +696,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' )/* mailmap lookup */ +if (part =='N' || part =='E' || part =='L' )/* mailmap lookup */
I think this is sufficient to fix the mailmap issue. Good.
pretty.c static size_t format_person_part(struct strbuf *sb, char part, · line 715
Quoted 11 lines
pretty.c +7
-0@@ -706,6 +706,13 @@ static size_t format_person_part(struct strbuf *sb, char part,strbuf_add (sb, mail, maillen);return placeholder_len; } +if (part =='l' || part =='L' ) {/* local-part */ +const char *at =memchr (mail,'@' , maillen); +if (at) + maillen = at - mail; +strbuf_add (sb, mail, maillen); +return placeholder_len; + }
And I think this does the counting correctly (mail[maillen] is the "@", so we wouldn't include it; good).
pretty.c static size_t format_person_part(struct strbuf *sb, char part, · line 718
Quoted 3 lines
pretty.c +3
-0+test_expect_success 'log pretty %an %ae %al %aN %aE %aL' ' + git checkout -b anaeal && + test_commit anaeal_test anaeal_test_file &&
Not a big deal, but we could simplify this a bit, I think. There's no need to make a new branch. And there's no need to specify the filename to test_commit. IMHO it's worth being as simple as possible in the tests, because then a reader doesn't have to think about whether those details are important or not.
pretty.c static size_t format_person_part(struct strbuf *sb, char part,
Quoted 1 line
pretty.c +1
-0+ git log --pretty="%an%n%ae%n%al%n%aN%n%aE%n%aL" -1 > actual &&
I didn't think about this before, but...surely we're testing %an, etc already?
Indeed, it looks like t6006 already covers that. Maybe you should be adding to that test? I note that it just hardcodes "[email protected]" in the expectation. I'd be OK with either following the lead there, or doing a separate preparatory patch to use $GIT_AUTHOR_EMAIL, etc.
pretty.c
Quoted 8 lines
pretty.c +8
-0+ { + echo"${GIT_AUTHOR_NAME}" && + echo"${GIT_AUTHOR_EMAIL}" && + echo"${TEST_AUTHOR_LOCALNAME}" + echo"${GIT_AUTHOR_NAME}" && + echo"${GIT_AUTHOR_EMAIL}" && + echo"${TEST_AUTHOR_LOCALNAME}" + } > expect &&
The expectation for %aE is the same as for %ae. So we're not really testing that we actually applied the mailmap. It looks like t4203 has some tests for %aE; you'd probably want to check %aL there.
Quoted 1 line
+test_expect_success 'log pretty %cn %ce %cl %cN %cE %cL' '
Likewise, both of the spots I mentioned cover the committer formats, too.
pretty.c
Quoted 3 lines
pretty.c +3
-0+TEST_AUTHOR_LOCALNAME=author +TEST_AUTHOR_DOMAIN=example.com +GIT_AUTHOR_EMAIL=${TEST_AUTHOR_LOCALNAME}@${TEST_AUTHOR_DOMAIN}
If you follow the lead of t6006 and just hard-code these, then this hunk can go away. But if you do keep it, note that...
pretty.c
Quoted 4 lines
export
GIT_MERGE_VERBOSITYGIT_MERGE_AUTOEDITpretty.c +2
-0+export TEST_AUTHOR_LOCALNAME TEST_AUTHOR_DOMAIN export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME +export TEST_COMMITTER_LOCALNAME TEST_COMMITTER_DOMAIN
These lines are unnecessary. We have to export GIT_AUTHOR_EMAIL, etc, so that the child git-commit process can read it. But there's no need to do so for TEST_*, which are meant to be used by the test scripts themselves.
-Peff
Quoted 8 lines · Jeff King
Quoted 6 lines · 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 "[email protected]" saves 11 columns.
Quoted 8 lines
Quoted 4 lines
Add a "%aL"|"%al|%cL|%cl" option that output the local-part of an email address.
Also add tests for "%ae","%an", "%ce", and "%cn".
Thanks, this is looking better, but I think there are still a few minor bits to address.
Thanks :)
Quoted 21 lines
Quoted 8 lines
Changes in v2:
- Changed option to 'L' based on https://www.ietf.org/rfc/rfc2822.txt
definition of 'local-part' of email addresses.
- added additional information to documentation for %cL and %cl
- added mailmap output test
- modified code to use mailmap output for "L" option
- modified code to check if email address field has '@' symbol
- modified tests based on input from PeffThis change list is very welcome, but it should generally go after the "---", so that it's not part of the commit message (i.e., it is for people reading this email and reviewing now, but people reading "git log" later would not know or care about v1).
Quoted 4 lines
Signed-off-by Prarit Bhargava <[email protected]>Cc Junio C Hamano <[email protected]>Cc brian m. carlson <[email protected]>Cc Jeff King <[email protected]>Likewise we do not generally use "cc:" trailers in this project.
Quoted 15 lines
Documentation/pretty-formats.txt The placeholders are: · line 167
Quoted 10 lines
Documentation/pretty-formats.txt +2
-0@@ -163,6 +163,11 @@ The placeholders are: '%ae':: author email '%aE':: author email (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1]) +'%al':: author local-part (the portion of the email address preceding the '@' + symbol)I'm not sure if it is worth saying something like "preceding the @ symbol, or the whole address if no @ symbol". It's a pretty rare case, I'd think, and it does clutter up the wording. So just a thought.
After adding the text I've decided to keep it the same. As you pointed out it ended up being too long.
Quoted 11 lines
Documentation/pretty-formats.txt The placeholders are: · line 170
Quoted 3 lines
Documentation/pretty-formats.txt +3
-0+'%aL':: author local-part (the portion of the email address preceding the '@' + symbol, respecting .mailmap, see linkgit:git-shortlog[1] or + linkgit:git-blame[1])This description gets pretty long. I wonder if we can simplify by referring to earlier formats, which would also make clear to the user the relationship between the formats. Perhaps:
'%aL':: author local-part (see '%al'), respecting .mailmap (see '%aE')
And ditto for %cL.
I have added this for v3.
<snip>
Quoted 8 lines
I didn't think about this before, but...surely we're testing %an, etc already?
Indeed, it looks like t6006 already covers that. Maybe you should be adding to that test? I note that it just hardcodes "[email protected]" in the expectation. I'd be OK with either following the lead there, or doing a separate preparatory patch to use $GIT_AUTHOR_EMAIL, etc.
I've done separate preparatory patches for both t6006 and t4203 for v3.
Quoted 18 lines
Documentation/pretty-formats.txt The placeholders are:
Quoted 8 lines
Documentation/pretty-formats.txt +8
-0+ { + echo "${GIT_AUTHOR_NAME}" && + echo "${GIT_AUTHOR_EMAIL}" && + echo "${TEST_AUTHOR_LOCALNAME}" + echo "${GIT_AUTHOR_NAME}" && + echo "${GIT_AUTHOR_EMAIL}" && + echo "${TEST_AUTHOR_LOCALNAME}" + } > expect &&The expectation for %aE is the same as for %ae. So we're not really testing that we actually applied the mailmap. It looks like t4203 has some tests for %aE; you'd probably want to check %aL there.
Quoted 1 line
+test_expect_success 'log pretty %cn %ce %cl %cN %cE %cL' '
Likewise, both of the spots I mentioned cover the committer formats, too.
Quoted 7 lines
Documentation/pretty-formats.txt
Quoted 3 lines
Documentation/pretty-formats.txt +3
-0+TEST_AUTHOR_LOCALNAME=author +TEST_AUTHOR_DOMAIN=example.com +GIT_AUTHOR_EMAIL=${TEST_AUTHOR_LOCALNAME}@${TEST_AUTHOR_DOMAIN}If you follow the lead of t6006 and just hard-code these, then this hunk can go away. But if you do keep it, note that...
I implemented the suggested tests in both test files in v3.
Quoted 10 lines
Documentation/pretty-formats.txt
Quoted 4 lines
export
GIT_MERGE_VERBOSITYGIT_MERGE_AUTOEDITDocumentation/pretty-formats.txt +2
-0+export TEST_AUTHOR_LOCALNAME TEST_AUTHOR_DOMAIN export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME +export TEST_COMMITTER_LOCALNAME TEST_COMMITTER_DOMAINThese lines are unnecessary. We have to export
GIT_AUTHOR_EMAIL, etc, so that the child git-commit process can read it. But there's no need to do so for TEST_*, which are meant to be used by the test scripts themselves.
Removed in v3. I will post after running the test suite.
Thanks,
P.
Just a couple of test nits:
t/t4202-log.sh test_expect_success 'log --end-of-options' ' · line 1735
Quoted 4 lines · Prarit Bhargava
t/t4202-log.sh +4
-0+test_expect_success 'log pretty %an %ae %al %aN %aE %aL' ' + git checkout -b anaeal && + test_commit anaeal_test anaeal_test_file && + git log --pretty="%an%n%ae%n%al%n%aN%n%aE%n%aL" -1 > actual &&
Style: no space between redirection and filename, i.e. >actual
t/t4202-log.sh test_expect_success 'log --end-of-options' ' · line 1739
Quoted 4 lines
t/t4202-log.sh +4
-0+ { + echo "${GIT_AUTHOR_NAME}" && + echo "${GIT_AUTHOR_EMAIL}" && + echo "${TEST_AUTHOR_LOCALNAME}"
Broken &&-chain (though with just a bunch of echos it won't really make much of a difference)
t/t4202-log.sh test_expect_success 'log --end-of-options' ' · line 1739
Quoted 3 lines
t/t4202-log.sh +3
-0+ echo "${GIT_AUTHOR_NAME}" && + echo "${GIT_AUTHOR_EMAIL}" && + echo "${TEST_AUTHOR_LOCALNAME}"
All these variables stand on their own, so the curly braces around them are unnecessary.
Quoted 19 lines
t/t4202-log.sh +19
-0+ } > expect && + test_cmp expect actual +' + +test_expect_success 'log pretty %cn %ce %cl %cN %cE %cL' ' + git checkout -b cncecl && + test_commit cncecl_test cncecl_test_file && + git log --pretty="%cn%n%ce%n%cl%n%cN%n%cE%n%cL" -1 > actual && + { + echo "${GIT_COMMITTER_NAME}" && + echo "${GIT_COMMITTER_EMAIL}" && + echo "${TEST_COMMITTER_LOCALNAME}" + echo "${GIT_COMMITTER_NAME}" && + echo "${GIT_COMMITTER_EMAIL}" && + echo "${TEST_COMMITTER_LOCALNAME}" + } > expect && + test_cmp expect actual +' +
Quoted 19 lines · SZEDER Gábor
Just a couple of test nits:
t/t4202-log.sh test_expect_success 'log --end-of-options' ' · line 1735
Quoted 4 lines · Prarit Bhargava
t/t4202-log.sh +4
-0+test_expect_success 'log pretty %an %ae %al %aN %aE %aL' ' + git checkout -b anaeal && + test_commit anaeal_test anaeal_test_file && + git log --pretty="%an%n%ae%n%al%n%aN%n%aE%n%aL" -1 > actual &&Style: no space between redirection and filename, i.e. >actual
t/t4202-log.sh test_expect_success 'log --end-of-options' ' · line 1739
Quoted 4 lines
t/t4202-log.sh +4
-0+ { + echo "${GIT_AUTHOR_NAME}" && + echo "${GIT_AUTHOR_EMAIL}" && + echo "${TEST_AUTHOR_LOCALNAME}"Broken &&-chain (though with just a bunch of echos it won't really make much of a difference)
Quoted 6 lines
t/t4202-log.sh test_expect_success 'log --end-of-options' ' · line 1739
Quoted 3 lines
t/t4202-log.sh +3
-0+ echo "${GIT_AUTHOR_NAME}" && + echo "${GIT_AUTHOR_EMAIL}" && + echo "${TEST_AUTHOR_LOCALNAME}"All these variables stand on their own, so the curly braces around them are unnecessary.
I've changed this code (based on Peff's suggestions) to other tests, however, AFAIK using braces around is considered "good practice".
It can't harm anything to have braces but if the preferred git coding style is to only use them when necessary I will remove them.
P.
Quoted 20 lines
Quoted 20 lines
t/t4202-log.sh +19
-0+ } > expect && + test_cmp expect actual +' + +test_expect_success 'log pretty %cn %ce %cl %cN %cE %cL' ' + git checkout -b cncecl && + test_commit cncecl_test cncecl_test_file && + git log --pretty="%cn%n%ce%n%cl%n%cN%n%cE%n%cL" -1 > actual && + { + echo "${GIT_COMMITTER_NAME}" && + echo "${GIT_COMMITTER_EMAIL}" && + echo "${TEST_COMMITTER_LOCALNAME}" + echo "${GIT_COMMITTER_NAME}" && + echo "${GIT_COMMITTER_EMAIL}" && + echo "${TEST_COMMITTER_LOCALNAME}" + } > expect && + test_cmp expect actual +' +
Quoted 2 lines · Prarit Bhargava
It can't harm anything to have braces but if the preferred git coding style is to only use them when necessary I will remove them.
It harms readability. Don't try to be different just for the sake of being different, especially when you think "it can't harm anything" aka "there is no strong reason to do so (or not to)". Instead, help others by making sure that their eyes do not have to get distracted for such meaningless differences from existing parts of the system.
Thanks.
Quoted 11 lines · Junio C Hamano
Quoted 2 lines · Prarit Bhargava
It can't harm anything to have braces but if the preferred git coding style is to only use them when necessary I will remove them.
It harms readability. Don't try to be different just for the sake of being different, especially when you think "it can't harm anything" aka "there is no strong reason to do so (or not to)". Instead, help others by making sure that their eyes do not have to get distracted for such meaningless differences from existing parts of the system.
Ha :) I did pull them for v3 after doing a search. I didn't reply properly and should have said "I'll do a search". Admittedly I'm concerned in a few spots in the code where it *seems* like something could go wrong if the code is changed. But nothing worth patching over.
P.
Quoted 3 lines
Thanks.