Add mailmap support to ref-filter
cover Add mailmap support to ref-filter
Add mailmap support to ref-filter, making ref-filter and pretty closer, which is a part of the effort made to unify both ref-filter and pretty.
PATCH 1/2 - Introduces the "test_bad_atom()" function which checks for if the
given error message (either due to "err_bad_arg()" or any other err) is correct.
PATCH 2/2 - The actual mailmap support.
Kousik Sanagavarapu (2):
t/t6300: introduce test_bad_atom()
ref-filter: add mailmap support
Documentation/git-for-each-ref.txt | 6 +- ref-filter.c | 152 ++++++++++++++++++++++------- t/t6300-for-each-ref.sh | 103 +++++++++++++++++++ 3 files changed, 225 insertions(+), 36 deletions(-)
Signature · 1 line
2.42.0.160.g6905eb16ce.dirty
PATCH 1/2 t/t6300: introduce test_bad_atom()
Introduce a new function "test_bad_atom()", which is similar to "test_atom()" but should be used to check whether the correct error message is shown on stderr.
Like "test_atom()", the new function takes three arguments. The three arguments specify the ref, the format and the expected error message respectively, with an optional fourth argument for tweaking "test_expect_*" (which is by default "success").
--- t/t6300-for-each-ref.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
t/t6300-for-each-ref.sh +20 -0
@@ -267,6 +267,26 @@ test_expect_success 'arguments to %(objectname:short=) must be positive integers test_must_fail git for-each-ref --format="%(objectname:short=foo)" ' +test_bad_atom() { + case "$1" in + head) ref=refs/heads/main ;; + tag) ref=refs/tags/testtag ;; + sym) ref=refs/heads/sym ;; + *) ref=$1 ;; + esac + printf '%s\n' "$3">expect + test_expect_${4:-success} $PREREQ "err basic atom: $1 $2" " + test_must_fail git for-each-ref --format='%($2)' $ref 2>actual && + test_cmp expect actual + " +} + +test_bad_atom head 'authoremail:foo' \ + 'fatal: unrecognized %(authoremail) argument: foo' + +test_bad_atom tag 'taggeremail:localpart trim' \ + 'fatal: unrecognized %(taggeremail) argument: trim' + test_date () { f=$1 && committer_date=$2 &&
Signature · 1 line
2.42.0.160.g6905eb16ce.dirty
Re: [PATCH 1/2] t/t6300: introduce test_bad_atom()
Quoted 21 lines · Kousik Sanagavarapu
Introduce a new function "
test_bad_atom()", which is similar to "test_atom()" but should be used to check whether the correct error message is shown on stderr.Like "
test_atom()", the new function takes three arguments. The three arguments specify the ref, the format and the expected error message respectively, with an optional fourth argument for tweaking "test_expect_*" (which is by default "success").Mentored-by Christian Couder <[email protected]>Mentored-by Hariom Verma <[email protected]>Signed-off-by Kousik Sanagavarapu <[email protected]>--- t/t6300-for-each-ref.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)t/t6300-for-each-ref.sh +0
-0
t/t6300-for-each-ref.sh test_expect_success 'arguments to %(objectname:short=) must be positive integers · line 270
Quoted 4 lines
t/t6300-for-each-ref.sh +1
-0@@ -267,6 +267,26 @@ test_expect_success 'arguments to %(objectname:short=) must be positive integers test_must_fail git for-each-ref --format="%(objectname:short=foo)" ' +test_bad_atom() {
Style: have SP on both sides of "()".
t/t6300-for-each-ref.sh test_expect_success 'arguments to %(objectname:short=) must be positive integers · line 276
Quoted 6 lines
t/t6300-for-each-ref.sh +6
-0+ case "$1" in + head) ref=refs/heads/main ;; + tag) ref=refs/tags/testtag ;; + sym) ref=refs/heads/sym ;; + *) ref=$1 ;; + esac
Somehow this indirection makes the two examples we see below harder to understand. Why shouldn't we just write the full refname on th command line of test_bad_atom? That would make it crystal clear which ref each test works on. It does not help that both 'head' and 'sym' refer to a local branch (if the former referred to .git/HEAD or .git/remotes/origin/HEAD it may have been an excellent choice of the name, but that is not what is going on).
t/t6300-for-each-ref.sh test_expect_success 'arguments to %(objectname:short=) must be positive integers · line 277
Quoted 1 line
t/t6300-for-each-ref.sh +1
-0+ printf '%s\n' "$3">expect
Style: need SP before (but not after) '>'.
t/t6300-for-each-ref.sh test_expect_success 'arguments to %(objectname:short=) must be positive integers · line 281
Quoted 4 lines
t/t6300-for-each-ref.sh +4
-0+ test_expect_${4:-success} $PREREQ "err basic atom: $1 $2" " + test_must_fail git for-each-ref --format='%($2)' $ref 2>actual && + test_cmp expect actual + "
It is error prone to have the executable part of test_expect_{success,failure} inside a pair of double quotes and have $variable interpolated _before_ even the arguments to test_expect_{success,failure} are formed. It is much more preferrable to write
test_bad_atom () {
ref=$1 format=$2
printf '%s\n' "$3" >expect
$test_do=test_expect_${4:-success}
$test_do $PREREQ "err basic atom: $ref $format" '
test_must_fail git for-each-ref \
--format="%($format)" "$ref" 2>error &&
test_cmp expect error
'
}This is primarily because you cannot control what is in "$2" to ensure the correctness of the test we see above locally (i.e. if your caller has a single-quote in "$2", the shell script you create for running test_expect_{success,failure} would be syntactically incorrect). By enclosing the executable part inside a pair of single quotes, and having the $variables interpolated when that executable part is evaled when test_expect_{success,failure} runs, you will avoid such problems, and those reading the above can locally know that you are aware of and correctly avoiding such problems.
I guess three among four problems I just pointed out you blindly copied from test_atom. But let's not spread badness (preliminary clean-up to existing badness would be welcome instead).
t/t6300-for-each-ref.sh test_expect_success 'arguments to %(objectname:short=) must be positive integers · line 288
Quoted 7 lines
t/t6300-for-each-ref.sh +7
-0+} + +test_bad_atom head 'authoremail:foo' \ + 'fatal: unrecognized %(authoremail) argument: foo' + +test_bad_atom tag 'taggeremail:localpart trim' \ + 'fatal: unrecognized %(taggeremail) argument: trim'
It is strange to see double SP before 'trim' in this error message. Are we etching a code mistake in stone here? Wouldn't the error message say "...argument: localpart trim" instead, perhaps?
Quoted 3 lines
t/t6300-for-each-ref.sh +0
-0test_date () { f=$1 && committer_date=$2 &&
Re: [PATCH 1/2] t/t6300: introduce test_bad_atom()
Quoted 10 lines · Junio C Hamano
t/t6300-for-each-ref.sh test_expect_success 'arguments to %(objectname:short=) must be positive integers · line 276
Quoted 6 lines
t/t6300-for-each-ref.sh +6
-0+ case "$1" in + head) ref=refs/heads/main ;; + tag) ref=refs/tags/testtag ;; + sym) ref=refs/heads/sym ;; + *) ref=$1 ;; + esacSomehow this indirection makes the two examples we see below harder to understand. ... It does not help that both 'head' and 'sym' refer to a local branch ...
Ah, this "sym" thing is a (rather unnatural) symbolic ref inside refs/heads/ hierarchy, so the naming makes halfway sense. As it is also used in test_atom, I no longer find it all that much disturbing.
Everything else I said in my review still stands, I would think.
Thanks.
Re: [PATCH 1/2] t/t6300: introduce test_bad_atom()
In reply to Junio C HamanoQuoted 6 lines · Junio C Hamano
t/t6300-for-each-ref.sh test_expect_success 'arguments to %(objectname:short=) must be positive integers · line 288
Quoted 2 lines
t/t6300-for-each-ref.sh +2
-0+test_bad_atom tag 'taggeremail:localpart trim' \ + 'fatal: unrecognized %(taggeremail) argument: trim'It is strange to see double SP before 'trim' in this error message. Are we etching a code mistake in stone here? Wouldn't the error message say "...argument: localpart trim" instead, perhaps?
I tried. The fatal message does say ...argument: localpart trim" as I suspected, when you ask for 'taggeremail:localpart trim'.
I think I know what is going on. With the [PATCH 1/2] as-is, this piece does not pass. But because the error message from parsing gets broken by [PATCH 2/2], after applying [PATCH 2/2], the error message will become what the above test expects, hiding the new breakage in the code. And it probably was not noticed before you sent the patches, because you did not test [PATCH 1/2] alone.
Re: [PATCH 1/2] t/t6300: introduce test_bad_atom()
In reply to Junio C HamanoSorry for the late reply.
Quoted 30 lines · Junio C Hamano
Quoted 21 lines · Kousik Sanagavarapu
Introduce a new function "
test_bad_atom()", which is similar to "test_atom()" but should be used to check whether the correct error message is shown on stderr.Like "
test_atom()", the new function takes three arguments. The three arguments specify the ref, the format and the expected error message respectively, with an optional fourth argument for tweaking "test_expect_*" (which is by default "success").Mentored-by Christian Couder <[email protected]>Mentored-by Hariom Verma <[email protected]>Signed-off-by Kousik Sanagavarapu <[email protected]>--- t/t6300-for-each-ref.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)t/t6300-for-each-ref.sh +0
-0t/t6300-for-each-ref.sh test_expect_success 'arguments to %(objectname:short=) must be positive integers · line 270
Quoted 4 lines
t/t6300-for-each-ref.sh +1
-0@@ -267,6 +267,26 @@ test_expect_success 'arguments to %(objectname:short=) must be positive integers test_must_fail git for-each-ref --format="%(objectname:short=foo)" ' +test_bad_atom() {Style: have SP on both sides of "()".
Quoted 5 lines
[...]
t/t6300-for-each-ref.sh test_expect_success 'arguments to %(objectname:short=) must be positive integers · line 277
Quoted 1 line
t/t6300-for-each-ref.sh +1
-0+ printf '%s\n' "$3">expectStyle: need SP before (but not after) '>'.
I'll make these style changes, they slipped by.
Quoted 22 lines
t/t6300-for-each-ref.sh test_expect_success 'arguments to %(objectname:short=) must be positive integers · line 281
Quoted 4 lines
t/t6300-for-each-ref.sh +4
-0+ test_expect_${4:-success} $PREREQ "err basic atom: $1 $2" " + test_must_fail git for-each-ref --format='%($2)' $ref 2>actual && + test_cmp expect actual + "It is error prone to have the executable part of test_expect_{success,failure} inside a pair of double quotes and have $variable interpolated _before_ even the arguments to test_expect_{success,failure} are formed. It is much more preferrable to write
test_bad_atom () { ref=$1 format=$2 printf '%s\n' "$3" >expect $test_do=test_expect_${4:-success} $test_do $PREREQ "err basic atom: $ref $format" ' test_must_fail git for-each-ref \ --format="%($format)" "$ref" 2>error && test_cmp expect error ' }
Quoted 9 lines
This is primarily because you cannot control what is in "$2" to ensure the correctness of the test we see above locally (i.e. if your caller has a single-quote in "$2", the shell script you create for running test_expect_{success,failure} would be syntactically incorrect). By enclosing the executable part inside a pair of single quotes, and having the $variables interpolated when that executable part is
evaled when test_expect_{success,failure} runs, you will avoid such problems, and those reading the above can locally know that you are aware of and correctly avoiding such problems.
I see.
Quoted 3 lines
I guess three among four problems I just pointed out you blindly copied from
test_atom. But let's not spread badness (preliminary clean-up to existing badness would be welcome instead).
Yeah, I had copied it from test_atom. Although I didn't realize that it was bad to implement test_bad_atom the way I did. Thanks for such a nice explanation. So I guess we can include the test_atom cleanup in this series?
Quoted 15 lines
t/t6300-for-each-ref.sh test_expect_success 'arguments to %(objectname:short=) must be positive integers · line 288
Quoted 7 lines
t/t6300-for-each-ref.sh +7
-0+} + +test_bad_atom head 'authoremail:foo' \ + 'fatal: unrecognized %(authoremail) argument: foo' + +test_bad_atom tag 'taggeremail:localpart trim' \ + 'fatal: unrecognized %(taggeremail) argument: trim'It is strange to see double SP before 'trim' in this error message. Are we etching a code mistake in stone here? Wouldn't the error message say "...argument: localpart trim" instead, perhaps?
Quoted 3 lines
test_date() {t/t6300-for-each-ref.sh +0
-0f=$1 && committer_date=$2 &&
So I read the the other replies and it seems that it indeed hides a breakage and yeah I hadn't tested PATCH 1/2 independently. I'll change this too.
Thanks
PATCH 2/2 ref-filter: add mailmap support
In reply to Kousik SanagavarapuAdd mailmap support to ref-filter formats which are similar in pretty. This support is such that the following pretty placeholders are equivalent to the new ref-filter atoms:
%aN = authorname:mailmap
%cN = committername:mailmap
%aE = authoremail:mailmap
%aL = authoremail:mailmap,localpart
%cE = committeremail:mailmap
%cL = committeremail:mailmap,localpart
Additionally, mailmap can also be used with ":trim" option for email by doing something like "authoremail:mailmap,trim".
The above also applies for the "tagger" atom, that is, "taggername:mailmap", "taggeremail:mailmap", "taggeremail:mailmap,trim" and "taggername:mailmap,localpart".
The functionality of ":trim" and ":localpart" remains the same. That is, ":trim" gives the email, but without the angle brackets and ":localpart" gives the part of the email before the '@' character (if such a character is not found then we directly grab everything between the angle brackets).
--- Documentation/git-for-each-ref.txt | 6 +- ref-filter.c | 152 ++++++++++++++++++++++------- t/t6300-for-each-ref.sh | 83 ++++++++++++++++ 3 files changed, 205 insertions(+), 36 deletions(-)
Documentation/git-for-each-ref.txt +5 -1
@@ -303,7 +303,11 @@ Fields that have name-email-date tuple as its value (`author`, and `date` to extract the named component. For email fields (`authoremail`, `committeremail` and `taggeremail`), `:trim` can be appended to get the email without angle brackets, and `:localpart` to get the part before the `@` symbol -out of the trimmed email. +out of the trimmed email. In addition to these, the `:mailmap` option and the +corresponding `:mailmap,trim` and `:mailmap,localpart` can be used (order does +not matter) to get values of the name and email according to the .mailmap file +or according to the file set in the mailmap.file or mailmap.blob configuration +variable (see linkgit:gitmailmap[5]). The raw data in an object is `raw`.
ref-filter.c +117 -35
237 lines not on this page · raw message
t/t6300-for-each-ref.sh +83 -0
135 lines not on this page · raw message
Signature · 1 line
2.42.0.160.g6905eb16ce.dirty
v2 cover Add mailmap support to ref-filter
In reply to Kousik SanagavarapuThanks Junio for review on the previous round.
PATCH 1/3 - Cleanup test_atom to be less error-prone
PATCH 2/3 - Fix hidden breakage
PATCH 3/3 - Unchanged
Kousik Sanagavarapu (3):
t/t6300: cleanup test_atom
t/t6300: introduce test_bad_atom
ref-filter: add mailmap support
Documentation/git-for-each-ref.txt | 6 +- ref-filter.c | 152 ++++++++++++++++++++++------- t/t6300-for-each-ref.sh | 123 +++++++++++++++++++++-- 3 files changed, 239 insertions(+), 42 deletions(-)
Range-diff against v1:
-: ---------- > 1: b28e858e35 t/t6300: cleanup test_atom 1: 0a90b67889 ! 2: ee90d017d5 t/t6300: introduce test_bad_atom()
@@ Metadata
Author: Kousik Sanagavarapu <[email protected]>
## Commit message ##
- t/t6300: introduce test_bad_atom()
+ t/t6300: introduce test_bad_atom
- Introduce a new function "test_bad_atom()", which is similar to
+ Introduce a new function "test_bad_atom", which is similar to
"test_atom()" but should be used to check whether the correct error message is shown on stderr.
- Like "test_atom()", the new function takes three arguments. The three
+ Like "test_atom", the new function takes three arguments. The three
arguments specify the ref, the format and the expected error message respectively, with an optional fourth argument for tweaking "test_expect_*" (which is by default "success").
@@ t/t6300-for-each-ref.sh: test_expect_success 'arguments to %(objectname:short=)
test_must_fail git for-each-ref --format="%(objectname:short=foo)"
'
-+test_bad_atom() {
++test_bad_atom () {
+ case "$1" in
+ head) ref=refs/heads/main ;;
+ tag) ref=refs/tags/testtag ;;
+ sym) ref=refs/heads/sym ;;
+ *) ref=$1 ;;
+ esac
-+ printf '%s\n' "$3">expect
-+ test_expect_${4:-success} $PREREQ "err basic atom: $1 $2" "
-+ test_must_fail git for-each-ref --format='%($2)' $ref 2>actual &&
-+ test_cmp expect actual
-+ "
++ format=$2
++ test_do=test_expect_${4:-success}
++
++ printf '%s\n' "$3" >expect
++ $test_do $PREREQ "err basic atom: $ref $format" '
++ test_must_fail git for-each-ref \
++ --format="%($format)" "$ref" 2>error &&
++ test_cmp expect error
++ '
+}
+
+test_bad_atom head 'authoremail:foo' \
+ 'fatal: unrecognized %(authoremail) argument: foo' +
+test_bad_atom tag 'taggeremail:localpart trim' \
-+ 'fatal: unrecognized %(taggeremail) argument: trim' ++ 'fatal: unrecognized %(taggeremail) argument: localpart trim'
+
test_date () {
f=$1 &&
2: 63fc69f4dc ! 3: fdc14fe80b ref-filter: add mailmap support
@@ t/t6300-for-each-ref.sh: test_atom tag '*objectname' $(git rev-parse refs/tags/t
test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200'
test_atom tag creator 'C O Mitter <[email protected]> 1151968725 +0200'
test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200'
-@@ t/t6300-for-each-ref.sh: test_bad_atom() {
+@@ t/t6300-for-each-ref.sh: test_bad_atom () {
test_bad_atom head 'authoremail:foo' \
'fatal: unrecognized %(authoremail) argument: foo'
@@ t/t6300-for-each-ref.sh: test_bad_atom() {
+ 'fatal: unrecognized %(taggeremail) argument: ;localpart trim'
+
test_bad_atom tag 'taggeremail:localpart trim' \
- 'fatal: unrecognized %(taggeremail) argument: trim'
-
+- 'fatal: unrecognized %(taggeremail) argument: localpart trim'
++ 'fatal: unrecognized %(taggeremail) argument: trim'
++
+test_bad_atom tag 'taggeremail:mailmap,mailmap,trim,qux,localpart,trim' \
+ 'fatal: unrecognized %(taggeremail) argument: qux,localpart,trim'
-+
+
test_date () {
f=$1 &&
- committer_date=$2 &&Signature · 1 line
2.42.0.273.ge948a9aaf4
PATCH v2 1/3 t/t6300: cleanup test_atom
Previously, when the executable part of "test_expect_{success,failure}" (inside "test_atom") got "eval"ed, it would have been syntactically incorrect if the second argument ($2, which is the format) to "test_atom" were enclosed in single quotes because the $variables would get interpolated even before the arguments to "test_expect_{success,failure}" are formed.
So fix this and also some style issues along the way.
--- t/t6300-for-each-ref.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
t/t6300-for-each-ref.sh +10 -6
@@ -41,25 +41,29 @@ test_expect_success setup ' git config push.default current ' -test_atom() { +test_atom () { case "$1" in head) ref=refs/heads/main ;; tag) ref=refs/tags/testtag ;; sym) ref=refs/heads/sym ;; *) ref=$1 ;; esac + format=$2 + test_do=test_expect_${4:-success} + printf '%s\n' "$3" >expected - test_expect_${4:-success} $PREREQ "basic atom: $1 $2" " - git for-each-ref --format='%($2)' $ref >actual && + $test_do $PREREQ "basic atom: $ref $format" ' + git for-each-ref --format="%($format)" "$ref" >actual && sanitize_pgp <actual >actual.clean && test_cmp expected actual.clean - " + ' + # Automatically test "contents:size" atom after testing "contents" - if test "$2" = "contents" + if test "$format" = "contents" then # for commit leg, $3 is changed there expect=$(printf '%s' "$3" | wc -c) - test_expect_${4:-success} $PREREQ "basic atom: $1 contents:size" ' + $test_do $PREREQ "basic atom: $ref contents:size" ' type=$(git cat-file -t "$ref") && case $type in tag)
Signature · 1 line
2.42.0.273.ge948a9aaf4
PATCH v2 2/3 t/t6300: introduce test_bad_atom
In reply to Kousik SanagavarapuIntroduce a new function "test_bad_atom", which is similar to "test_atom()" but should be used to check whether the correct error message is shown on stderr.
Like "test_atom", the new function takes three arguments. The three arguments specify the ref, the format and the expected error message respectively, with an optional fourth argument for tweaking "test_expect_*" (which is by default "success").
--- t/t6300-for-each-ref.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
t/t6300-for-each-ref.sh +24 -0
@@ -271,6 +271,30 @@ test_expect_success 'arguments to %(objectname:short=) must be positive integers test_must_fail git for-each-ref --format="%(objectname:short=foo)" ' +test_bad_atom () { + case "$1" in + head) ref=refs/heads/main ;; + tag) ref=refs/tags/testtag ;; + sym) ref=refs/heads/sym ;; + *) ref=$1 ;; + esac + format=$2 + test_do=test_expect_${4:-success} + + printf '%s\n' "$3" >expect + $test_do $PREREQ "err basic atom: $ref $format" ' + test_must_fail git for-each-ref \ + --format="%($format)" "$ref" 2>error && + test_cmp expect error + ' +} + +test_bad_atom head 'authoremail:foo' \ + 'fatal: unrecognized %(authoremail) argument: foo' + +test_bad_atom tag 'taggeremail:localpart trim' \ + 'fatal: unrecognized %(taggeremail) argument: localpart trim' + test_date () { f=$1 && committer_date=$2 &&
Signature · 1 line
2.42.0.273.ge948a9aaf4
PATCH v2 3/3 ref-filter: add mailmap support
In reply to Kousik SanagavarapuAdd mailmap support to ref-filter formats which are similar in pretty. This support is such that the following pretty placeholders are equivalent to the new ref-filter atoms:
%aN = authorname:mailmap
%cN = committername:mailmap
%aE = authoremail:mailmap
%aL = authoremail:mailmap,localpart
%cE = committeremail:mailmap
%cL = committeremail:mailmap,localpart
Additionally, mailmap can also be used with ":trim" option for email by doing something like "authoremail:mailmap,trim".
The above also applies for the "tagger" atom, that is, "taggername:mailmap", "taggeremail:mailmap", "taggeremail:mailmap,trim" and "taggername:mailmap,localpart".
The functionality of ":trim" and ":localpart" remains the same. That is, ":trim" gives the email, but without the angle brackets and ":localpart" gives the part of the email before the '@' character (if such a character is not found then we directly grab everything between the angle brackets).
--- Documentation/git-for-each-ref.txt | 6 +- ref-filter.c | 152 ++++++++++++++++++++++------- t/t6300-for-each-ref.sh | 85 +++++++++++++++- 3 files changed, 206 insertions(+), 37 deletions(-)
Documentation/git-for-each-ref.txt +5 -1
@@ -303,7 +303,11 @@ Fields that have name-email-date tuple as its value (`author`, and `date` to extract the named component. For email fields (`authoremail`, `committeremail` and `taggeremail`), `:trim` can be appended to get the email without angle brackets, and `:localpart` to get the part before the `@` symbol -out of the trimmed email. +out of the trimmed email. In addition to these, the `:mailmap` option and the +corresponding `:mailmap,trim` and `:mailmap,localpart` can be used (order does +not matter) to get values of the name and email according to the .mailmap file +or according to the file set in the mailmap.file or mailmap.blob configuration +variable (see linkgit:gitmailmap[5]). The raw data in an object is `raw`.
ref-filter.c +117 -35
237 lines not on this page · raw message
t/t6300-for-each-ref.sh +84 -1
135 lines not on this page · raw message
Signature · 1 line
2.42.0.273.ge948a9aaf4