threads / patch / 51466

v2, 3 partsuse mailmap by default in git log

Subject: [PATCH v2 0/3] use mailmap by default in git log

## tl;dr

9 messages between Jul 11, 2019 and Jul 11, 2019. Diffs are folded; open one to read it.

replies: 8people: 2as markdown or json

Ariadne Conill· Jul 11, 2019, 17:26 UTC · lore

It is not uncommon for people to change their name or e-mail address. To facilitate this, Git provides support for the `.mailmap` file, which contains a list of identities and previously used e-mail addresses that are associated with that identity.

Unfortunately, while Git's support for the `.mailmap` file is generally excellent, I recently discovered that `git log` does not treat the mail map file the same as the other tools, instead requiring an explicit flag to use the mailmap file.

I believe this is an unfortunate flaw, as the mailmap file should ideally contain the most current known contact information for a contributor, allowing anyone to contact the contributor about their patches in the future.

New in version 2:
- The `--no-use-mailmap` option, which complements `--use-mailmap`.
- Tests for `--no-use-mailmap`.
Ariadne Conill (3):
  log: use mailmap by default
  log: add --no-use-mailmap option to complement --use-mailmap option
  tests: add test for git log --no-use-mailmap
 Documentation/git-log.txt | 5 +++++
 builtin/log.c             | 3 ++-
 t/t4203-mailmap.sh        | 8 ++++++++
 3 files changed, 15 insertions(+), 1 deletion(-)
-- 
2.17.1
Ariadne Conill· Jul 11, 2019, 17:26 UTC · re: Ariadne Conill · lore

[PATCH v2 1/3] log: use mailmap by default

The `git log` command shows the author and committer name recorded in the git repository itself, while other commands respect `.mailmap` by default. I believe this is a bad design: it causes log entries to reflect inaccurate information: anyone who changes their name or e-mail address will not have that change (recorded in mailmap file) reflected when using `git log` by default.

Anyone who explicitly wants the current behaviour can clearly request it by setting the `log.mailmap` setting to `false` in their `.gitconfig` file.

Signed-off-by: Ariadne Conill <ariadne@dereferenced.org>
---
 builtin/log.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to builtin/log.c +1 −1
diff --git a/builtin/log.c b/builtin/log.c
index 7c8767d3bc..3d2ce8fa3d 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -47,7 +47,7 @@ static int default_follow;
 static int default_show_signature;
 static int decoration_style;
 static int decoration_given;
-static int use_mailmap_config;
+static int use_mailmap_config = 1;
 static const char *fmt_patch_subject_prefix = "PATCH";
 static const char *fmt_pretty;
 
-- 
2.17.1
Ariadne Conill· Jul 11, 2019, 17:26 UTC · re: Ariadne Conill · lore

[PATCH v2 2/3] log: add --no-use-mailmap option to complement --use-mailmap option

When mailmap is enabled by default or by configuration, it may be useful to override the default behaviour. Previously, it was possible to enable the mailmap feature when it was disabled by default or in the configuration, but it was not possible to disable the mailmap feature when it was enabled by default or by the configuration.

The --no-use-mailmap option equalizes this by allowing the user to explicitly enable or disable the mailmap feature according to their requirements.

Signed-off-by: Ariadne Conill <ariadne@dereferenced.org>
---
 Documentation/git-log.txt | 5 +++++
 builtin/log.c             | 1 +
 2 files changed, 6 insertions(+)
Show changes to 2 files +6 −0

Documentation/git-log.txt, builtin/log.c

diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
index b02e922dc3..50bc8f7da2 100644
--- a/Documentation/git-log.txt
+++ b/Documentation/git-log.txt
@@ -54,6 +54,11 @@ OPTIONS
 	addresses to canonical real names and email addresses. See
 	linkgit:git-shortlog[1].
 
+--no-use-mailmap::
+	Do not use the mailmap file to map author and commiter names
+	and email addresses to canonical real names and email addresses.
+	See linkgit:git-shortlog[1].
+
 --full-diff::
 	Without this flag, `git log -p <path>...` shows commits that
 	touch the specified paths, and diffs about the same specified
diff --git a/builtin/log.c b/builtin/log.c
index 3d2ce8fa3d..a9195bcb34 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -167,6 +167,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
 		OPT__QUIET(&quiet, N_("suppress diff output")),
 		OPT_BOOL(0, "source", &source, N_("show source")),
 		OPT_BOOL(0, "use-mailmap", &mailmap, N_("Use mail map file")),
+		OPT_NEGBIT(0, "no-use-mailmap", &mailmap, N_("Do not use mail map file"), 1),
 		OPT_STRING_LIST(0, "decorate-refs", &decorate_refs_include,
 				N_("pattern"), N_("only decorate refs that match <pattern>")),
 		OPT_STRING_LIST(0, "decorate-refs-exclude", &decorate_refs_exclude,
-- 
2.17.1
Beat Bolli· Jul 11, 2019, 18:24 UTC · re: Ariadne Conill · lore

Re: [PATCH v2 2/3] log: add --no-use-mailmap option to complement --use-mailmap option

On 11.07.19 19:26, Ariadne Conill wrote:
Show 42 quoted lines
> When mailmap is enabled by default or by configuration, it may be
> useful to override the default behaviour.  Previously, it was
> possible to enable the mailmap feature when it was disabled by
> default or in the configuration, but it was not possible to disable
> the mailmap feature when it was enabled by default or by the
> configuration.
> 
> The --no-use-mailmap option equalizes this by allowing the user to
> explicitly enable or disable the mailmap feature according to their
> requirements.
> 
> Signed-off-by: Ariadne Conill <ariadne@dereferenced.org>
> ---
>  Documentation/git-log.txt | 5 +++++
>  builtin/log.c             | 1 +
>  2 files changed, 6 insertions(+)
> 
> diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
> index b02e922dc3..50bc8f7da2 100644
> --- a/Documentation/git-log.txt
> +++ b/Documentation/git-log.txt
> @@ -54,6 +54,11 @@ OPTIONS
>  	addresses to canonical real names and email addresses. See
>  	linkgit:git-shortlog[1].
>  
> +--no-use-mailmap::
> +	Do not use the mailmap file to map author and commiter names
> +	and email addresses to canonical real names and email addresses.
> +	See linkgit:git-shortlog[1].
> +
>  --full-diff::
>  	Without this flag, `git log -p <path>...` shows commits that
>  	touch the specified paths, and diffs about the same specified
> diff --git a/builtin/log.c b/builtin/log.c
> index 3d2ce8fa3d..a9195bcb34 100644
> --- a/builtin/log.c
> +++ b/builtin/log.c
> @@ -167,6 +167,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
>  		OPT__QUIET(&quiet, N_("suppress diff output")),
>  		OPT_BOOL(0, "source", &source, N_("show source")),
>  		OPT_BOOL(0, "use-mailmap", &mailmap, N_("Use mail map file")),
> +		OPT_NEGBIT(0, "no-use-mailmap", &mailmap, N_("Do not use mail map file"), 1),

This works already. OPT_BOOL automatically handles the negation. You just have to add "[no-]" to the documentation of --use-mailmap.

>  		OPT_STRING_LIST(0, "decorate-refs", &decorate_refs_include,
>  				N_("pattern"), N_("only decorate refs that match <pattern>")),
>  		OPT_STRING_LIST(0, "decorate-refs-exclude", &decorate_refs_exclude,
> 

Cheers, Beat

Ariadne Conill· Jul 11, 2019, 18:25 UTC · re: Beat Bolli · lore

Re: [PATCH v2 2/3] log: add --no-use-mailmap option to complement --use-mailmap option

Hello,
On Thu, Jul 11, 2019 at 1:24 PM Beat Bolli <dev+git@drbeat.li> wrote:
Show 47 quoted lines
>
> On 11.07.19 19:26, Ariadne Conill wrote:
> > When mailmap is enabled by default or by configuration, it may be
> > useful to override the default behaviour.  Previously, it was
> > possible to enable the mailmap feature when it was disabled by
> > default or in the configuration, but it was not possible to disable
> > the mailmap feature when it was enabled by default or by the
> > configuration.
> >
> > The --no-use-mailmap option equalizes this by allowing the user to
> > explicitly enable or disable the mailmap feature according to their
> > requirements.
> >
> > Signed-off-by: Ariadne Conill <ariadne@dereferenced.org>
> > ---
> >  Documentation/git-log.txt | 5 +++++
> >  builtin/log.c             | 1 +
> >  2 files changed, 6 insertions(+)
> >
> > diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
> > index b02e922dc3..50bc8f7da2 100644
> > --- a/Documentation/git-log.txt
> > +++ b/Documentation/git-log.txt
> > @@ -54,6 +54,11 @@ OPTIONS
> >       addresses to canonical real names and email addresses. See
> >       linkgit:git-shortlog[1].
> >
> > +--no-use-mailmap::
> > +     Do not use the mailmap file to map author and commiter names
> > +     and email addresses to canonical real names and email addresses.
> > +     See linkgit:git-shortlog[1].
> > +
> >  --full-diff::
> >       Without this flag, `git log -p <path>...` shows commits that
> >       touch the specified paths, and diffs about the same specified
> > diff --git a/builtin/log.c b/builtin/log.c
> > index 3d2ce8fa3d..a9195bcb34 100644
> > --- a/builtin/log.c
> > +++ b/builtin/log.c
> > @@ -167,6 +167,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
> >               OPT__QUIET(&quiet, N_("suppress diff output")),
> >               OPT_BOOL(0, "source", &source, N_("show source")),
> >               OPT_BOOL(0, "use-mailmap", &mailmap, N_("Use mail map file")),
> > +             OPT_NEGBIT(0, "no-use-mailmap", &mailmap, N_("Do not use mail map file"), 1),
>
> This works already. OPT_BOOL automatically handles the negation. You
> just have to add "[no-]" to the documentation of --use-mailmap.

Aha. I was expecting it to behave like typical getopt_long() parsing, where you have to handle this yourself. No problem. I'll clean that up! Thanks for the tip.

Ariadne
Beat Bolli· Jul 11, 2019, 18:27 UTC · re: Ariadne Conill · lore

Re: [PATCH v2 2/3] log: add --no-use-mailmap option to complement --use-mailmap option

On 11.07.19 20:25, Ariadne Conill wrote:
Show 56 quoted lines
> Hello,
> 
> On Thu, Jul 11, 2019 at 1:24 PM Beat Bolli <dev+git@drbeat.li> wrote:
>>
>> On 11.07.19 19:26, Ariadne Conill wrote:
>>> When mailmap is enabled by default or by configuration, it may be
>>> useful to override the default behaviour.  Previously, it was
>>> possible to enable the mailmap feature when it was disabled by
>>> default or in the configuration, but it was not possible to disable
>>> the mailmap feature when it was enabled by default or by the
>>> configuration.
>>>
>>> The --no-use-mailmap option equalizes this by allowing the user to
>>> explicitly enable or disable the mailmap feature according to their
>>> requirements.
>>>
>>> Signed-off-by: Ariadne Conill <ariadne@dereferenced.org>
>>> ---
>>>  Documentation/git-log.txt | 5 +++++
>>>  builtin/log.c             | 1 +
>>>  2 files changed, 6 insertions(+)
>>>
>>> diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
>>> index b02e922dc3..50bc8f7da2 100644
>>> --- a/Documentation/git-log.txt
>>> +++ b/Documentation/git-log.txt
>>> @@ -54,6 +54,11 @@ OPTIONS
>>>       addresses to canonical real names and email addresses. See
>>>       linkgit:git-shortlog[1].
>>>
>>> +--no-use-mailmap::
>>> +     Do not use the mailmap file to map author and commiter names
>>> +     and email addresses to canonical real names and email addresses.
>>> +     See linkgit:git-shortlog[1].
>>> +
>>>  --full-diff::
>>>       Without this flag, `git log -p <path>...` shows commits that
>>>       touch the specified paths, and diffs about the same specified
>>> diff --git a/builtin/log.c b/builtin/log.c
>>> index 3d2ce8fa3d..a9195bcb34 100644
>>> --- a/builtin/log.c
>>> +++ b/builtin/log.c
>>> @@ -167,6 +167,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
>>>               OPT__QUIET(&quiet, N_("suppress diff output")),
>>>               OPT_BOOL(0, "source", &source, N_("show source")),
>>>               OPT_BOOL(0, "use-mailmap", &mailmap, N_("Use mail map file")),
>>> +             OPT_NEGBIT(0, "no-use-mailmap", &mailmap, N_("Do not use mail map file"), 1),
>>
>> This works already. OPT_BOOL automatically handles the negation. You
>> just have to add "[no-]" to the documentation of --use-mailmap.
> 
> Aha.  I was expecting it to behave like typical getopt_long() parsing,
> where you have to handle this yourself.  No problem.  I'll clean that
> up!  Thanks for the tip.
> 
> Ariadne
You're welcome!
Beat
Ariadne Conill· Jul 11, 2019, 17:26 UTC · re: Ariadne Conill · lore

[PATCH v2 3/3] tests: add test for git log --no-use-mailmap

In order to prove that the --no-use-mailmap option works as expected, we add a test for it which runs with -Dlog.mailmap=true to ensure that the option successfully negates the configured default.

Signed-off-by: Ariadne Conill <ariadne@dereferenced.org>
---
 t/t4203-mailmap.sh | 8 ++++++++
 1 file changed, 8 insertions(+)
Show changes to t/t4203-mailmap.sh +8 −0
diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh
index 43b1522ea2..23a8947bce 100755
--- a/t/t4203-mailmap.sh
+++ b/t/t4203-mailmap.sh
@@ -465,6 +465,14 @@ test_expect_success 'Only grep replaced author with --use-mailmap' '
 	git log --use-mailmap --author "<cto@coompany.xx>" >actual &&
 	test_must_be_empty actual
 '
+cat >expect <<\EOF
+Author: santa <me@company.xx>
+EOF
+
+test_expect_success 'Grep author with --no-use-mailmap + log.mailmap=True' '
+	git -c log.mailmap=True log --no-use-mailmap --author santa | grep Author >actual &&
+	test_cmp expect actual
+'
 
 # git blame
 cat >expect <<\EOF
-- 
2.17.1
Beat Bolli· Jul 11, 2019, 17:32 UTC · re: Ariadne Conill · lore

Re: [PATCH v2 3/3] tests: add test for git log --no-use-mailmap

On 11.07.19 19:26, Ariadne Conill wrote:
> In order to prove that the --no-use-mailmap option works as expected,
> we add a test for it which runs with -Dlog.mailmap=true to ensure that
s/-D/-c /
This ain't Java :-)
Show 27 quoted lines
> the option successfully negates the configured default.
> 
> Signed-off-by: Ariadne Conill <ariadne@dereferenced.org>
> ---
>  t/t4203-mailmap.sh | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh
> index 43b1522ea2..23a8947bce 100755
> --- a/t/t4203-mailmap.sh
> +++ b/t/t4203-mailmap.sh
> @@ -465,6 +465,14 @@ test_expect_success 'Only grep replaced author with --use-mailmap' '
>  	git log --use-mailmap --author "<cto@coompany.xx>" >actual &&
>  	test_must_be_empty actual
>  '
> +cat >expect <<\EOF
> +Author: santa <me@company.xx>
> +EOF
> +
> +test_expect_success 'Grep author with --no-use-mailmap + log.mailmap=True' '
> +	git -c log.mailmap=True log --no-use-mailmap --author santa | grep Author >actual &&
> +	test_cmp expect actual
> +'
>  
>  # git blame
>  cat >expect <<\EOF
> 

Cheers, Beat

Ariadne Conill· Jul 11, 2019, 17:38 UTC · re: Beat Bolli · lore

Re: [PATCH v2 3/3] tests: add test for git log --no-use-mailmap

Hello,
On Thu, Jul 11, 2019 at 12:32 PM Beat Bolli <dev+git@drbeat.li> wrote:
Show 8 quoted lines
>
> On 11.07.19 19:26, Ariadne Conill wrote:
> > In order to prove that the --no-use-mailmap option works as expected,
> > we add a test for it which runs with -Dlog.mailmap=true to ensure that
>
> s/-D/-c /
>
> This ain't Java :-)

Indeed, it is not. I thought I caught that when proofreading the commit message. Will resolve in v3.

Thanks for the review!
Ariadne

← back to recent threads