add git-check-mailmap command
Subsystems (2)
v2 cover add git-check-mailmap command
This is a re-roll of [1] which introduces git-check-mailmap. The primary motivation for this command is to expose git's stable, well-tested C-implementation of .mailmap functionality to scripts and porcelains, thus relieving them of the need to reimplement support themselves. The git-contacts [2] script (currently at es/contacts in 'pu') would be one such client. v2 removes the RFC status and addresses comments from reviewers [1].
Changes since v1:
* Add Documentation/git-check-mailmap.txt.
* Add --null alias for -z.
* Use OPT_BOOL rather than deprecated OPT_BOOLEAN.
* Simplify code which outputs normalized contact.
* Settle on "stdout" as argument to maybe_flush_or_die().
* Eliminate diff noise from patch 4/4.
[1]: http://thread.gmane.org/gmane.comp.version-control.git/230068/
[2]: http://thread.gmane.org/gmane.comp.version-control.git/229533/
Eric Sunshine (4):
builtin: add git-check-mailmap command
t4203: test check-mailmap command invocation
t4203: test mailmap functionality directly rather than indirectly
t4203: consolidate test-repository setup
.gitignore | 1 + Documentation/git-check-mailmap.txt | 55 ++++++++ Makefile | 1 + builtin.h | 1 + builtin/check-mailmap.c | 69 ++++++++++ command-list.txt | 1 + contrib/completion/git-completion.bash | 1 + git.c | 1 + t/t4203-mailmap.sh | 234 +++++++++++++++++---------------- 9 files changed, 251 insertions(+), 113 deletions(-) create mode 100644 Documentation/git-check-mailmap.txt create mode 100644 builtin/check-mailmap.c
Signature · 1 line
1.8.3.2
PATCH v2 1/4 builtin: add git-check-mailmap command
Introduce command check-mailmap, similar to check-attr and check-ignore, which allows direct testing of .mailmap configuration.
As plumbing accessible to scripts and other porcelain, check-mailmap publishes the stable, well-tested .mailmap functionality employed by built-in Git commands. Consequently, script authors need not re-implement .mailmap functionality manually, thus avoiding potential quirks and behavioral differences.
--- .gitignore | 1 + Documentation/git-check-mailmap.txt | 55 +++++++++++++++++++++++++++ Makefile | 1 + builtin.h | 1 + builtin/check-mailmap.c | 69 ++++++++++++++++++++++++++++++++++ command-list.txt | 1 + contrib/completion/git-completion.bash | 1 + git.c | 1 + 8 files changed, 130 insertions(+) create mode 100644 Documentation/git-check-mailmap.txt create mode 100644 builtin/check-mailmap.c
.gitignore +1 -0
@@ -23,6 +23,7 @@ /git-cat-file /git-check-attr /git-check-ignore +/git-check-mailmap /git-check-ref-format /git-checkout /git-checkout-index
Documentation/git-check-mailmap.txt new file +55 -0
55 lines not on this page · raw message
Makefile +1 -0
@@ -912,6 +912,7 @@ BUILTIN_OBJS += builtin/bundle.o BUILTIN_OBJS += builtin/cat-file.o BUILTIN_OBJS += builtin/check-attr.o BUILTIN_OBJS += builtin/check-ignore.o +BUILTIN_OBJS += builtin/check-mailmap.o BUILTIN_OBJS += builtin/check-ref-format.o BUILTIN_OBJS += builtin/checkout-index.o BUILTIN_OBJS += builtin/checkout.o
builtin.h +1 -0
@@ -40,6 +40,7 @@ extern int cmd_checkout(int argc, const char **argv, const char *prefix);extern int cmd_checkout_index (int argc,const char **argv,const char *prefix);extern int cmd_check_attr (int argc,const char **argv,const char *prefix);extern int cmd_check_ignore (int argc,const char **argv,const char *prefix); +extern int cmd_check_mailmap (int argc,const char **argv,const char *prefix);extern int cmd_check_ref_format (int argc,const char **argv,const char *prefix);extern int cmd_cherry (int argc,const char **argv,const char *prefix);extern int cmd_cherry_pick (int argc,const char **argv,const char *prefix);
builtin/check-mailmap.c new file +69 -0
69 lines not on this page · raw message
command-list.txt +1 -0
@@ -13,6 +13,7 @@ git-bundle mainporcelain git-cat-file plumbinginterrogators git-check-attr purehelpers git-check-ignore purehelpers +git-check-mailmap purehelpers git-checkout mainporcelain common git-checkout-index plumbingmanipulators git-check-ref-format purehelpers
contrib/completion/git-completion.bash +1 -0
@@ -648,6 +648,7 @@ __git_list_porcelain_commands () cat-file) : plumbing;; check-attr) : plumbing;; check-ignore) : plumbing;; + check-mailmap) : plumbing;; check-ref-format) : plumbing;; checkout-index) : plumbing;; commit-tree) : plumbing;;
git.c +1 -0
@@ -324,6 +324,7 @@ static void handle_internal_command(int argc, const char **argv) { "cat-file", cmd_cat_file, RUN_SETUP }, { "check-attr", cmd_check_attr, RUN_SETUP }, { "check-ignore", cmd_check_ignore, RUN_SETUP | NEED_WORK_TREE }, + { "check-mailmap", cmd_check_mailmap, RUN_SETUP }, { "check-ref-format", cmd_check_ref_format }, { "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE }, { "checkout-index", cmd_checkout_index,
Signature · 1 line
1.8.3.2
Re: [PATCH v2 1/4] builtin: add git-check-mailmap command
Documentation/git-check-mailmap.txt line 22
Quoted 8 lines · Eric Sunshine
Documentation/git-check-mailmap.txt new file +8
-0+DESCRIPTION +----------- + +For each ``Name $$<email@address>$$'' or ``$$<email@address>$$'' provided on +the command-line or standard input (when using `--stdin`), prints a line with +the canonical contact information for that person according to the 'mailmap' +(see "Mapping Authors" below). If no mapping exists for the person, echoes the +provided contact information.
OK. The last part needed a reading and a half for me to realize the "echoes the provided contact information" is the same thing as "the "input string is printed as-is", especially because "contact information" is not defined anywhere in the previous part of the DESCRIPTION section, though. I might be worth starting the paragraph with:
For each contact information (either in the form of ``Name <user@host>'' or ...)
in order to clarify that the two forms of input is what you call "contact information".
builtin/check-mailmap.c line 7
Quoted 13 lines
builtin/check-mailmap.c new file +7
-0@@ -0,0 +1,69 @@ +#include "builtin.h" +#include "mailmap.h" +#include "parse-options.h" +#include "string-list.h" + +static int use_stdin; +static int null_out;
Is there a reason why the variable name should not match that of the corresponding variables in check-ignore and check-attr, which you copied the bulk of the code from?
If there isn't, use "null_term_line" like they do.
builtin/check-mailmap.c line 11
Quoted 4 lines
builtin/check-mailmap.c new file +4
-0+static const char *const check_mailmap_usage[] = { +N_ ("git check-mailmap [options] <contact>..." ), +NULL +};
This mis-indentation looks somewhat unfortunate, but they are shared with other check-blah, and they are meant to contain a rather long string, so let's keep it like so.
builtin/check-mailmap.c line 24
Quoted 6 lines
builtin/check-mailmap.c new file +6
-0+static void check_mailmap (struct string_list *mailmap,const char *contact) +{ +const char *name, *mail; +size_t namelen, maillen; +struct ident_split ident; +char term = null_out ?'\0' :'\n' ;
Is there a reason why the variable name "term" should not match that of the corresponding variables in check-ignore and check-attr, which you copied the bulk of the code from?
If there isn't, use "line_termination" like they do.
Quoted 13 lines
builtin/check-mailmap.c new file +13
-0+if (split_ident_line (&ident, contact,strlen (contact))) +die (_ ("unable to parse contact: %s" ), contact); + + name = ident.name_begin; + namelen = ident.name_end - ident.name_begin; + mail = ident.mail_begin; + maillen = ident.mail_end - ident.mail_begin; + +map_user (mailmap, &mail, &maillen, &name, &namelen); + +if (namelen) +printf ("%.*s " , (int )namelen, name); +printf ("<%.*s>%c" , (int )maillen, mail, term);
builtin/check-mailmap.c line 48
Quoted 10 lines
builtin/check-mailmap.c new file +10
-0+} + +int cmd_check_mailmap (int argc,const char **argv,const char *prefix) +{ +int i; +struct string_list mailmap =STRING_LIST_INIT_NODUP ; + +git_config (git_default_config,NULL ); + argc =parse_options (argc, argv, prefix, check_mailmap_options, + check_mailmap_usage,0 );
It is a bit distracting that the second line that is not indented enough. Either (1) with enough HT and with minimum number of SP, align "argc" and "check_mailmap_usage", or (2) with minimum number of HT and no SP, push "check_mailmap_usage" to the right of opening parenthesis of "(argc". Our code tend to prefer (1).
Quoted 50 lines
builtin/check-mailmap.c new file +21
-0+if (argc ==0 && !use_stdin) +die (_ ("no contacts specified" )); + +read_mailmap (&mailmap,NULL ); + +for (i =0 ; i < argc; ++i) +check_mailmap (&mailmap, argv[i]); +maybe_flush_or_die (stdout,"stdout" ); + +if (use_stdin) { +struct strbuf buf =STRBUF_INIT ; +while (strbuf_getline (&buf, stdin,'\n' ) !=EOF ) { +check_mailmap (&mailmap, buf.buf); +maybe_flush_or_die (stdout,"stdout" ); + } +strbuf_release (&buf); + } + +clear_mailmap (&mailmap); +return 0 ; +}command-list.txt +1
-0@@ -13,6 +13,7 @@ git-bundle mainporcelain git-cat-file plumbinginterrogators git-check-attr purehelpers git-check-ignore purehelpers +git-check-mailmap purehelpers git-checkout mainporcelain common git-checkout-index plumbingmanipulators git-check-ref-format purehelperscontrib/completion/git-completion.bash +1
-0@@ -648,6 +648,7 @@ __git_list_porcelain_commands () cat-file) : plumbing;; check-attr) : plumbing;; check-ignore) : plumbing;; + check-mailmap) : plumbing;; check-ref-format) : plumbing;; checkout-index) : plumbing;; commit-tree) : plumbing;;git.c +0
-0
git.c static void handle_internal_command(int argc, const char **argv) · line 327
Quoted 4 lines
git.c +1
-0@@ -324,6 +324,7 @@ static void handle_internal_command(int argc, const char **argv) { "cat-file", cmd_cat_file, RUN_SETUP }, { "check-attr", cmd_check_attr, RUN_SETUP }, { "check-ignore", cmd_check_ignore, RUN_SETUP | NEED_WORK_TREE }, + { "check-mailmap", cmd_check_mailmap, RUN_SETUP },
As we can read from HEAD:.mailmap these days, the patch is correct that it does not require NEED_WORK_TREE here.
Thanks.
Quoted 3 lines
git.c +0
-0{ "check-ref-format", cmd_check_ref_format }, { "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE }, { "checkout-index", cmd_checkout_index,
Re: [PATCH v2 1/4] builtin: add git-check-mailmap command
Quoted 18 lines · Junio C Hamano
Documentation/git-check-mailmap.txt line 22
Quoted 8 lines · Eric Sunshine
Documentation/git-check-mailmap.txt new file +8
-0+DESCRIPTION +----------- + +For each ``Name $$<email@address>$$'' or ``$$<email@address>$$'' provided on +the command-line or standard input (when using `--stdin`), prints a line with +the canonical contact information for that person according to the 'mailmap' +(see "Mapping Authors" below). If no mapping exists for the person, echoes the +provided contact information.OK. The last part needed a reading and a half for me to realize the "echoes the provided contact information" is the same thing as "the "input string is printed as-is", especially because "contact information" is not defined anywhere in the previous part of the DESCRIPTION section, though. I might be worth starting the paragraph with:
Quoted 5 lines
For each contact information (either in the form of ``Name <user@host>'' or ...)
in order to clarify that the two forms of input is what you call "contact information".
Is this easier to read?
For each ``Name $$<user@host>$$'' or ``$$<user@host>$$'' from the command-line or standard input (when using --stdin), print a line showing either the canonical name and email address (see "Mapping Authors" below), or the input ``Name $$<user@host>$$'' or ``$$<user@host>$$'' if there is no mapping for that person.
Quoted 18 lines
builtin/check-mailmap.c line 7
Quoted 13 lines
builtin/check-mailmap.c new file +7
-0@@ -0,0 +1,69 @@ +#include "builtin.h" +#include "mailmap.h" +#include "parse-options.h" +#include "string-list.h" + +static int use_stdin; +static int null_out;Is there a reason why the variable name should not match that of the corresponding variables in check-ignore and check-attr, which you copied the bulk of the code from?
Quoted 1 line
If there isn't, use "
null_term_line" like they do.
In check-attr, null_term_line indicates that _input_ lines are null-terminated. In check-ignore, null_term_lines is overloaded (and perhaps abused) to mean that both _input_ and _output_ lines are null-terminated. In check-mailmap, -z affects only _output_ lines. A reader of the code can easily be misled into thinking that the variable controls the same function in all three programs, hence null_out was chosen to make it clear that it applies only to output. A lesser reason is that, in the future, someone might add an option to null terminate input lines (distinct from output), and null_in would be a reasonable name for that variable.
Other than the above reasoning, I don't feel strongly about it and can revert the name if you prefer.
Quoted 11 lines
builtin/check-mailmap.c line 24
Quoted 6 lines
builtin/check-mailmap.c new file +6
-0+static void check_mailmap (struct string_list *mailmap,const char *contact) +{ +const char *name, *mail; +size_t namelen, maillen; +struct ident_split ident; +char term = null_out ?'\0' :'\n' ;Is there a reason why the variable name "term" should not match that of the corresponding variables in check-ignore and check-attr, which you copied the bulk of the code from?
Quoted 1 line
If there isn't, use "
line_termination" like they do.
No strong justification. As with 'buf' vs. 'buffer', 'line_termination' required more reading effort without conveying any more information than 'term'.
Quoted 21 lines
Quoted 21 lines
builtin/check-mailmap.c new file +21
-0+if (split_ident_line (&ident, contact,strlen (contact))) +die (_ ("unable to parse contact: %s" ), contact); + + name = ident.name_begin; + namelen = ident.name_end - ident.name_begin; + mail = ident.mail_begin; + maillen = ident.mail_end - ident.mail_begin; + +map_user (mailmap, &mail, &maillen, &name, &namelen); + +if (namelen) +printf ("%.*s " , (int )namelen, name); +printf ("<%.*s>%c" , (int )maillen, mail, term); +} + +int cmd_check_mailmap (int argc,const char **argv,const char *prefix) +{ +int i; +struct string_list mailmap =STRING_LIST_INIT_NODUP ; + +git_config (git_default_config,NULL );
Quoted 8 lines
builtin/check-mailmap.c line 48
Quoted 2 lines
builtin/check-mailmap.c new file +2
-0+ argc =parse_options (argc, argv, prefix, check_mailmap_options, + check_mailmap_usage,0 );It is a bit distracting that the second line that is not indented enough. Either (1) with enough HT and with minimum number of SP, align "argc" and "
check_mailmap_usage", or (2) with minimum number of HT and no SP, push "check_mailmap_usage" to the right of opening parenthesis of "(argc". Our code tend to prefer (1).
Okay.
Re: [PATCH v2 1/4] builtin: add git-check-mailmap command
Quoted 6 lines · Eric Sunshine
Quoted 5 lines
For each contact information (either in the form of ``Name <user@host>'' or ...)
in order to clarify that the two forms of input is what you call "contact information".
Quoted 7 lines
Is this easier to read?
For each ``Name $$<user@host>$$'' or ``$$<user@host>$$'' from the command-line or standard input (when using
--stdin), print a line showing either the canonical name and email address (see "Mapping Authors" below), or the input ``Name $$<user@host>$$'' or ``$$<user@host>$$'' if there is no mapping for that person.
I find it easier than your original, but I do not know if you would want to repeat the "Name... or <user@host>" at the end. It does not seem to add much useful information and is distracting.
Quoted 6 lines
Quoted 1 line
If there isn't, use "
null_term_line" like they do.In check-attr,
null_term_lineindicates that _input_ lines are null-terminated. In check-ignore,null_term_linesis overloaded (and perhaps abused) to mean that both _input_ and _output_ lines are null-terminated.
That is unfortunate but it is good that you found the breakage. As we do not have --nul-terminated-input and --nul-terminated-output options separtely, -z should apply to both input and output. What b4666852 (check-attr: Add --stdin option, 2008-10-07) did is broken. What check-ignore does
We should find a way to fix it. I have a feeling that silently fixing it and seeing if anybody screams might be the best course of action ;-).
Also "git check-ignore -h" advertises "-z" as only affecting "--stdin", which is also wrong. It does affect both input and output as it should, so it should be described as such, I think.
Thanks for noticing.
Re: [PATCH v2 1/4] builtin: add git-check-mailmap command
Quoted 16 lines · Junio C Hamano
Quoted 6 lines · Eric Sunshine
Quoted 5 lines
For each contact information (either in the form of ``Name <user@host>'' or ...)
in order to clarify that the two forms of input is what you call "contact information".
Quoted 7 lines
Is this easier to read?
For each ``Name $$<user@host>$$'' or ``$$<user@host>$$'' from the command-line or standard input (when using
--stdin), print a line showing either the canonical name and email address (see "Mapping Authors" below), or the input ``Name $$<user@host>$$'' or ``$$<user@host>$$'' if there is no mapping for that person.
Quoted 3 lines
I find it easier than your original, but I do not know if you would want to repeat the "Name... or <user@host>" at the end. It does not seem to add much useful information and is distracting.
Next attempt:
For each ``Name $$<user@host>$$'' or ``$$<user@host>$$'' from the command-line or standard input (when using --stdin) look up the person's canonical name and email address (see "Mapping Authors" below). If found, print them; otherwise print the input as-is.
Quoted 9 lines
Quoted 4 lines
In check-attr,
null_term_lineindicates that _input_ lines are null-terminated. In check-ignore,null_term_linesis overloaded (and perhaps abused) to mean that both _input_ and _output_ lines are null-terminated.That is unfortunate but it is good that you found the breakage. As we do not have --nul-terminated-input and --nul-terminated-output options separtely, -z should apply to both input and output. What
b4666852(check-attr: Add --stdin option, 2008-10-07) did is broken.
I can make git-check-mailmap behave this way, however, other than git-check-ignore (which is quite new), there doesn't seem to be any precedence (that I can find) anywhere else in git which ties input and output null-termination to a single switch. Is it desirable to do so or should the user have more fine-grained control? ("xargs -0" comes to mind when thinking of a null-termination input switch.)
Quoted 3 lines
Also "git check-ignore -h" advertises "-z" as only affecting "--stdin", which is also wrong. It does affect both input and output as it should, so it should be described as such, I think.
I also noticed this. (It was copied from check-attr.c).
Re: [PATCH v2 1/4] builtin: add git-check-mailmap command
Quoted 10 lines · Eric Sunshine
Quoted 3 lines
I find it easier than your original, but I do not know if you would want to repeat the "Name... or <user@host>" at the end. It does not seem to add much useful information and is distracting.
Next attempt:
For each ``Name $$<user@host>$$'' or ``$$<user@host>$$'' from the command-line or standard input (when using
--stdin) look up the person's canonical name and email address (see "Mapping Authors" below). If found, print them; otherwise print the input as-is.
Nice.
Quoted 3 lines
... Is it desirable to do so
or should the user have more fine-grained control? ("xargs -0" comes to mind when thinking of a null-termination input switch.)
For the purposes of check-attr and check-ignore, a single "-z" governing both is sufficient. I think you already got that from my 4-patch series, but the core reason for that is :
- when "-z" is used, the user knows the input paths may need protection against LF.
- our output contains these same paths.
- which means our output cannot be expressed unambiguously using LF as record separator.
For the purpose of check-mailmap, I actually do not see much point in supporting "-z" format. We do not even handle names or addresses with LF in it. The mailmap format would not let you express such records in the first place, no?
Re: [PATCH v2 1/4] builtin: add git-check-mailmap command
Quoted 9 lines · Junio C Hamano
Quoted 3 lines · Eric Sunshine
... Is it desirable to do so
or should the user have more fine-grained control? ("xargs -0" comes to mind when thinking of a null-termination input switch.)For the purposes of check-attr and check-ignore, a single "-z" governing both is sufficient. I think you already got that from my 4-patch series, but the core reason for that is :
I'm reading it right now.
Quoted 5 lines
- when "-z" is used, the user knows the input paths may need protection against LF.
- our output contains these same paths.
Quoted 7 lines
- which means our output cannot be expressed unambiguously using LF as record separator.
For the purpose of check-mailmap, I actually do not see much point in supporting "-z" format. We do not even handle names or addresses with LF in it. The mailmap format would not let you express such records in the first place, no?
You're right. I had this exact argument in mind for why null-termination was not needed on the input side of check-mailmap, but for some reason I had a blind spot concerning the output side. I'll drop this option in the next re-roll.
PATCH v2 2/4 t4203: test check-mailmap command invocation
In reply to Eric SunshineTest the command-line interface of check-mailmap. (Actual .mailmap functionality is already covered by existing tests.)
--- t/t4203-mailmap.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
t/t4203-mailmap.sh +50 -0
@@ -13,6 +13,11 @@ fuzz_blame () { } test_expect_success setup ' + cat >contacts <<-\EOF && + A U Thor <[email protected]> + nick1 <[email protected]> + EOF + echo one >one && git add one && test_tick &&
@@ -23,6 +28,51 @@ test_expect_success setup ' git commit --author "nick1 <[email protected]>" -m second ' +test_expect_success 'check-mailmap no arguments' ' + test_must_fail git check-mailmap +' + +test_expect_success 'check-mailmap arguments' ' + cat >expect <<-\EOF && + A U Thor <[email protected]> + nick1 <[email protected]> + EOF + git check-mailmap \ + "A U Thor <[email protected]>" \ + "nick1 <[email protected]>" >actual && + test_cmp expect actual +' + +test_expect_success 'check-mailmap --stdin' ' + cat >expect <<-\EOF && + A U Thor <[email protected]> + nick1 <[email protected]> + EOF + git check-mailmap --stdin <contacts >actual && + test_cmp expect actual +' + +test_expect_success 'check-mailmap --stdin arguments' ' + cat >expect <<-\EOF && + Internal Guy <[email protected]> + EOF + cat <contacts >>expect && + git check-mailmap --stdin "Internal Guy <[email protected]>" \ + <contacts >actual && + test_cmp expect actual +' + +test_expect_success 'check-mailmap -z' ' + printf "A U Thor <[email protected]>\0" >expect && + printf "nick1 <[email protected]>\0" >>expect && + git check-mailmap -z --stdin <contacts >actual && + test_cmp expect actual +' + +test_expect_success 'check-mailmap bogus contact' ' + test_must_fail git check-mailmap bogus +' + cat >expect <<\EOF A U Thor (1): initial
Signature · 1 line
1.8.3.2
PATCH v2 3/4 t4203: test mailmap functionality directly rather than indirectly
In reply to Eric SunshineWith the introduction of check-mailmap, it is now possible to check .mailmap functionality directly rather than indirectly as a side-effect of other commands (such as git-shortlog), therefore, do so.
--- t/t4203-mailmap.sh | 133 ++++++++++++++++++----------------------------------- 1 file changed, 45 insertions(+), 88 deletions(-)
t/t4203-mailmap.sh +45 -88
@@ -74,128 +74,96 @@ test_expect_success 'check-mailmap bogus contact' ' ' cat >expect <<\EOF -A U Thor (1): - initial - -nick1 (1): - second - +A U Thor <[email protected]> +nick1 <[email protected]> EOF test_expect_success 'No mailmap' ' - git shortlog HEAD >actual && + git check-mailmap --stdin <contacts >actual && test_cmp expect actual ' cat >expect <<\EOF -Repo Guy (1): - initial - -nick1 (1): - second - +Repo Guy <[email protected]> +nick1 <[email protected]> EOF test_expect_success 'default .mailmap' ' echo "Repo Guy <[email protected]>" > .mailmap && - git shortlog HEAD >actual && + git check-mailmap --stdin <contacts >actual && test_cmp expect actual ' # Using a mailmap file in a subdirectory of the repo here, but # could just as well have been a file outside of the repository cat >expect <<\EOF -Internal Guy (1): - second - -Repo Guy (1): - initial - +Repo Guy <[email protected]> +Internal Guy <[email protected]> EOF test_expect_success 'mailmap.file set' ' mkdir -p internal_mailmap && echo "Internal Guy <[email protected]>" > internal_mailmap/.mailmap && git config mailmap.file internal_mailmap/.mailmap && - git shortlog HEAD >actual && + git check-mailmap --stdin <contacts >actual && test_cmp expect actual ' cat >expect <<\EOF -External Guy (1): - initial - -Internal Guy (1): - second - +External Guy <[email protected]> +Internal Guy <[email protected]> EOF test_expect_success 'mailmap.file override' ' echo "External Guy <[email protected]>" >> internal_mailmap/.mailmap && git config mailmap.file internal_mailmap/.mailmap && - git shortlog HEAD >actual && + git check-mailmap --stdin <contacts >actual && test_cmp expect actual ' cat >expect <<\EOF -Repo Guy (1): - initial - -nick1 (1): - second - +Repo Guy <[email protected]> +nick1 <[email protected]> EOF test_expect_success 'mailmap.file non-existent' ' rm internal_mailmap/.mailmap && rmdir internal_mailmap && - git shortlog HEAD >actual && + git check-mailmap --stdin <contacts >actual && test_cmp expect actual ' cat >expect <<\EOF -Internal Guy (1): - second - -Repo Guy (1): - initial - +Repo Guy <[email protected]> +Internal Guy <[email protected]> EOF test_expect_success 'name entry after email entry' ' mkdir -p internal_mailmap && echo "<[email protected]> <[email protected]>" >internal_mailmap/.mailmap && echo "Internal Guy <[email protected]>" >>internal_mailmap/.mailmap && - git shortlog HEAD >actual && + git check-mailmap --stdin <contacts >actual && test_cmp expect actual ' cat >expect <<\EOF -Internal Guy (1): - second - -Repo Guy (1): - initial - +Repo Guy <[email protected]> +Internal Guy <[email protected]> EOF test_expect_success 'name entry after email entry, case-insensitive' ' mkdir -p internal_mailmap && echo "<[email protected]> <[email protected]>" >internal_mailmap/.mailmap && echo "Internal Guy <[email protected]>" >>internal_mailmap/.mailmap && - git shortlog HEAD >actual && + git check-mailmap --stdin <contacts >actual && test_cmp expect actual ' cat >expect <<\EOF -A U Thor (1): - initial - -nick1 (1): - second - +A U Thor <[email protected]> +nick1 <[email protected]> EOF test_expect_success 'No mailmap files, but configured' ' rm -f .mailmap internal_mailmap/.mailmap && - git shortlog HEAD >actual && + git check-mailmap --stdin <contacts >actual && test_cmp expect actual '
@@ -217,54 +185,43 @@ test_expect_success 'setup mailmap blob tests' ' test_expect_success 'mailmap.blob set' ' cat >expect <<-\EOF && - Blob Guy (1): - second - - Repo Guy (1): - initial - + Repo Guy <[email protected]> + Blob Guy <[email protected]> EOF - git -c mailmap.blob=map:just-bugs shortlog HEAD >actual && + git -c mailmap.blob=map:just-bugs check-mailmap --stdin \ + <contacts >actual && test_cmp expect actual ' test_expect_success 'mailmap.blob overrides .mailmap' ' cat >expect <<-\EOF && - Blob Guy (2): - initial - second - + Blob Guy <[email protected]> + Blob Guy <[email protected]> EOF - git -c mailmap.blob=map:both shortlog HEAD >actual && + git -c mailmap.blob=map:both check-mailmap --stdin \ + <contacts >actual && test_cmp expect actual ' test_expect_success 'mailmap.file overrides mailmap.blob' ' cat >expect <<-\EOF && - Blob Guy (1): - second - - Internal Guy (1): - initial - + Internal Guy <[email protected]> + Blob Guy <[email protected]> EOF git \ -c mailmap.blob=map:both \ -c mailmap.file=internal.map \ - shortlog HEAD >actual && + check-mailmap --stdin <contacts >actual && test_cmp expect actual ' test_expect_success 'mailmap.blob can be missing' ' cat >expect <<-\EOF && - Repo Guy (1): - initial - - nick1 (1): - second - + Repo Guy <[email protected]> + nick1 <[email protected]> EOF - git -c mailmap.blob=map:nonexistent shortlog HEAD >actual && + git -c mailmap.blob=map:nonexistent check-mailmap --stdin \ + <contacts >actual && test_cmp expect actual '
@@ -273,12 +230,12 @@ test_expect_success 'mailmap.blob defaults to off in non-bare repo' ' ( cd non-bare && test_commit one .mailmap "Fake Name <[email protected]>" && - echo " 1 Fake Name" >expect && - git shortlog -ns HEAD >actual && + echo "Fake Name <[email protected]>" >expect && + git check-mailmap "A U Thor <[email protected]>" >actual && test_cmp expect actual && rm .mailmap && - echo " 1 A U Thor" >expect && - git shortlog -ns HEAD >actual && + echo "A U Thor <[email protected]>" >expect && + git check-mailmap "A U Thor <[email protected]>" >actual && test_cmp expect actual ) '
@@ -287,8 +244,8 @@ test_expect_success 'mailmap.blob defaults to HEAD:.mailmap in bare repo' ' git clone --bare non-bare bare && ( cd bare && - echo " 1 Fake Name" >expect && - git shortlog -ns HEAD >actual && + echo "Fake Name <[email protected]>" >expect && + git check-mailmap "A U Thor <[email protected]>" >actual && test_cmp expect actual ) '
Signature · 1 line
1.8.3.2
Re: [PATCH v2 3/4] t4203: test mailmap functionality directly rather than indirectly
Quoted 3 lines · Eric Sunshine
With the introduction of check-mailmap, it is now possible to check .mailmap functionality directly rather than indirectly as a side-effect of other commands (such as git-shortlog), therefore, do so.
Does this patch mean that we will now ignore future breakages in shortlog and blame if their mailmap integration becomes buggy?
I am not convinced it is a good idea if that is what is going on.
Quoted 261 lines
Signed-off-by Eric Sunshine <[email protected]>--- t/t4203-mailmap.sh | 133 ++++++++++++++++++----------------------------------- 1 file changed, 45 insertions(+), 88 deletions(-)t/t4203-mailmap.sh +45
-88@@ -74,128 +74,96 @@ test_expect_success 'check-mailmap bogus contact' ' ' cat >expect <<\EOF -A U Thor (1): - initial - -nick1 (1): - second - +A U Thor <[email protected]> +nick1 <[email protected]> EOF test_expect_success 'No mailmap' ' - git shortlog HEAD >actual && + git check-mailmap --stdin <contacts >actual && test_cmp expect actual ' cat >expect <<\EOF -Repo Guy (1): - initial - -nick1 (1): - second - +Repo Guy <[email protected]> +nick1 <[email protected]> EOF test_expect_success 'default .mailmap' ' echo "Repo Guy <[email protected]>" > .mailmap && - git shortlog HEAD >actual && + git check-mailmap --stdin <contacts >actual && test_cmp expect actual ' # Using a mailmap file in a subdirectory of the repo here, but # could just as well have been a file outside of the repository cat >expect <<\EOF -Internal Guy (1): - second - -Repo Guy (1): - initial - +Repo Guy <[email protected]> +Internal Guy <[email protected]> EOF test_expect_success 'mailmap.file set' ' mkdir -p internal_mailmap && echo "Internal Guy <[email protected]>" > internal_mailmap/.mailmap && git config mailmap.file internal_mailmap/.mailmap && - git shortlog HEAD >actual && + git check-mailmap --stdin <contacts >actual && test_cmp expect actual ' cat >expect <<\EOF -External Guy (1): - initial - -Internal Guy (1): - second - +External Guy <[email protected]> +Internal Guy <[email protected]> EOF test_expect_success 'mailmap.file override' ' echo "External Guy <[email protected]>" >> internal_mailmap/.mailmap && git config mailmap.file internal_mailmap/.mailmap && - git shortlog HEAD >actual && + git check-mailmap --stdin <contacts >actual && test_cmp expect actual ' cat >expect <<\EOF -Repo Guy (1): - initial - -nick1 (1): - second - +Repo Guy <[email protected]> +nick1 <[email protected]> EOF test_expect_success 'mailmap.file non-existent' ' rm internal_mailmap/.mailmap && rmdir internal_mailmap && - git shortlog HEAD >actual && + git check-mailmap --stdin <contacts >actual && test_cmp expect actual ' cat >expect <<\EOF -Internal Guy (1): - second - -Repo Guy (1): - initial - +Repo Guy <[email protected]> +Internal Guy <[email protected]> EOF test_expect_success 'name entry after email entry' ' mkdir -p internal_mailmap && echo "<[email protected]> <[email protected]>" >internal_mailmap/.mailmap && echo "Internal Guy <[email protected]>" >>internal_mailmap/.mailmap && - git shortlog HEAD >actual && + git check-mailmap --stdin <contacts >actual && test_cmp expect actual ' cat >expect <<\EOF -Internal Guy (1): - second - -Repo Guy (1): - initial - +Repo Guy <[email protected]> +Internal Guy <[email protected]> EOF test_expect_success 'name entry after email entry, case-insensitive' ' mkdir -p internal_mailmap && echo "<[email protected]> <[email protected]>" >internal_mailmap/.mailmap && echo "Internal Guy <[email protected]>" >>internal_mailmap/.mailmap && - git shortlog HEAD >actual && + git check-mailmap --stdin <contacts >actual && test_cmp expect actual ' cat >expect <<\EOF -A U Thor (1): - initial - -nick1 (1): - second - +A U Thor <[email protected]> +nick1 <[email protected]> EOF test_expect_success 'No mailmap files, but configured' ' rm -f .mailmap internal_mailmap/.mailmap && - git shortlog HEAD >actual && + git check-mailmap --stdin <contacts >actual && test_cmp expect actual '@@ -217,54 +185,43 @@ test_expect_success 'setup mailmap blob tests' ' test_expect_success 'mailmap.blob set' ' cat >expect <<-\EOF && - Blob Guy (1): - second - - Repo Guy (1): - initial - + Repo Guy <[email protected]> + Blob Guy <[email protected]> EOF - git -c mailmap.blob=map:just-bugs shortlog HEAD >actual && + git -c mailmap.blob=map:just-bugs check-mailmap --stdin \ + <contacts >actual && test_cmp expect actual ' test_expect_success 'mailmap.blob overrides .mailmap' ' cat >expect <<-\EOF && - Blob Guy (2): - initial - second - + Blob Guy <[email protected]> + Blob Guy <[email protected]> EOF - git -c mailmap.blob=map:both shortlog HEAD >actual && + git -c mailmap.blob=map:both check-mailmap --stdin \ + <contacts >actual && test_cmp expect actual ' test_expect_success 'mailmap.file overrides mailmap.blob' ' cat >expect <<-\EOF && - Blob Guy (1): - second - - Internal Guy (1): - initial - + Internal Guy <[email protected]> + Blob Guy <[email protected]> EOF git \ -c mailmap.blob=map:both \ -c mailmap.file=internal.map \ - shortlog HEAD >actual && + check-mailmap --stdin <contacts >actual && test_cmp expect actual ' test_expect_success 'mailmap.blob can be missing' ' cat >expect <<-\EOF && - Repo Guy (1): - initial - - nick1 (1): - second - + Repo Guy <[email protected]> + nick1 <[email protected]> EOF - git -c mailmap.blob=map:nonexistent shortlog HEAD >actual && + git -c mailmap.blob=map:nonexistent check-mailmap --stdin \ + <contacts >actual && test_cmp expect actual '@@ -273,12 +230,12 @@ test_expect_success 'mailmap.blob defaults to off in non-bare repo' ' ( cd non-bare && test_commit one .mailmap "Fake Name <[email protected]>" && - echo " 1 Fake Name" >expect && - git shortlog -ns HEAD >actual && + echo "Fake Name <[email protected]>" >expect && + git check-mailmap "A U Thor <[email protected]>" >actual && test_cmp expect actual && rm .mailmap && - echo " 1 A U Thor" >expect && - git shortlog -ns HEAD >actual && + echo "A U Thor <[email protected]>" >expect && + git check-mailmap "A U Thor <[email protected]>" >actual && test_cmp expect actual ) '@@ -287,8 +244,8 @@ test_expect_success 'mailmap.blob defaults to HEAD:.mailmap in bare repo' ' git clone --bare non-bare bare && ( cd bare && - echo " 1 Fake Name" >expect && - git shortlog -ns HEAD >actual && + echo "Fake Name <[email protected]>" >expect && + git check-mailmap "A U Thor <[email protected]>" >actual && test_cmp expect actual ) '
Re: [PATCH v2 3/4] t4203: test mailmap functionality directly rather than indirectly
Quoted 10 lines · Junio C Hamano
Quoted 3 lines · Eric Sunshine
With the introduction of check-mailmap, it is now possible to check .mailmap functionality directly rather than indirectly as a side-effect of other commands (such as git-shortlog), therefore, do so.
Does this patch mean that we will now ignore future breakages in shortlog and blame if their mailmap integration becomes buggy?
I am not convinced it is a good idea if that is what is going on.
I meant to mention in the cover letter that this patch was open for debate, however, it does not eliminate all testing of these other commands.
The tests in which git-check-mailmap is substituted for git-shortlog all worked against a simplistic two-commit repository. Those tests were checking the low-level mailmap functionality under various conditions and configurations; they were not especially checking any particular behavior of git-shortlog.
There still remain a final eight tests which cover git-shortlog, git-log, and git-blame. These tests do check mailmap-related behavior of those commands, and they do so using a more involved seven-commit repository with "complex" mappings, so we have not necessarily lost any checks of mailmap integration for those commands.
Would this patch become more palatable if I stated the above in the commit message?
-- ES
Re: [PATCH v2 3/4] t4203: test mailmap functionality directly rather than indirectly
Quoted 22 lines · Eric Sunshine
Quoted 10 lines · Junio C Hamano
Quoted 3 lines · Eric Sunshine
With the introduction of check-mailmap, it is now possible to check .mailmap functionality directly rather than indirectly as a side-effect of other commands (such as git-shortlog), therefore, do so.
Does this patch mean that we will now ignore future breakages in shortlog and blame if their mailmap integration becomes buggy?
I am not convinced it is a good idea if that is what is going on.
I meant to mention in the cover letter that this patch was open for debate, however, it does not eliminate all testing of these other commands.
The tests in which git-check-mailmap is substituted for git-shortlog all worked against a simplistic two-commit repository. Those tests were checking the low-level mailmap functionality under various conditions and configurations; they were not especially checking any particular behavior of git-shortlog.
Quoted 8 lines
There still remain a final eight tests which cover git-shortlog, git-log, and git-blame. These tests do check mailmap-related behavior of those commands, and they do so using a more involved seven-commit repository with "complex" mappings, so we have not necessarily lost any checks of mailmap integration for those commands.
Would this patch become more palatable if I stated the above in the commit message?
My current thinking is "no" --- the patch has as a justification "Now we can test these aspects of .mailmap handling directly with a low-level tool instead of using the tool most people will use, so do so", which sounds an awful lot like "Reduce test coverage of commonly used tools, because we can".
But I imagine the actual motivation was something other than "because we can". For example, maybe the idea is that after this patch, it should be easier to make cosmetic improvements to the shortlog, log, and blame output and only have to change those final 8 tests that are adequately covering the output? If you have such plans and this patch makes them easier, it could sound like a good patch as a stepping stone toward that.
Thanks and hope that helps,
Jonathan
Re: [PATCH v2 3/4] t4203: test mailmap functionality directly rather than indirectly
Quoted 5 lines · Jonathan Nieder
My current thinking is "no" --- the patch has as a justification "Now we can test these aspects of .mailmap handling directly with a low-level tool instead of using the tool most people will use, so do so", which sounds an awful lot like "Reduce test coverage of commonly used tools, because we can".
Yes, that was exactly my reaction that prompted my response.
Re: [PATCH v2 3/4] t4203: test mailmap functionality directly rather than indirectly
Quoted 9 lines · Junio C Hamano
Quoted 5 lines · Jonathan Nieder
My current thinking is "no" --- the patch has as a justification "Now we can test these aspects of .mailmap handling directly with a low-level tool instead of using the tool most people will use, so do so", which sounds an awful lot like "Reduce test coverage of commonly used tools, because we can".
Yes, that was exactly my reaction that prompted my response.
Does any of my follow-up commentary result in a different reaction? If not, I'll drop patches 3 &4 in the re-roll.
Re: [PATCH v2 3/4] t4203: test mailmap functionality directly rather than indirectly
Quoted 9 lines · Eric Sunshine
Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Jonathan Nieder
My current thinking is "no" --- the patch has as a justification "Now we can test these aspects of .mailmap handling directly with a low-level tool instead of using the tool most people will use, so do so", which sounds an awful lot like "Reduce test coverage of commonly used tools, because we can".
Quoted 4 lines
Quoted 1 line
Yes, that was exactly my reaction that prompted my response.
Does any of my follow-up commentary result in a different reaction?
Not really. While I _do_ think direct testing has merits, I think that should be done by adding direct tests, not by removing the tests that are meant to protect higher level _users_ of the underlying mechanism from breakages. After all, their breakages may not come from new breakages of the lower level mechanism (i.e. the mailmap.c code) but the way these higher level code makes calls into the mechanism, and direct test of the lower level mechanism will not protect them from the latter kind of breakages.
Re: [PATCH v2 3/4] t4203: test mailmap functionality directly rather than indirectly
In reply to Jonathan NiederQuoted 32 lines · Jonathan Nieder
Quoted 22 lines · Eric Sunshine
Quoted 10 lines · Junio C Hamano
Quoted 3 lines · Eric Sunshine
With the introduction of check-mailmap, it is now possible to check .mailmap functionality directly rather than indirectly as a side-effect of other commands (such as git-shortlog), therefore, do so.
Does this patch mean that we will now ignore future breakages in shortlog and blame if their mailmap integration becomes buggy?
I am not convinced it is a good idea if that is what is going on.
I meant to mention in the cover letter that this patch was open for debate, however, it does not eliminate all testing of these other commands.
The tests in which git-check-mailmap is substituted for git-shortlog all worked against a simplistic two-commit repository. Those tests were checking the low-level mailmap functionality under various conditions and configurations; they were not especially checking any particular behavior of git-shortlog.
Quoted 8 lines
There still remain a final eight tests which cover git-shortlog, git-log, and git-blame. These tests do check mailmap-related behavior of those commands, and they do so using a more involved seven-commit repository with "complex" mappings, so we have not necessarily lost any checks of mailmap integration for those commands.
Would this patch become more palatable if I stated the above in the commit message?
Quoted 8 lines
My current thinking is "no" --- the patch has as a justification "Now we can test these aspects of .mailmap handling directly with a low-level tool instead of using the tool most people will use, so do so", which sounds an awful lot like "Reduce test coverage of commonly used tools, because we can".
But I imagine the actual motivation was something other than "because we can".
The motivation is as stated in the subject: Direct rather than indirect testing of mailmap functionality. The tests in question are properly crafted to check only low-level mailmap (not git-shortlog) functionality under various conditions and configurations, yet the mental load on the reader is high because he has to keep in mind the authors and commits in the repository underlying git-shortlog's output. When testing via git-check-mailmap, mental load is low: there is a direct correlation between the "Name <email@address>" which goes in and that which comes out. What is being tested is the same, but it's easier to reason about and understand the the tests when done directly.
When converting the tests, I also discovered an additional, perhaps more important motivation. Most of the tests check only that name remapping functions correctly, however, a couple also attempt to check address remapping ([email protected] => [email protected]). Even though the tests succeed, they don't actually prove that address remapping was correct (or occurred at all) since git-shortlog does not display the email address. git-check-mailmap always displays the email address, thus the check actually tests the intended email address remapping.
Quoted 6 lines
For example, maybe the idea is that after this patch, it should be easier to make cosmetic improvements to the shortlog, log, and blame output and only have to change those final 8 tests that are adequately covering the output? If you have such plans and this patch makes them easier, it could sound like a good patch as a stepping stone toward that.
PATCH v2 4/4 t4203: consolidate test-repository setup
In reply to Eric SunshineThe simple two-commit test-repository created by 'setup' is no longer needed by any of the tests retrofitted to use check-mailmap. Subsequent, more complex tests of git-shortlog, git-log, and git-blame functionality expand the repository by adding five commits. Consolidate the creation of this seven-commit repository into a single setup function.
--- t/t4203-mailmap.sh | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-)
t/t4203-mailmap.sh +27 -26
@@ -22,10 +22,36 @@ test_expect_success setup ' git add one && test_tick && git commit -m initial && + echo two >>one && git add one && test_tick && - git commit --author "nick1 <[email protected]>" -m second + git commit --author "nick1 <[email protected]>" -m second && + + echo three >>one && + git add one && + test_tick && + git commit --author "nick2 <[email protected]>" -m third && + + echo four >>one && + git add one && + test_tick && + git commit --author "nick2 <[email protected]>" -m fourth && + + echo five >>one && + git add one && + test_tick && + git commit --author "santa <[email protected]>" -m fifth && + + echo six >>one && + git add one && + test_tick && + git commit --author "claus <[email protected]>" -m sixth && + + echo seven >>one && + git add one && + test_tick && + git commit --author "CTO <[email protected]>" -m seventh ' test_expect_success 'check-mailmap no arguments' '
@@ -276,31 +302,6 @@ Some Dude <[email protected]> (1): EOF test_expect_success 'Shortlog output (complex mapping)' ' - echo three >>one && - git add one && - test_tick && - git commit --author "nick2 <[email protected]>" -m third && - - echo four >>one && - git add one && - test_tick && - git commit --author "nick2 <[email protected]>" -m fourth && - - echo five >>one && - git add one && - test_tick && - git commit --author "santa <[email protected]>" -m fifth && - - echo six >>one && - git add one && - test_tick && - git commit --author "claus <[email protected]>" -m sixth && - - echo seven >>one && - git add one && - test_tick && - git commit --author "CTO <[email protected]>" -m seventh && - mkdir -p internal_mailmap && echo "Committed <[email protected]>" > internal_mailmap/.mailmap && echo "<[email protected]> <[email protected]>" >> internal_mailmap/.mailmap &&
Signature · 1 line
1.8.3.2