mailmap: default mailmap.blob in bare repositories

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>

Jeff King committed Dec 13, 2012 at 08:04 UTC 8c473cecfd8835c2bdf34b323e1b2de620099c04
3 files changed +35 -3
Documentation/config.txt
+5 -3
@@ -1519,9 +1519,11 @@ mailmap.file::
1519
1520 mailmap.blob::
1521 Like `mailmap.file`, but consider the value as a reference to a
1522 - blob in the repository (e.g., `HEAD:.mailmap`). If both
1523 - `mailmap.file` and `mailmap.blob` are given, both are parsed,
1524 - with entries from `mailmap.file` taking precedence.
1522 + blob in the repository. If both `mailmap.file` and
1523 + `mailmap.blob` are given, both are parsed, with entries from
1524 + `mailmap.file` taking precedence. In a bare repository, this
1525 + defaults to `HEAD:.mailmap`. In a non-bare repository, it
1526 + defaults to empty.
1527
1528 man.viewer::
1529 Specify the programs that may be used to display help in the
mailmap.c
+5
@@ -233,7 +233,12 @@ static int read_mailmap_blob(struct string_list *map,
233 int read_mailmap(struct string_list *map, char **repo_abbrev)
234 {
235 int err = 0;
236 +
237 map->strdup_strings = 1;
238 +
239 + if (!git_mailmap_blob && is_bare_repository())
240 + git_mailmap_blob = "HEAD:.mailmap";
241 +
242 err |= read_mailmap_file(map, ".mailmap", repo_abbrev);
243 err |= read_mailmap_blob(map, git_mailmap_blob, repo_abbrev);
244 err |= read_mailmap_file(map, git_mailmap_file, repo_abbrev);
t/t4203-mailmap.sh
+25
@@ -218,6 +218,31 @@ test_expect_success 'mailmap.blob can be missing' '
218 test_cmp expect actual
219 '
220
221 +test_expect_success 'mailmap.blob defaults to off in non-bare repo' '
222 + git init non-bare &&
223 + (
224 + cd non-bare &&
225 + test_commit one .mailmap "Fake Name <author@example.com>" &&
226 + echo " 1 Fake Name" >expect &&
227 + git shortlog -ns HEAD >actual &&
228 + test_cmp expect actual &&
229 + rm .mailmap &&
230 + echo " 1 A U Thor" >expect &&
231 + git shortlog -ns HEAD >actual &&
232 + test_cmp expect actual
233 + )
234 +'
235 +
236 +test_expect_success 'mailmap.blob defaults to HEAD:.mailmap in bare repo' '
237 + git clone --bare non-bare bare &&
238 + (
239 + cd bare &&
240 + echo " 1 Fake Name" >expect &&
241 + git shortlog -ns HEAD >actual &&
242 + test_cmp expect actual
243 + )
244 +'
245 +
246 test_expect_success 'cleanup after mailmap.blob tests' '
247 rm -f .mailmap
248 '