From 42957af0273a338de232a6a0071a3ddcf92f9fee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:17:45 +0100 Subject: [PATCH 01/22] mailmap doc: create a new "gitmailmap(5)" man page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Create a gitmailmap(5) page similar to how .gitmodules and .gitignore have their own pages at gitmodules(5) and gitignore(5). Now instead of "check-mailmap", "blame" and "shortlog" documentation including the description of the format we link to one canonical place. This makes things easier for readers, since in our manpage or web-based[1] output it's not clear that the "MAPPING AUTHORS" sections aren't subtly different, as opposed to just included. 1. https://git-scm.com/docs/git-check-mailmap Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- Documentation/Makefile | 1 + Documentation/git-blame.txt | 2 +- Documentation/git-check-mailmap.txt | 2 +- Documentation/git-shortlog.txt | 6 +--- Documentation/{mailmap.txt => gitmailmap.txt} | 33 +++++++++++++++++++ command-list.txt | 1 + 6 files changed, 38 insertions(+), 7 deletions(-) rename Documentation/{mailmap.txt => gitmailmap.txt} (88%) diff --git a/Documentation/Makefile b/Documentation/Makefile index b980407059..81d1bf7a04 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -21,6 +21,7 @@ MAN1_TXT += gitweb.txt MAN5_TXT += gitattributes.txt MAN5_TXT += githooks.txt MAN5_TXT += gitignore.txt +MAN5_TXT += gitmailmap.txt MAN5_TXT += gitmodules.txt MAN5_TXT += gitrepository-layout.txt MAN5_TXT += gitweb.conf.txt diff --git a/Documentation/git-blame.txt b/Documentation/git-blame.txt index 34b496d485..3bf5d5d8b4 100644 --- a/Documentation/git-blame.txt +++ b/Documentation/git-blame.txt @@ -226,7 +226,7 @@ commit commentary), a blame viewer will not care. MAPPING AUTHORS --------------- -include::mailmap.txt[] +See linkgit:gitmailmap[5]. SEE ALSO diff --git a/Documentation/git-check-mailmap.txt b/Documentation/git-check-mailmap.txt index aa2055dbeb..45a5cfafd8 100644 --- a/Documentation/git-check-mailmap.txt +++ b/Documentation/git-check-mailmap.txt @@ -39,7 +39,7 @@ printed; otherwise only ``$$$$'' is printed. MAPPING AUTHORS --------------- -include::mailmap.txt[] +See linkgit:gitmailmap[5]. GIT diff --git a/Documentation/git-shortlog.txt b/Documentation/git-shortlog.txt index fd93cd41e9..c16cc3b608 100644 --- a/Documentation/git-shortlog.txt +++ b/Documentation/git-shortlog.txt @@ -111,11 +111,7 @@ include::rev-list-options.txt[] MAPPING AUTHORS --------------- -The `.mailmap` feature is used to coalesce together commits by the same -person in the shortlog, where their name and/or email address was -spelled differently. - -include::mailmap.txt[] +See linkgit:gitmailmap[5]. GIT --- diff --git a/Documentation/mailmap.txt b/Documentation/gitmailmap.txt similarity index 88% rename from Documentation/mailmap.txt rename to Documentation/gitmailmap.txt index 4a8c276529..8b07f9c5d7 100644 --- a/Documentation/mailmap.txt +++ b/Documentation/gitmailmap.txt @@ -1,9 +1,28 @@ +gitmailmap(5) +============= + +NAME +---- +gitmailmap - Map author/committer names and/or E-Mail addresses + +SYNOPSIS +-------- +$GIT_WORK_DIR/.mailmap + + +DESCRIPTION +----------- + If the file `.mailmap` exists at the toplevel of the repository, or at the location pointed to by the mailmap.file or mailmap.blob configuration options, it is used to map author and committer names and email addresses to canonical real names and email addresses. + +SYNTAX +------ + In the simple form, each line in the file consists of the canonical real name of an author, whitespace, and an email address used in the commit (enclosed by '<' and '>') to map to the name. For example: @@ -27,6 +46,10 @@ commit matching the specified commit email address, and: which allows mailmap to replace both the name and the email of a commit matching both the specified commit name and email address. + +EXAMPLES +-------- + Example 1: Your history contains commits by two authors, Jane and Joe, whose names appear in the repository under several forms: @@ -73,3 +96,13 @@ Santa Claus Use hash '#' for comments that are either on their own line, or after the email address. + + +SEE ALSO +-------- +linkgit:git-check-mailmap[1] + + +GIT +--- +Part of the linkgit:git[1] suite diff --git a/command-list.txt b/command-list.txt index 9379b02e5e..a289f09ed6 100644 --- a/command-list.txt +++ b/command-list.txt @@ -204,6 +204,7 @@ gitfaq guide gitglossary guide githooks guide gitignore guide +gitmailmap guide gitmodules guide gitnamespaces guide gitremote-helpers guide From 4f2ee994f32fd29a049a6c39282156cfaa99e248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:17:46 +0100 Subject: [PATCH 02/22] mailmap doc: quote config variables `like.this` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Quote the mailmap.file and mailmap.blob configuration variables as `mailmap.file` and `mailmap.blob`, and link to git-config(1). This is in line with the preferred way of doing this in the rest of our documentation. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- Documentation/gitmailmap.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/gitmailmap.txt b/Documentation/gitmailmap.txt index 8b07f9c5d7..e75eadde63 100644 --- a/Documentation/gitmailmap.txt +++ b/Documentation/gitmailmap.txt @@ -14,8 +14,8 @@ DESCRIPTION ----------- If the file `.mailmap` exists at the toplevel of the repository, or at -the location pointed to by the mailmap.file or mailmap.blob -configuration options, it +the location pointed to by the `mailmap.file` or `mailmap.blob` +configuration options (see linkgit:git-config[1]), it is used to map author and committer names and email addresses to canonical real names and email addresses. From 6646cca8927c1c88a13e07bc14144cf5c12610f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:17:47 +0100 Subject: [PATCH 03/22] check-mailmap doc: note config options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a passing mention of the mailmap.file and mailmap.blob configuration options. Before this addition a reader of the "check-mailmap" manpage would have no idea that a custom map could be specified, unless they'd happen to e.g. come across it in the "config" manpage first. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- Documentation/git-check-mailmap.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/git-check-mailmap.txt b/Documentation/git-check-mailmap.txt index 45a5cfafd8..02f4418323 100644 --- a/Documentation/git-check-mailmap.txt +++ b/Documentation/git-check-mailmap.txt @@ -36,6 +36,13 @@ name is provided or known to the 'mailmap', ``Name $$$$'' is printed; otherwise only ``$$$$'' is printed. +CONFIGURATION +------------- + +See `mailmap.file` and `mailmap.blob` in linkgit:git-config[1] for how +to specify a custom `.mailmap` target file or object. + + MAPPING AUTHORS --------------- From fcafb753829b5d2c73fe67becc073227feb4d7a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:17:48 +0100 Subject: [PATCH 04/22] mailmap doc: start by mentioning the comment syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mentioning the comment syntax and blank line support first is in line with how "git help config" describes its format. See b8936cf060 (config.txt grammar, typo, and asciidoc fixes, 2006-06-08) for the paragraph I'm copying & amending from its documentation. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- Documentation/gitmailmap.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Documentation/gitmailmap.txt b/Documentation/gitmailmap.txt index e75eadde63..4e4677018b 100644 --- a/Documentation/gitmailmap.txt +++ b/Documentation/gitmailmap.txt @@ -23,6 +23,9 @@ canonical real names and email addresses. SYNTAX ------ +The '#' character begins a comment to the end of line, blank lines +are ignored. + In the simple form, each line in the file consists of the canonical real name of an author, whitespace, and an email address used in the commit (enclosed by '<' and '>') to map to the name. For example: @@ -94,8 +97,6 @@ Other Author Santa Claus ------------ -Use hash '#' for comments that are either on their own line, or after -the email address. SEE ALSO From 9aaeac9cf7b21ff820d724d6961495e60546b8c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:17:49 +0100 Subject: [PATCH 05/22] mailmap tests: use our preferred whitespace syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change these tests to use the preferred whitespace around ">", "<<-EOF" etc. This is an initial step in larger and more meaningful refactoring of the file, which makes a subsequent commit easier to read. I'm not changing the whitespace of "echo > file" patterns to "echo >file" because all of those will be changed to here-docs in a subsequent commit. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t4203-mailmap.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index 586c3a86b1..034a78aba1 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -13,7 +13,7 @@ fuzz_blame () { } test_expect_success setup ' - cat >contacts <<- EOF && + cat >contacts <<-EOF && $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> nick1 EOF @@ -33,7 +33,7 @@ test_expect_success 'check-mailmap no arguments' ' ' test_expect_success 'check-mailmap arguments' ' - cat >expect <<- EOF && + cat >expect <<-EOF && $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> nick1 EOF @@ -44,7 +44,7 @@ test_expect_success 'check-mailmap arguments' ' ' test_expect_success 'check-mailmap --stdin' ' - cat >expect <<- EOF && + cat >expect <<-EOF && $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> nick1 EOF @@ -195,10 +195,10 @@ test_expect_success 'No mailmap files, but configured' ' test_expect_success 'setup mailmap blob tests' ' git checkout -b map && test_when_finished "git checkout master" && - cat >just-bugs <<- EOF && + cat >just-bugs <<-\EOF && Blob Guy EOF - cat >both <<- EOF && + cat >both <<-EOF && Blob Guy <$GIT_AUTHOR_EMAIL> Blob Guy EOF @@ -471,7 +471,7 @@ test_expect_success 'Log output with log.mailmap' ' ' test_expect_success 'log.mailmap=false disables mailmap' ' - cat >expect <<- EOF && + cat >expect <<-EOF && Author: CTO Author: claus Author: santa @@ -480,12 +480,12 @@ test_expect_success 'log.mailmap=false disables mailmap' ' Author: nick1 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> EOF - git -c log.mailmap=False log | grep Author > actual && + git -c log.mailmap=False log | grep Author >actual && test_cmp expect actual ' test_expect_success '--no-use-mailmap disables mailmap' ' - cat >expect <<- EOF && + cat >expect <<-EOF && Author: CTO Author: claus Author: santa From e9931ace4f69998b7dfaa52701d4e16e7dd50160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:17:50 +0100 Subject: [PATCH 06/22] mailmap tests: modernize syntax & test idioms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor the mailmap tests to: * Setup "actual" test files in the body of "test_expect_success" * Don't have X of "test_expect_success X Y" be an unquoted string. * Not to carry over test config between tests, and instead use "test_config". * Replace various "echo" a line-at-a-time patterns with here-docs. * Change a case of "log.mailmap=False" to use the lower-case "false". Both work, but this ends up in git-config's boolean parsing and these atypical values are tested for elsewhere. Let's use the lower-case to not draw the reader's attention to this abnormality. * Remove commentary asserting that things work a given way in favor of simply testing for it, i.e. in the case of a .mailmap file outside of the repository. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t4203-mailmap.sh | 517 ++++++++++++++++++++++++++------------------- 1 file changed, 296 insertions(+), 221 deletions(-) diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index 034a78aba1..61d1b62317 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -12,7 +12,7 @@ fuzz_blame () { " "$@" } -test_expect_success setup ' +test_expect_success 'setup commits and contacts file' ' cat >contacts <<-EOF && $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> nick1 @@ -66,128 +66,164 @@ test_expect_success 'check-mailmap bogus contact' ' test_must_fail git check-mailmap bogus ' -cat >expect << EOF -$GIT_AUTHOR_NAME (1): - initial - -nick1 (1): - second - -EOF - test_expect_success 'No mailmap' ' + cat >expect <<-EOF && + $GIT_AUTHOR_NAME (1): + initial + + nick1 (1): + second + + EOF git shortlog HEAD >actual && test_cmp expect actual ' -cat >expect <<\EOF -Repo Guy (1): - initial +test_expect_success 'setup default .mailmap' ' + cat >default.map <<-EOF + Repo Guy <$GIT_AUTHOR_EMAIL> + EOF +' -nick1 (1): - second +test_expect_success 'test default .mailmap' ' + test_when_finished "rm .mailmap" && + cp default.map .mailmap && -EOF + cat >expect <<-\EOF && + Repo Guy (1): + initial -test_expect_success 'default .mailmap' ' - echo "Repo Guy <$GIT_AUTHOR_EMAIL>" > .mailmap && + nick1 (1): + second + + EOF git shortlog HEAD >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 - -EOF test_expect_success 'mailmap.file set' ' - mkdir -p internal_mailmap && - echo "Internal Guy " > internal_mailmap/.mailmap && - git config mailmap.file internal_mailmap/.mailmap && + test_when_finished "rm .mailmap" && + cp default.map .mailmap && + + test_config mailmap.file internal.map && + cat >internal.map <<-\EOF && + Internal Guy + EOF + + cat >expect <<-\EOF && + Internal Guy (1): + second + + Repo Guy (1): + initial + + EOF git shortlog HEAD >actual && - test_cmp expect actual + test_cmp expect actual && + + # The internal_mailmap/.mailmap file is an a subdirectory, but + # as shown here it can also be outside the repository + test_when_finished "rm -rf sub-repo" && + git clone . sub-repo && + ( + cd sub-repo && + cp ../.mailmap . && + git config mailmap.file ../internal.map && + git shortlog HEAD >actual && + test_cmp ../expect actual + ) ' -cat >expect <<\EOF -External Guy (1): - initial - -Internal Guy (1): - second - -EOF test_expect_success 'mailmap.file override' ' - echo "External Guy <$GIT_AUTHOR_EMAIL>" >> internal_mailmap/.mailmap && - git config mailmap.file internal_mailmap/.mailmap && + test_config mailmap.file internal.map && + cat >internal.map <<-EOF && + Internal Guy + External Guy <$GIT_AUTHOR_EMAIL> + EOF + + cat >expect <<-\EOF && + External Guy (1): + initial + + Internal Guy (1): + second + + EOF git shortlog HEAD >actual && test_cmp expect actual ' -cat >expect <<\EOF -Repo Guy (1): - initial - -nick1 (1): - second - -EOF - test_expect_success 'mailmap.file non-existent' ' - rm internal_mailmap/.mailmap && - rmdir internal_mailmap && + test_when_finished "rm .mailmap" && + cp default.map .mailmap && + + cat >expect <<-\EOF && + Repo Guy (1): + initial + + nick1 (1): + second + + EOF git shortlog HEAD >actual && test_cmp expect actual ' -cat >expect <<\EOF -Internal Guy (1): - second - -Repo Guy (1): - initial - -EOF - test_expect_success 'name entry after email entry' ' - mkdir -p internal_mailmap && - echo " " >internal_mailmap/.mailmap && - echo "Internal Guy " >>internal_mailmap/.mailmap && + test_when_finished "rm .mailmap" && + cp default.map .mailmap && + + test_config mailmap.file internal.map && + cat >internal.map <<-\EOF && + + Internal Guy + EOF + + cat >expect <<-\EOF && + Internal Guy (1): + second + + Repo Guy (1): + initial + + EOF + git shortlog HEAD >actual && test_cmp expect actual ' -cat >expect <<\EOF -Internal Guy (1): - second - -Repo Guy (1): - initial - -EOF - test_expect_success 'name entry after email entry, case-insensitive' ' - mkdir -p internal_mailmap && - echo " " >internal_mailmap/.mailmap && - echo "Internal Guy " >>internal_mailmap/.mailmap && + test_when_finished "rm .mailmap" && + cp default.map .mailmap && + + test_config mailmap.file internal.map && + cat >internal.map <<-\EOF && + + Internal Guy + EOF + + cat >expect <<-\EOF && + Internal Guy (1): + second + + Repo Guy (1): + initial + + EOF + git shortlog HEAD >actual && test_cmp expect actual ' -cat >expect << EOF -$GIT_AUTHOR_NAME (1): - initial - -nick1 (1): - second - -EOF test_expect_success 'No mailmap files, but configured' ' - rm -f .mailmap internal_mailmap/.mailmap && + cat >expect <<-EOF && + $GIT_AUTHOR_NAME (1): + initial + + nick1 (1): + second + + EOF git shortlog HEAD >actual && test_cmp expect actual ' @@ -205,11 +241,16 @@ test_expect_success 'setup mailmap blob tests' ' printf "Tricky Guy <$GIT_AUTHOR_EMAIL>" >no-newline && git add just-bugs both no-newline && git commit -m "my mailmaps" && - echo "Repo Guy <$GIT_AUTHOR_EMAIL>" >.mailmap && - echo "Internal Guy <$GIT_AUTHOR_EMAIL>" >internal.map + + cat >internal.map <<-EOF + Internal Guy <$GIT_AUTHOR_EMAIL> + EOF ' test_expect_success 'mailmap.blob set' ' + test_when_finished "rm .mailmap" && + cp default.map .mailmap && + cat >expect <<-\EOF && Blob Guy (1): second @@ -223,6 +264,9 @@ test_expect_success 'mailmap.blob set' ' ' test_expect_success 'mailmap.blob overrides .mailmap' ' + test_when_finished "rm .mailmap" && + cp default.map .mailmap && + cat >expect <<-\EOF && Blob Guy (2): initial @@ -250,6 +294,9 @@ test_expect_success 'mailmap.file overrides mailmap.blob' ' ' test_expect_success 'mailmap.blob can be missing' ' + test_when_finished "rm .mailmap" && + cp default.map .mailmap && + cat >expect <<-\EOF && Repo Guy (1): initial @@ -267,11 +314,15 @@ test_expect_success 'mailmap.blob defaults to off in non-bare repo' ' ( cd non-bare && test_commit one .mailmap "Fake Name <$GIT_AUTHOR_EMAIL>" && - echo " 1 Fake Name" >expect && + cat >expect <<-\EOF && + 1 Fake Name + EOF git shortlog -ns HEAD >actual && test_cmp expect actual && rm .mailmap && - echo " 1 $GIT_AUTHOR_NAME" >expect && + cat >expect <<-EOF && + 1 $GIT_AUTHOR_NAME + EOF git shortlog -ns HEAD >actual && test_cmp expect actual ) @@ -281,7 +332,9 @@ 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 && + cat >expect <<-\EOF && + 1 Fake Name + EOF git shortlog -ns HEAD >actual && test_cmp expect actual ) @@ -300,50 +353,46 @@ test_expect_success 'mailmap.blob can handle blobs without trailing newline' ' test_cmp expect actual ' -test_expect_success 'cleanup after mailmap.blob tests' ' - rm -f .mailmap -' - test_expect_success 'single-character name' ' - echo " 1 A <$GIT_AUTHOR_EMAIL>" >expect && - echo " 1 nick1 " >>expect && - echo "A <$GIT_AUTHOR_EMAIL>" >.mailmap && test_when_finished "rm .mailmap" && + cat >.mailmap <<-EOF && + A <$GIT_AUTHOR_EMAIL> + EOF + + cat >expect <<-EOF && + 1 A <$GIT_AUTHOR_EMAIL> + 1 nick1 + EOF git shortlog -es HEAD >actual && test_cmp expect actual ' test_expect_success 'preserve canonical email case' ' - echo " 1 $GIT_AUTHOR_NAME " >expect && - echo " 1 nick1 " >>expect && - echo " <$GIT_AUTHOR_EMAIL>" >.mailmap && test_when_finished "rm .mailmap" && + cat >.mailmap <<-EOF && + <$GIT_AUTHOR_EMAIL> + EOF + + cat >expect <<-EOF && + 1 $GIT_AUTHOR_NAME + 1 nick1 + EOF git shortlog -es HEAD >actual && test_cmp expect actual ' -# Extended mailmap configurations should give us the following output for shortlog -cat >expect << EOF -$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> (1): - initial - -CTO (1): - seventh - -Other Author (2): - third - fourth - -Santa Claus (2): - fifth - sixth - -Some Dude (1): - second - -EOF - test_expect_success 'Shortlog output (complex mapping)' ' + test_config mailmap.file complex.map && + cat >complex.map <<-EOF && + Committed <$GIT_COMMITTER_EMAIL> + + Some Dude nick1 + Other Author nick2 + Other Author + Santa Claus + Santa Claus + EOF + echo three >>one && git add one && test_tick && @@ -369,103 +418,119 @@ test_expect_success 'Shortlog output (complex mapping)' ' test_tick && git commit --author "CTO " -m seventh && - mkdir -p internal_mailmap && - echo "Committed <$GIT_COMMITTER_EMAIL>" > internal_mailmap/.mailmap && - echo " " >> internal_mailmap/.mailmap && - echo "Some Dude nick1 " >> internal_mailmap/.mailmap && - echo "Other Author nick2 " >> internal_mailmap/.mailmap && - echo "Other Author " >> internal_mailmap/.mailmap && - echo "Santa Claus " >> internal_mailmap/.mailmap && - echo "Santa Claus " >> internal_mailmap/.mailmap && + cat >expect <<-EOF && + $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> (1): + initial + + CTO (1): + seventh + + Other Author (2): + third + fourth + + Santa Claus (2): + fifth + sixth + + Some Dude (1): + second + + EOF git shortlog -e HEAD >actual && test_cmp expect actual ' -# git log with --pretty format which uses the name and email mailmap placemarkers -cat >expect << EOF -Author CTO maps to CTO -Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> - -Author claus maps to Santa Claus -Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> - -Author santa maps to Santa Claus -Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> - -Author nick2 maps to Other Author -Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> - -Author nick2 maps to Other Author -Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> - -Author nick1 maps to Some Dude -Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> - -Author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> maps to $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> -Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> -EOF - test_expect_success 'Log output (complex mapping)' ' + test_config mailmap.file complex.map && + + cat >expect <<-EOF && + Author CTO maps to CTO + Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> + + Author claus maps to Santa Claus + Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> + + Author santa maps to Santa Claus + Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> + + Author nick2 maps to Other Author + Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> + + Author nick2 maps to Other Author + Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> + + Author nick1 maps to Some Dude + Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> + + Author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> maps to $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> + Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> + EOF + git log --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual && test_cmp expect actual ' -cat >expect << EOF -Author email cto@coompany.xx has local-part cto -Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME - -Author email me@company.xx has local-part me -Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME - -Author email me@company.xx has local-part me -Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME - -Author email nick2@company.xx has local-part nick2 -Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME - -Author email bugs@company.xx has local-part bugs -Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME - -Author email bugs@company.xx has local-part bugs -Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME - -Author email author@example.com has local-part author -Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME -EOF - test_expect_success 'Log output (local-part email address)' ' + cat >expect <<-EOF && + Author email cto@coompany.xx has local-part cto + Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME + + Author email me@company.xx has local-part me + Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME + + Author email me@company.xx has local-part me + Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME + + Author email nick2@company.xx has local-part nick2 + Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME + + Author email bugs@company.xx has local-part bugs + Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME + + Author email bugs@company.xx has local-part bugs + Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME + + Author email author@example.com has local-part author + Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME + EOF + git log --pretty=format:"Author email %ae has local-part %al%nCommitter email %ce has local-part %cl%n" >actual && test_cmp expect actual ' -cat >expect << EOF -Author: CTO -Author: Santa Claus -Author: Santa Claus -Author: Other Author -Author: Other Author -Author: Some Dude -Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> -EOF - test_expect_success 'Log output with --use-mailmap' ' + test_config mailmap.file complex.map && + + cat >expect <<-EOF && + Author: CTO + Author: Santa Claus + Author: Santa Claus + Author: Other Author + Author: Other Author + Author: Some Dude + Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> + EOF + git log --use-mailmap | grep Author >actual && test_cmp expect actual ' -cat >expect << EOF -Author: CTO -Author: Santa Claus -Author: Santa Claus -Author: Other Author -Author: Other Author -Author: Some Dude -Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> -EOF - test_expect_success 'Log output with log.mailmap' ' + test_config mailmap.file complex.map && + + cat >expect <<-EOF && + Author: CTO + Author: Santa Claus + Author: Santa Claus + Author: Other Author + Author: Other Author + Author: Some Dude + Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> + EOF + git -c log.mailmap=True log | grep Author >actual && test_cmp expect actual ' @@ -480,7 +545,7 @@ test_expect_success 'log.mailmap=false disables mailmap' ' Author: nick1 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> EOF - git -c log.mailmap=False log | grep Author >actual && + git -c log.mailmap=false log | grep Author >actual && test_cmp expect actual ' @@ -498,56 +563,66 @@ test_expect_success '--no-use-mailmap disables mailmap' ' test_cmp expect actual ' -cat >expect <<\EOF -Author: Santa Claus -Author: Santa Claus -EOF - test_expect_success 'Grep author with --use-mailmap' ' + test_config mailmap.file complex.map && + + cat >expect <<-\EOF && + Author: Santa Claus + Author: Santa Claus + EOF git log --use-mailmap --author Santa | grep Author >actual && test_cmp expect actual ' -cat >expect <<\EOF -Author: Santa Claus -Author: Santa Claus -EOF test_expect_success 'Grep author with log.mailmap' ' + test_config mailmap.file complex.map && + + cat >expect <<-\EOF && + Author: Santa Claus + Author: Santa Claus + EOF + git -c log.mailmap=True log --author Santa | grep Author >actual && test_cmp expect actual ' test_expect_success 'log.mailmap is true by default these days' ' + test_config mailmap.file complex.map && git log --author Santa | grep Author >actual && test_cmp expect actual ' test_expect_success 'Only grep replaced author with --use-mailmap' ' + test_config mailmap.file complex.map && git log --use-mailmap --author "" >actual && test_must_be_empty actual ' -# git blame -cat >expect <expect <<-EOF && + ^OBJI ($GIT_AUTHOR_NAME DATE 1) one + OBJID (Some Dude DATE 2) two + OBJID (Other Author DATE 3) three + OBJID (Other Author DATE 4) four + OBJID (Santa Claus DATE 5) five + OBJID (Santa Claus DATE 6) six + OBJID (CTO DATE 7) seven + EOF + git blame one >actual && fuzz_blame actual >actual.fuzz && test_cmp expect actual.fuzz ' -cat >expect <<\EOF -Some Dude -EOF - test_expect_success 'commit --author honors mailmap' ' + test_config mailmap.file complex.map && + + cat >expect <<-\EOF && + Some Dude + EOF + test_must_fail git commit --author "nick" --allow-empty -meight && git commit --author "Some Dude" --allow-empty -meight && git show --pretty=format:"%an <%ae>%n" >actual && From 1db421ab85c44c46f6908eb03d1459d636e2b959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:17:51 +0100 Subject: [PATCH 07/22] mailmap tests: improve --stdin tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The --stdin tests setup the "contact" file in the main setup, let's instead set it up in the test that uses it. Also refactor the first test so it's obvious that the point of it is that "check-mailmap" will spew its input as-is when given no argument. For that one we can just use the "expect" file as-is. Also add tests for how other "--stdin" cases are handled, e.g. one where we actually do a mapping. For the rest of --stdin testing we just assume we're going to get the same output. We could follow-up and make sure everything's round-tripped through both --stdin and the file/blob backends, but I don't think there's much point in that. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t4203-mailmap.sh | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index 61d1b62317..dbd365681e 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -13,11 +13,6 @@ fuzz_blame () { } test_expect_success 'setup commits and contacts file' ' - cat >contacts <<-EOF && - $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> - nick1 - EOF - echo one >one && git add one && test_tick && @@ -48,24 +43,53 @@ test_expect_success 'check-mailmap --stdin' ' $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> nick1 EOF - git check-mailmap --stdin actual && + git check-mailmap --stdin actual && test_cmp expect actual ' -test_expect_success 'check-mailmap --stdin arguments' ' +test_expect_success 'check-mailmap --stdin arguments: no mapping' ' + test_when_finished "rm contacts" && + cat >contacts <<-EOF && + $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> + nick1 + EOF cat >expect <<-\EOF && Internal Guy EOF - cat >expect && + cat contacts >>expect && + git check-mailmap --stdin "Internal Guy " \ actual && test_cmp expect actual ' +test_expect_success 'check-mailmap --stdin arguments: mapping' ' + test_when_finished "rm .mailmap" && + cat >.mailmap <<-EOF && + New Name <$GIT_AUTHOR_EMAIL> + EOF + cat >stdin <<-EOF && + Old Name <$GIT_AUTHOR_EMAIL> + EOF + + cp .mailmap expect && + git check-mailmap --stdin actual && + test_cmp expect actual && + + cat .mailmap >>expect && + git check-mailmap --stdin "Another Old Name <$GIT_AUTHOR_EMAIL>" \ + actual && + test_cmp expect actual +' + test_expect_success 'check-mailmap bogus contact' ' test_must_fail git check-mailmap bogus ' +test_expect_success 'check-mailmap bogus contact --stdin' ' + test_must_fail git check-mailmap --stdin bogus expect <<-EOF && $GIT_AUTHOR_NAME (1): From fb3bbe4ea35cb67279dc4a4509e9bce34a33b2b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:17:52 +0100 Subject: [PATCH 08/22] mailmap tests: remove redundant entry in test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove a redundant line in a test added in d20d654fe8 (Change current mailmap usage to do matching on both name and email of author/committer., 2009-02-08). This didn't conceivably test anything useful and is most likely a copy/paste error. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t4203-mailmap.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index dbd365681e..03a98d9635 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -414,7 +414,6 @@ test_expect_success 'Shortlog output (complex mapping)' ' Other Author nick2 Other Author Santa Claus - Santa Claus EOF echo three >>one && From 400d160e39509fc5d7051f7338293b793cded9e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:17:53 +0100 Subject: [PATCH 09/22] mailmap tests: add a test for "not a blob" error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a test for one of the error conditions added in 938a60d64f (mailmap: clean up read_mailmap error handling, 2012-12-12). Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t4203-mailmap.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index 03a98d9635..78d56e0566 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -333,6 +333,15 @@ test_expect_success 'mailmap.blob can be missing' ' test_cmp expect actual ' +test_expect_success 'mailmap.blob might be the wrong type' ' + test_when_finished "rm .mailmap" && + cp default.map .mailmap && + + git -c mailmap.blob=HEAD: shortlog HEAD >actual 2>err && + test_i18ngrep "mailmap is not a blob" err && + test_cmp expect actual +' + test_expect_success 'mailmap.blob defaults to off in non-bare repo' ' git init non-bare && ( From c1fe7fd7e343517f743c3dc0d905f9f3083f66e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:17:54 +0100 Subject: [PATCH 10/22] mailmap tests: get rid of overly complex blame fuzzing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change a test that used a custom fuzzing function since bfdfa3d414 (t4203 (mailmap): stop hardcoding commit ids and dates, 2010-10-15) to just use the "blame --porcelain" output instead. We could use the same pattern as 0ba9c9a0fb (t8008: rely on rev-parse'd HEAD instead of sha1 value, 2017-07-26) does to do this, but there wouldn't be any point. We're not trying to test "blame" output here in general, just that "blame" pays attention to the mailmap. So it's sufficient to get the blamed line(s) and authors from the output, which is much easier with the "--porcelain" option. It would still be possible for there to be a bug in "blame" such that it uses the mailmap for its "--porcelain" output, but not the regular output. Let's test for that simply by checking if specifying the mailmap changes the output. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t4203-mailmap.sh | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index 78d56e0566..a42b454756 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -4,14 +4,6 @@ test_description='.mailmap configurations' . ./test-lib.sh -fuzz_blame () { - sed " - s/$_x05[0-9a-f][0-9a-f][0-9a-f]/OBJID/g - s/$_x05[0-9a-f][0-9a-f]/OBJI/g - s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g - " "$@" -} - test_expect_success 'setup commits and contacts file' ' echo one >one && git add one && @@ -630,24 +622,42 @@ test_expect_success 'Only grep replaced author with --use-mailmap' ' test_must_be_empty actual ' -test_expect_success 'Blame output (complex mapping)' ' +test_expect_success 'Blame --porcelain output (complex mapping)' ' test_config mailmap.file complex.map && cat >expect <<-EOF && - ^OBJI ($GIT_AUTHOR_NAME DATE 1) one - OBJID (Some Dude DATE 2) two - OBJID (Other Author DATE 3) three - OBJID (Other Author DATE 4) four - OBJID (Santa Claus DATE 5) five - OBJID (Santa Claus DATE 6) six - OBJID (CTO DATE 7) seven + 1 1 1 + A U Thor + 2 2 1 + Some Dude + 3 3 1 + Other Author + 4 4 1 + Other Author + 5 5 1 + Santa Claus + 6 6 1 + Santa Claus + 7 7 1 + CTO EOF - git blame one >actual && - fuzz_blame actual >actual.fuzz && + git blame --porcelain one >actual.blame && + grep -E \ + -e "[0-9]+ [0-9]+ [0-9]+$" \ + -e "^author .*$" \ + actual.blame >actual.grep && + cut -d " " -f2-4 actual.fuzz && test_cmp expect actual.fuzz ' +test_expect_success 'Blame output (complex mapping)' ' + git -c mailmap.file=complex.map blame one >a && + git blame one >b && + test_file_not_empty a && + ! cmp a b +' + test_expect_success 'commit --author honors mailmap' ' test_config mailmap.file complex.map && From 56ac194e1d3b3f3b46c2d48f47bde69d35547a7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:17:55 +0100 Subject: [PATCH 11/22] mailmap: test for silent exiting on missing file/blob MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit That we silently ignore missing mailmap.file or mailmap.blob values is intentional. See 938a60d64f (mailmap: clean up read_mailmap error handling, 2012-12-12). However, nothing tested for this. Let's do that by checking that stderr is empty in those cases. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t4203-mailmap.sh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index a42b454756..2b342d7f7c 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -309,6 +309,24 @@ test_expect_success 'mailmap.file overrides mailmap.blob' ' test_cmp expect actual ' +test_expect_success 'mailmap.file can be missing' ' + test_when_finished "rm .mailmap" && + cp default.map .mailmap && + + test_config mailmap.file nonexistent && + cat >expect <<-\EOF && + Repo Guy (1): + initial + + nick1 (1): + second + + EOF + git shortlog HEAD >actual 2>err && + test_must_be_empty err && + test_cmp expect actual +' + test_expect_success 'mailmap.blob can be missing' ' test_when_finished "rm .mailmap" && cp default.map .mailmap && @@ -321,7 +339,8 @@ test_expect_success 'mailmap.blob can be missing' ' second EOF - git -c mailmap.blob=map:nonexistent shortlog HEAD >actual && + git -c mailmap.blob=map:nonexistent shortlog HEAD >actual 2>err && + test_must_be_empty err && test_cmp expect actual ' From f21426e189f3ace9dcf9d713b2c2f2721515b886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:17:56 +0100 Subject: [PATCH 12/22] test-lib functions: expand "test_commit" comment template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Expand the comment template for "test_commit" to match that of "test_commit_bulk" added in b1c36cb849 (test-lib: introduce test_commit_bulk, 2019-07-02). It has several undocumented options, which won't all fit on one line. Follow-up commit(s) will document them. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/test-lib-functions.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 999982fe4a..396e039d2a 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -178,16 +178,14 @@ debug () { GIT_DEBUGGER="${GIT_DEBUGGER}" "$@" <&6 >&5 2>&7 } -# Call test_commit with the arguments -# [-C ] [ [ []]]" +# Usage: test_commit [options] [ [ []]] +# -C : +# Run all git commands in directory # # This will commit a file with the given contents and the given commit # message, and tag the resulting commit with the given tag name. # # , , and all default to . -# -# If the first argument is "-C", the second argument is used as a path for -# the git invocations. test_commit () { notick= && From 76b8b8d05c723232f27d9396d3ddfd2b10394187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:17:57 +0100 Subject: [PATCH 13/22] test-lib functions: document arguments to test_commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The --notick argument was added in [1] and was followed by --signoff in [2], but neither of these commits added any documentation for these options. When -C was added in [3] a comment was added to document it, but not the other options. Let's document all of these options. 1. 44b85e89d7 (t7003: add test to filter a branch with a commit at epoch, 2012-07-12), 2. 5ed75e2a3f (cherry-pick: don't forget -s on failure, 2012-09-14). 3. 6f94351b0a (test-lib-functions.sh: teach test_commit -C , 2016-12-08) Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/test-lib-functions.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 396e039d2a..194b601bc0 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -181,6 +181,10 @@ debug () { # Usage: test_commit [options] [ [ []]] # -C : # Run all git commands in directory +# --notick +# Do not call test_tick before making a commit +# --signoff +# Invoke "git commit" with --signoff # # This will commit a file with the given contents and the given commit # message, and tag the resulting commit with the given tag name. From 999cfc4f45e90a2eafa9b170d0ab9f0f13cbddb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:17:58 +0100 Subject: [PATCH 14/22] test-lib functions: add --author support to test_commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for --author to "test_commit". This will simplify some current and future tests, one of those is being changed here. Let's also line-wrap the "git commit" command invocation to make diffs that add subsequent options easier to add, as they'll only need to add a new option line. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t7509-commit-authorship.sh | 7 ++----- t/test-lib-functions.sh | 11 ++++++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/t/t7509-commit-authorship.sh b/t/t7509-commit-authorship.sh index 500ab2fe72..ee6c47416e 100755 --- a/t/t7509-commit-authorship.sh +++ b/t/t7509-commit-authorship.sh @@ -18,11 +18,8 @@ message_body () { } test_expect_success '-C option copies authorship and message' ' - echo "Initial" >foo && - git add foo && - test_tick && - git commit -m "Initial Commit" --author Frigate\ \ && - git tag Initial && + test_commit --author Frigate\ \ \ + "Initial Commit" foo Initial Initial && echo "Test 1" >>foo && test_tick && git commit -a -C Initial && diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 194b601bc0..529f6264fe 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -185,6 +185,8 @@ debug () { # Do not call test_tick before making a commit # --signoff # Invoke "git commit" with --signoff +# --author= +# Invoke "git commit" with --author= # # This will commit a file with the given contents and the given commit # message, and tag the resulting commit with the given tag name. @@ -193,6 +195,7 @@ debug () { test_commit () { notick= && + author= && signoff= && indir= && while test $# != 0 @@ -201,6 +204,10 @@ test_commit () { --notick) notick=yes ;; + --author) + author="$2" + shift + ;; --signoff) signoff="$1" ;; @@ -222,7 +229,9 @@ test_commit () { then test_tick fi && - git ${indir:+ -C "$indir"} commit $signoff -m "$1" && + git ${indir:+ -C "$indir"} commit \ + ${author:+ --author "$author"} \ + $signoff -m "$1" && git ${indir:+ -C "$indir"} tag "${4:-$1}" } From 3373518cc8bd0916581ccfd4a2ee9682d61a8874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:17:59 +0100 Subject: [PATCH 15/22] test-lib functions: add an --append option to test_commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add an --append option to test_commit to append to the we're writing to. This simplifies a lot of test setup, as shown in some of the tests being changed here. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t4203-mailmap.sh | 39 +++++++-------------------------------- t/test-lib-functions.sh | 14 +++++++++++++- 2 files changed, 20 insertions(+), 33 deletions(-) diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index 2b342d7f7c..5d92880a5a 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -5,14 +5,8 @@ test_description='.mailmap configurations' . ./test-lib.sh test_expect_success 'setup commits and contacts file' ' - echo one >one && - git add one && - test_tick && - git commit -m initial && - echo two >>one && - git add one && - test_tick && - git commit --author "nick1 " -m second + test_commit initial one one && + test_commit --author "nick1 " --append second one two ' test_expect_success 'check-mailmap no arguments' ' @@ -436,30 +430,11 @@ test_expect_success 'Shortlog output (complex mapping)' ' Santa Claus EOF - echo three >>one && - git add one && - test_tick && - git commit --author "nick2 " -m third && - - echo four >>one && - git add one && - test_tick && - git commit --author "nick2 " -m fourth && - - echo five >>one && - git add one && - test_tick && - git commit --author "santa " -m fifth && - - echo six >>one && - git add one && - test_tick && - git commit --author "claus " -m sixth && - - echo seven >>one && - git add one && - test_tick && - git commit --author "CTO " -m seventh && + test_commit --author "nick2 " --append third one three && + test_commit --author "nick2 " --append fourth one four && + test_commit --author "santa " --append fifth one five && + test_commit --author "claus " --append sixth one six && + test_commit --author "CTO " --append seventh one seven && cat >expect <<-EOF && $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> (1): diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 529f6264fe..b0a5d74dc7 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -183,6 +183,9 @@ debug () { # Run all git commands in directory # --notick # Do not call test_tick before making a commit +# --append +# Use "echo >>" instead of "echo >" when writing "" to +# "" # --signoff # Invoke "git commit" with --signoff # --author= @@ -195,6 +198,7 @@ debug () { test_commit () { notick= && + append= && author= && signoff= && indir= && @@ -204,6 +208,9 @@ test_commit () { --notick) notick=yes ;; + --append) + append=yes + ;; --author) author="$2" shift @@ -223,7 +230,12 @@ test_commit () { done && indir=${indir:+"$indir"/} && file=${2:-"$1.t"} && - echo "${3-$1}" > "$indir$file" && + if test -n "$append" + then + echo "${3-$1}" >>"$indir$file" + else + echo "${3-$1}" >"$indir$file" + fi && git ${indir:+ -C "$indir"} add "$file" && if test -z "$notick" then From f5d79bf7dd6996b96009ac63b350aa047f2d9959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:18:00 +0100 Subject: [PATCH 16/22] tests: refactor a few tests to use "test_commit --append" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor a few more tests to use the new "--append" option to "test_commit". I added it for use in the mailmap tests, but this demonstrates how useful it is in general. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t1412-reflog-loop.sh | 7 ++----- t/t2012-checkout-last.sh | 12 +++--------- t/t7810-grep.sh | 18 +++--------------- 3 files changed, 8 insertions(+), 29 deletions(-) diff --git a/t/t1412-reflog-loop.sh b/t/t1412-reflog-loop.sh index 3acd895afb..977603f7f1 100755 --- a/t/t1412-reflog-loop.sh +++ b/t/t1412-reflog-loop.sh @@ -4,11 +4,8 @@ test_description='reflog walk shows repeated commits again' . ./test-lib.sh test_expect_success 'setup commits' ' - test_tick && - echo content >file && git add file && git commit -m one && - git tag one && - echo content >>file && git add file && git commit -m two && - git tag two + test_commit one file content && + test_commit --append two file content ' test_expect_success 'setup reflog with alternating commits' ' diff --git a/t/t2012-checkout-last.sh b/t/t2012-checkout-last.sh index e7ba8c505f..c95aa3e78f 100755 --- a/t/t2012-checkout-last.sh +++ b/t/t2012-checkout-last.sh @@ -5,13 +5,9 @@ test_description='checkout can switch to last branch and merge base' . ./test-lib.sh test_expect_success 'setup' ' - echo hello >world && - git add world && - git commit -m initial && + test_commit initial world hello && git branch other && - echo "hello again" >>world && - git add world && - git commit -m second + test_commit --append second world "hello again" ' test_expect_success '"checkout -" does not work initially' ' @@ -93,9 +89,7 @@ test_expect_success 'switch to twelfth from the last' ' test_expect_success 'merge base test setup' ' git checkout -b another other && - echo "hello again" >>world && - git add world && - git commit -m third + test_commit --append third world "hello again" ' test_expect_success 'another...master' ' diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index 991d5bd9c0..312e0f8cb4 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -687,21 +687,9 @@ test_expect_success 'grep -C1 hunk mark between files' ' ' test_expect_success 'log grep setup' ' - echo a >>file && - test_tick && - GIT_AUTHOR_NAME="With * Asterisk" \ - GIT_AUTHOR_EMAIL="xyzzy@frotz.com" \ - git commit -a -m "second" && - - echo a >>file && - test_tick && - git commit -a -m "third" && - - echo a >>file && - test_tick && - GIT_AUTHOR_NAME="Night Fall" \ - GIT_AUTHOR_EMAIL="nitfol@frobozz.com" \ - git commit -a -m "fourth" + test_commit --append --author "With * Asterisk " second file a && + test_commit --append third file a && + test_commit --append --author "Night Fall " fourth file a ' test_expect_success 'log grep (1)' ' From 05b5ff219c22ca8b3abb7fed3e4dcaf41fe46018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:18:01 +0100 Subject: [PATCH 17/22] mailmap doc + tests: add better examples & test them MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change the mailmap documentation added in 0925ce4d49 (Add map_user() and clear_mailmap() to mailmap, 2009-02-08) to continue discussing the Jane/Joe example. I think this makes things a lot less confusing as we're building up more complex examples using one set of data which covers all the things we'd like to discuss. Also add tests to assert that what our documentation says is what's actually happening. This is mostly (or entirely) covered by existing tests which I'm not deleting, but having these tests for the synopsis makes it easier to follow-along while reading the tests & docs. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- Documentation/gitmailmap.txt | 51 ++++++++++++--------- t/t4203-mailmap.sh | 88 ++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 21 deletions(-) diff --git a/Documentation/gitmailmap.txt b/Documentation/gitmailmap.txt index 4e4677018b..55dfebd1b1 100644 --- a/Documentation/gitmailmap.txt +++ b/Documentation/gitmailmap.txt @@ -53,7 +53,7 @@ commit matching both the specified commit name and email address. EXAMPLES -------- -Example 1: Your history contains commits by two authors, Jane +Your history contains commits by two authors, Jane and Joe, whose names appear in the repository under several forms: ------------ @@ -65,36 +65,45 @@ Jane D. ------------ Now suppose that Joe wants his middle name initial used, and Jane -prefers her family name fully spelled out. A proper `.mailmap` file -would look like: +prefers her family name fully spelled out. A `.mailmap` file to +correct the names would look like: ------------ -Jane Doe Joe R. Developer +Jane Doe +Jane Doe ------------ -Note how there is no need for an entry for ``, because the -real name of that author is already correct. - -Example 2: Your repository contains commits from the following -authors: +Note that there's no need to map the name for 'jane@laptop.(none)' to +only correct the names. However, leaving the obviously broken +`' and '' E-Mails as-is is +usually not what you want. A `.mailmap` file which also corrects those +is: ------------ -nick1 -nick2 -nick2 -santa -claus -CTO +Joe R. Developer +Jane Doe +Jane Doe ------------ -Then you might want a `.mailmap` file that looks like: +Finally, let's say that Joe and Jane shared an E-Mail address, but not +a name, e.g. by having these two commits in the history generated by a +bug reporting system. I.e. names appearing in history as: + ------------ - -Some Dude nick1 -Other Author nick2 -Other Author -Santa Claus +Joe +Jane +------------ + +A full `.mailmap` file which also handles those cases (an addition of +two lines to the above example) would be: + +------------ +Joe R. Developer +Jane Doe +Jane Doe +Joe R. Developer Joe +Jane Doe Jane ------------ diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index 5d92880a5a..96ba5367c6 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -419,6 +419,94 @@ test_expect_success 'preserve canonical email case' ' test_cmp expect actual ' +test_expect_success 'gitmailmap(5) example output: setup' ' + test_create_repo doc && + test_commit -C doc --author "Joe Developer " A && + test_commit -C doc --author "Joe R. Developer " B && + test_commit -C doc --author "Jane Doe " C && + test_commit -C doc --author "Jane Doe " D && + test_commit -C doc --author "Jane D. " E +' + +test_expect_success 'gitmailmap(5) example output: example #1' ' + test_config -C doc mailmap.file ../doc.map && + cat >doc.map <<-\EOF && + Joe R. Developer + Jane Doe + Jane Doe + EOF + + cat >expect <<-\EOF && + Author Joe Developer maps to Joe R. Developer + Committer C O Mitter maps to C O Mitter + + Author Joe R. Developer maps to Joe R. Developer + Committer C O Mitter maps to C O Mitter + + Author Jane Doe maps to Jane Doe + Committer C O Mitter maps to C O Mitter + + Author Jane Doe maps to Jane Doe + Committer C O Mitter maps to C O Mitter + + Author Jane D maps to Jane Doe + Committer C O Mitter maps to C O Mitter + EOF + git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual && + test_cmp expect actual +' + +test_expect_success 'gitmailmap(5) example output: example #2' ' + test_config -C doc mailmap.file ../doc.map && + cat >doc.map <<-\EOF && + Joe R. Developer + Jane Doe + Jane Doe + EOF + + cat >expect <<-\EOF && + Author Joe Developer maps to Joe R. Developer + Committer C O Mitter maps to C O Mitter + + Author Joe R. Developer maps to Joe R. Developer + Committer C O Mitter maps to C O Mitter + + Author Jane Doe maps to Jane Doe + Committer C O Mitter maps to C O Mitter + + Author Jane Doe maps to Jane Doe + Committer C O Mitter maps to C O Mitter + + Author Jane D maps to Jane Doe + Committer C O Mitter maps to C O Mitter + EOF + git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual && + test_cmp expect actual +' + +test_expect_success 'gitmailmap(5) example output: example #3' ' + test_config -C doc mailmap.file ../doc.map && + cat >>doc.map <<-\EOF && + Joe R. Developer Joe + Jane Doe Jane + EOF + + test_commit -C doc --author "Joe " F && + test_commit -C doc --author "Jane " G && + + cat >>expect <<-\EOF && + + Author Joe maps to Joe R. Developer + Committer C O Mitter maps to C O Mitter + + Author Jane maps to Jane Doe + Committer C O Mitter maps to C O Mitter + EOF + git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual && + test_cmp expect actual +' + + test_expect_success 'Shortlog output (complex mapping)' ' test_config mailmap.file complex.map && cat >complex.map <<-EOF && From 9b391b09a084d49a71d29f1a90637252db427cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:18:02 +0100 Subject: [PATCH 18/22] mailmap tests: add a test for comment syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a test for mailmap comment syntax. As noted in [1] there was no test coverage for this. Let's make sure a future change doesn't break it. 1. https://lore.kernel.org/git/CAN0heSoKYWXqskCR=GPreSHc6twCSo1345WTmiPdrR57XSShhA@mail.gmail.com/ Reported-by: Martin Ågren Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t4203-mailmap.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index 96ba5367c6..10e672e006 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -753,4 +753,37 @@ test_expect_success 'commit --author honors mailmap' ' test_cmp expect actual ' +test_expect_success 'comment syntax: setup' ' + test_create_repo comm && + test_commit -C comm --author "A " A && + test_commit -C comm --author "B " B && + test_commit -C comm --author "C <#@example.com>" C && + test_commit -C comm --author "D " D && + + test_config -C comm mailmap.file ../doc.map && + cat >>doc.map <<-\EOF && + # Ah + + ; Bee + Cee <#@example.com> + Dee + EOF + + cat >expect <<-\EOF && + Author A maps to A + Committer C O Mitter maps to C O Mitter + + Author B maps to ; Bee + Committer C O Mitter maps to C O Mitter + + Author C <#@example.com> maps to Cee + Committer C O Mitter maps to C O Mitter + + Author D maps to Dee + Committer C O Mitter maps to C O Mitter + EOF + git -C comm log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual && + test_cmp expect actual +' + test_done From 9e2a14a88953da80cba75ddde4488a88402e7c8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:18:03 +0100 Subject: [PATCH 19/22] mailmap tests: add tests for whitespace syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add tests for mailmap's handling of whitespace, i.e. how it trims space within "<>" and around author names. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t4203-mailmap.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index 10e672e006..4f61655c04 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -786,4 +786,56 @@ test_expect_success 'comment syntax: setup' ' test_cmp expect actual ' +test_expect_success 'whitespace syntax: setup' ' + test_create_repo space && + test_commit -C space --author "A " A && + test_commit -C space --author "B " B && + test_commit -C space --author " C " C && + test_commit -C space --author " D " D && + test_commit -C space --author "E E " E && + test_commit -C space --author "F F " F && + test_commit -C space --author "G G " G && + test_commit -C space --author "H H " H && + + test_config -C space mailmap.file ../space.map && + cat >>space.map <<-\EOF && + Ah < a@example.com > + Bee < b@example.com > + Cee C + dee D + eee E E + eff F F + gee G G + aitch H H + EOF + + cat >expect <<-\EOF && + Author A maps to A + Committer C O Mitter maps to C O Mitter + + Author B maps to B + Committer C O Mitter maps to C O Mitter + + Author C maps to Cee + Committer C O Mitter maps to C O Mitter + + Author D maps to dee + Committer C O Mitter maps to C O Mitter + + Author E E maps to eee + Committer C O Mitter maps to C O Mitter + + Author F F maps to eff + Committer C O Mitter maps to C O Mitter + + Author G G maps to gee + Committer C O Mitter maps to C O Mitter + + Author H H maps to H H + Committer C O Mitter maps to C O Mitter + EOF + git -C space log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual && + test_cmp expect actual +' + test_done From 34986b773a0ebe0298965b64c801dd983cba29e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:18:04 +0100 Subject: [PATCH 20/22] mailmap tests: add tests for empty "<>" syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add tests for mailmap's handling of "<>", which is allowed on the RHS, but not the LHS of a " " pair. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t4203-mailmap.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index 4f61655c04..f19736fef1 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -838,4 +838,31 @@ test_expect_success 'whitespace syntax: setup' ' test_cmp expect actual ' +test_expect_success 'empty syntax: setup' ' + test_create_repo empty && + test_commit -C empty --author "A <>" A && + test_commit -C empty --author "B " B && + test_commit -C empty --author "C " C && + + test_config -C empty mailmap.file ../empty.map && + cat >>empty.map <<-\EOF && + Ah <> + Bee <> + Cee <> + EOF + + cat >expect <<-\EOF && + Author A <> maps to Bee + Committer C O Mitter maps to C O Mitter + + Author B maps to B + Committer C O Mitter maps to C O Mitter + + Author C maps to C + Committer C O Mitter maps to C O Mitter + EOF + git -C empty log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual && + test_cmp expect actual +' + test_done From 238803cb409930a9cbbe911917b28817d182330e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:18:05 +0100 Subject: [PATCH 21/22] mailmap doc + tests: document and test for case-insensitivity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add documentation and more tests for case-insensitivity. The existing test only matched on the E-Mail part, but as shown here we also match the name with strcasecmp(). This behavior was last discussed on the mailing list in the thread starting at [1]. It seems we're keeping it like this, so let's document it. 1. https://lore.kernel.org/git/87czykvg19.fsf@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- Documentation/gitmailmap.txt | 5 +++++ t/t4203-mailmap.sh | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Documentation/gitmailmap.txt b/Documentation/gitmailmap.txt index 55dfebd1b1..7f1089786d 100644 --- a/Documentation/gitmailmap.txt +++ b/Documentation/gitmailmap.txt @@ -49,6 +49,11 @@ commit matching the specified commit email address, and: which allows mailmap to replace both the name and the email of a commit matching both the specified commit name and email address. +Both E-Mails and names are matched case-insensitively. For example +this would also match the 'Commit Name ' above: +-- +Proper Name CoMmIt NaMe +-- EXAMPLES -------- diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index f19736fef1..89cb300f28 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -220,7 +220,21 @@ test_expect_success 'name entry after email entry, case-insensitive' ' initial EOF + git shortlog HEAD >actual && + test_cmp expect actual && + cat >internal.map <<-\EOF && + NiCk NICK1 + EOF + + cat >expect <<-\EOF && + NiCk (1): + second + + Repo Guy (1): + initial + + EOF git shortlog HEAD >actual && test_cmp expect actual ' From 4e168333a8716d902aed10c74ae5e408e683f902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 12 Jan 2021 21:18:06 +0100 Subject: [PATCH 22/22] shortlog: remove unused(?) "repo-abbrev" feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove support for the magical "repo-abbrev" comment in .mailmap files. This was added to .mailmap parsing in [1], as a generalized feature of the git-shortlog Perl script added earlier in [2]. There was no documentation or tests for this feature, and I don't think it's used in practice anymore. What it did was to allow you to specify a single string to be search-replaced with "/.../" in the .mailmap file. E.g. for linux.git's current .mailmap: git archive --remote=git@gitlab.com:linux-kernel/linux.git \ HEAD -- .mailmap | grep -a repo-abbrev # repo-abbrev: /pub/scm/linux/kernel/git/ Then when running e.g.: git shortlog --merges --author=Linus -1 v5.10-rc7..v5.10 | grep Merge We'd emit (the [...] is mine): Merge tag [...]git://git.kernel.org/.../tip/tip But will now emit: Merge tag [...]git.kernel.org/pub/scm/linux/kernel/git/tip/tip I think at this point this is just a historical artifact we can get rid of. It was initially meant for Linus's own use when we integrated the Perl script[2], but since then it seems he's stopped using it. Digging through Linus's release announcements on the LKML[3] the last release I can find that made use of this output is Linux 2.6.25-rc6 back in March 2008[4]. Later on Linus started using --no-merges[5], and nowadays seems to prefer some custom not-quite-shortlog format of merges from lieutenants[6]. You will still see it on linux.git if you run "git shortlog" manually yourself with --merges, with this removed you can still get the same output with: git log --pretty=fuller v5.10-rc7..v5.10 | sed 's!/pub/scm/linux/kernel/git/!/.../!g' | git shortlog Arguably we should do the same for the search-replacing of "[PATCH]" at the beginning with "". That seems to be another relic of a bygone era when linux.git patches would have their E-Mail subject lines applied as-is by "git am" or whatever. But we documented that feature in "git-shortlog(1)", and it seems more widely applicable than something purely kernel-specific. 1. 7595e2ee6ef (git-shortlog: make common repository prefix configurable with .mailmap, 2006-11-25) 2. fa375c7f1b6 (Add git-shortlog perl script, 2005-06-04) 3. https://lore.kernel.org/lkml/ 4. https://lore.kernel.org/lkml/alpine.LFD.1.00.0803161651350.3020@woody.linux-foundation.org/ 5. https://lore.kernel.org/lkml/BANLkTinrbh7Xi27an3uY7pDWrNKhJRYmEA@mail.gmail.com/ 6. https://lore.kernel.org/lkml/CAHk-=wg1+kf1AVzXA-RQX0zjM6t9J2Kay9xyuNqcFHWV-y5ZYw@mail.gmail.com/ Acked-by: Linus Torvalds Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- builtin/blame.c | 2 +- builtin/check-mailmap.c | 2 +- builtin/commit.c | 2 +- builtin/log.c | 2 +- builtin/shortlog.c | 16 ++------------ mailmap.c | 48 +++++++++++------------------------------ mailmap.h | 2 +- pretty.c | 2 +- shortlog.h | 1 - 9 files changed, 21 insertions(+), 56 deletions(-) diff --git a/builtin/blame.c b/builtin/blame.c index 6f7e32411a..712ae8e742 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -1151,7 +1151,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix) sb.xdl_opts = xdl_opts; sb.no_whole_file_rename = no_whole_file_rename; - read_mailmap(&mailmap, NULL); + read_mailmap(&mailmap); sb.found_guilty_entry = &found_guilty_entry; sb.found_guilty_entry_data = π diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c index cdce144f3b..7dc47e4793 100644 --- a/builtin/check-mailmap.c +++ b/builtin/check-mailmap.c @@ -47,7 +47,7 @@ int cmd_check_mailmap(int argc, const char **argv, const char *prefix) if (argc == 0 && !use_stdin) die(_("no contacts specified")); - read_mailmap(&mailmap, NULL); + read_mailmap(&mailmap); for (i = 0; i < argc; ++i) check_mailmap(&mailmap, argv[i]); diff --git a/builtin/commit.c b/builtin/commit.c index 505fe60956..739110c5a7 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1039,7 +1039,7 @@ static const char *find_author_by_nickname(const char *name) av[++ac] = NULL; setup_revisions(ac, av, &revs, NULL); revs.mailmap = &mailmap; - read_mailmap(revs.mailmap, NULL); + read_mailmap(revs.mailmap); if (prepare_revision_walk(&revs)) die(_("revision walk setup failed")); diff --git a/builtin/log.c b/builtin/log.c index bd6ff4f9f9..4ee81bc976 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -230,7 +230,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, if (mailmap) { rev->mailmap = xcalloc(1, sizeof(struct string_list)); - read_mailmap(rev->mailmap, NULL); + read_mailmap(rev->mailmap); } if (rev->pretty_given && rev->commit_format == CMIT_FMT_RAW) { diff --git a/builtin/shortlog.c b/builtin/shortlog.c index c52e4ccd19..e7c21ab620 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -61,8 +61,7 @@ static void insert_one_record(struct shortlog *log, if (log->summary) item->util = (void *)(UTIL_TO_INT(item) + 1); else { - const char *dot3 = log->common_repo_prefix; - char *buffer, *p; + char *buffer; struct strbuf subject = STRBUF_INIT; const char *eol; @@ -82,17 +81,6 @@ static void insert_one_record(struct shortlog *log, format_subject(&subject, oneline, " "); buffer = strbuf_detach(&subject, NULL); - if (dot3) { - int dot3len = strlen(dot3); - if (dot3len > 5) { - while ((p = strstr(buffer, dot3)) != NULL) { - int taillen = strlen(p) - dot3len; - memcpy(p, "/.../", 5); - memmove(p + 5, p + dot3len, taillen + 1); - } - } - } - if (item->util == NULL) item->util = xcalloc(1, sizeof(struct string_list)); string_list_append(item->util, buffer); @@ -342,7 +330,7 @@ void shortlog_init(struct shortlog *log) { memset(log, 0, sizeof(*log)); - read_mailmap(&log->mailmap, &log->common_repo_prefix); + read_mailmap(&log->mailmap); log->list.strdup_strings = 1; log->wrap = DEFAULT_WRAPLEN; diff --git a/mailmap.c b/mailmap.c index 962fd86d6d..eb77c6e77c 100644 --- a/mailmap.c +++ b/mailmap.c @@ -143,31 +143,13 @@ static char *parse_name_and_email(char *buffer, char **name, return (*right == '\0' ? NULL : right); } -static void read_mailmap_line(struct string_list *map, char *buffer, - char **repo_abbrev) +static void read_mailmap_line(struct string_list *map, char *buffer) { char *name1 = NULL, *email1 = NULL, *name2 = NULL, *email2 = NULL; - if (buffer[0] == '#') { - static const char abbrev[] = "# repo-abbrev:"; - int abblen = sizeof(abbrev) - 1; - int len = strlen(buffer); - if (!repo_abbrev) - return; - - if (len && buffer[len - 1] == '\n') - buffer[--len] = 0; - if (!strncmp(buffer, abbrev, abblen)) { - char *cp; - - free(*repo_abbrev); - - for (cp = buffer + abblen; isspace(*cp); cp++) - ; /* nothing */ - *repo_abbrev = xstrdup(cp); - } + if (buffer[0] == '#') return; - } + if ((name2 = parse_name_and_email(buffer, &name1, &email1, 0)) != NULL) parse_name_and_email(name2, &name2, &email2, 1); @@ -175,8 +157,7 @@ static void read_mailmap_line(struct string_list *map, char *buffer, add_mapping(map, name1, email1, name2, email2); } -static int read_mailmap_file(struct string_list *map, const char *filename, - char **repo_abbrev) +static int read_mailmap_file(struct string_list *map, const char *filename) { char buffer[1024]; FILE *f; @@ -192,13 +173,12 @@ static int read_mailmap_file(struct string_list *map, const char *filename, } while (fgets(buffer, sizeof(buffer), f) != NULL) - read_mailmap_line(map, buffer, repo_abbrev); + read_mailmap_line(map, buffer); fclose(f); return 0; } -static void read_mailmap_string(struct string_list *map, char *buf, - char **repo_abbrev) +static void read_mailmap_string(struct string_list *map, char *buf) { while (*buf) { char *end = strchrnul(buf, '\n'); @@ -206,14 +186,12 @@ static void read_mailmap_string(struct string_list *map, char *buf, if (*end) *end++ = '\0'; - read_mailmap_line(map, buf, repo_abbrev); + read_mailmap_line(map, buf); buf = end; } } -static int read_mailmap_blob(struct string_list *map, - const char *name, - char **repo_abbrev) +static int read_mailmap_blob(struct string_list *map, const char *name) { struct object_id oid; char *buf; @@ -231,13 +209,13 @@ static int read_mailmap_blob(struct string_list *map, if (type != OBJ_BLOB) return error("mailmap is not a blob: %s", name); - read_mailmap_string(map, buf, repo_abbrev); + read_mailmap_string(map, buf); free(buf); return 0; } -int read_mailmap(struct string_list *map, char **repo_abbrev) +int read_mailmap(struct string_list *map) { int err = 0; @@ -247,10 +225,10 @@ int read_mailmap(struct string_list *map, char **repo_abbrev) if (!git_mailmap_blob && is_bare_repository()) git_mailmap_blob = "HEAD:.mailmap"; - err |= read_mailmap_file(map, ".mailmap", repo_abbrev); + err |= read_mailmap_file(map, ".mailmap"); if (startup_info->have_repository) - err |= read_mailmap_blob(map, git_mailmap_blob, repo_abbrev); - err |= read_mailmap_file(map, git_mailmap_file, repo_abbrev); + err |= read_mailmap_blob(map, git_mailmap_blob); + err |= read_mailmap_file(map, git_mailmap_file); return err; } diff --git a/mailmap.h b/mailmap.h index d0e65646cb..7e99fccb46 100644 --- a/mailmap.h +++ b/mailmap.h @@ -3,7 +3,7 @@ struct string_list; -int read_mailmap(struct string_list *map, char **repo_abbrev); +int read_mailmap(struct string_list *map); void clear_mailmap(struct string_list *map); int map_user(struct string_list *map, diff --git a/pretty.c b/pretty.c index 05eef7fda0..3922f6f9f2 100644 --- a/pretty.c +++ b/pretty.c @@ -679,7 +679,7 @@ static int mailmap_name(const char **email, size_t *email_len, static struct string_list *mail_map; if (!mail_map) { mail_map = xcalloc(1, sizeof(*mail_map)); - read_mailmap(mail_map, NULL); + read_mailmap(mail_map); } return mail_map->nr && map_user(mail_map, email, email_len, name, name_len); } diff --git a/shortlog.h b/shortlog.h index 64be879b24..3f7e9aabca 100644 --- a/shortlog.h +++ b/shortlog.h @@ -23,7 +23,6 @@ struct shortlog { } groups; struct string_list trailers; - char *common_repo_prefix; int email; struct string_list mailmap; FILE *file;