mailmap: default mailmap.blob in bare repositories
authorJeff King <peff@peff.net>
Thu, 13 Dec 2012 13:04:47 +0000 (08:04 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 13 Dec 2012 18:22:13 +0000 (10:22 -0800)
The motivation for mailmap.blob is to let users of bare
repositories use the mailmap feature, as they would not have
a checkout containing the .mailmap file. We can make it even
easier for them by just looking in HEAD:.mailmap by default.

We can't know for sure that this is where they would keep a
mailmap, of course, but it is the best guess (and it matches
the non-bare behavior, which reads from HEAD:.mailmap in the
working tree). If it's missing, git will silently ignore the
setting.

We do not do the same magic in the non-bare case, because:

1. In the common case, HEAD:.mailmap will be the same as
the .mailmap in the working tree, which is a no-op.

2. In the uncommon case, the user has modified .mailmap
but not yet committed it, and would expect the working
tree version to take precedence.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config.txt
mailmap.c
t/t4203-mailmap.sh
index 376007797c3a3d977991b50814eb6c29a03d14e9..1a3c554dbfbb35901855f3b8e6410c3d4154a262 100644 (file)
@@ -1519,9 +1519,11 @@ mailmap.file::
 
 mailmap.blob::
        Like `mailmap.file`, but consider the value as a reference to a
-       blob in the repository (e.g., `HEAD:.mailmap`). If both
-       `mailmap.file` and `mailmap.blob` are given, both are parsed,
-       with entries from `mailmap.file` taking precedence.
+       blob in the repository. If both `mailmap.file` and
+       `mailmap.blob` are given, both are parsed, with entries from
+       `mailmap.file` taking precedence. In a bare repository, this
+       defaults to `HEAD:.mailmap`. In a non-bare repository, it
+       defaults to empty.
 
 man.viewer::
        Specify the programs that may be used to display help in the
index 5ffe48a60478ada46b4ab1fac1b6dd7abe3fc918..b16542febec14ed86fd7ef21ba19899d08c95a64 100644 (file)
--- a/mailmap.c
+++ b/mailmap.c
@@ -233,7 +233,12 @@ static int read_mailmap_blob(struct string_list *map,
 int read_mailmap(struct string_list *map, char **repo_abbrev)
 {
        int err = 0;
+
        map->strdup_strings = 1;
+
+       if (!git_mailmap_blob && is_bare_repository())
+               git_mailmap_blob = "HEAD:.mailmap";
+
        err |= read_mailmap_file(map, ".mailmap", repo_abbrev);
        err |= read_mailmap_blob(map, git_mailmap_blob, repo_abbrev);
        err |= read_mailmap_file(map, git_mailmap_file, repo_abbrev);
index e7ea40ceb6c68a69fefae30ef5cee09acd02a6b2..aae30d97b1a0b95f9cae5c2659f77cf2cb9c3947 100755 (executable)
@@ -218,6 +218,31 @@ test_expect_success 'mailmap.blob can be missing' '
        test_cmp expect actual
 '
 
+test_expect_success 'mailmap.blob defaults to off in non-bare repo' '
+       git init non-bare &&
+       (
+               cd non-bare &&
+               test_commit one .mailmap "Fake Name <author@example.com>" &&
+               echo "     1    Fake Name" >expect &&
+               git shortlog -ns HEAD >actual &&
+               test_cmp expect actual &&
+               rm .mailmap &&
+               echo "     1    A U Thor" >expect &&
+               git shortlog -ns HEAD >actual &&
+               test_cmp expect actual
+       )
+'
+
+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 &&
+               test_cmp expect actual
+       )
+'
+
 test_expect_success 'cleanup after mailmap.blob tests' '
        rm -f .mailmap
 '