Skip to content

Commit e6bb5f7

Browse files
apelissegitster
authored andcommitted
log: add log.mailmap configuration option
Teach "log.mailmap" configuration variable to turn "--use-mailmap" option on to "git log", "git show" and "git whatchanged". The "--no-use-mailmap" option from the command line can countermand the setting. Signed-off-by: Antoine Pelisse <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d72fbe8 commit e6bb5f7

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

Documentation/config.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,10 @@ log.showroot::
15091509
Tools like linkgit:git-log[1] or linkgit:git-whatchanged[1], which
15101510
normally hide the root commit will now show it. True by default.
15111511

1512+
log.mailmap::
1513+
If true, makes linkgit:git-log[1], linkgit:git-show[1], and
1514+
linkgit:git-whatchanged[1] assume `--use-mailmap`.
1515+
15121516
mailmap.file::
15131517
The location of an augmenting mailmap file. The default
15141518
mailmap, located in the root of the repository, is loaded

builtin/log.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static int default_abbrev_commit;
3131
static int default_show_root = 1;
3232
static int decoration_style;
3333
static int decoration_given;
34+
static int use_mailmap_config;
3435
static const char *fmt_patch_subject_prefix = "PATCH";
3536
static const char *fmt_pretty;
3637

@@ -106,6 +107,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
106107
OPT_END()
107108
};
108109

110+
mailmap = use_mailmap_config;
109111
argc = parse_options(argc, argv, prefix,
110112
builtin_log_options, builtin_log_usage,
111113
PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN |
@@ -358,6 +360,11 @@ static int git_log_config(const char *var, const char *value, void *cb)
358360
}
359361
if (!prefixcmp(var, "color.decorate."))
360362
return parse_decorate_color_config(var, 15, value);
363+
if (!strcmp(var, "log.mailmap")) {
364+
use_mailmap_config = git_config_bool(var, value);
365+
return 0;
366+
}
367+
361368
if (grep_config(var, value, cb) < 0)
362369
return -1;
363370
return git_diff_ui_config(var, value, cb);

t/t4203-mailmap.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,21 @@ test_expect_success 'Log output with --use-mailmap' '
254254
test_cmp expect actual
255255
'
256256

257+
cat >expect <<\EOF
258+
Author: CTO <[email protected]>
259+
Author: Santa Claus <[email protected]>
260+
Author: Santa Claus <[email protected]>
261+
Author: Other Author <[email protected]>
262+
Author: Other Author <[email protected]>
263+
Author: Some Dude <[email protected]>
264+
Author: A U Thor <[email protected]>
265+
EOF
266+
267+
test_expect_success 'Log output with log.mailmap' '
268+
git -c log.mailmap=True log | grep Author >actual &&
269+
test_cmp expect actual
270+
'
271+
257272
cat >expect <<\EOF
258273
Author: Santa Claus <[email protected]>
259274
Author: Santa Claus <[email protected]>
@@ -263,6 +278,15 @@ test_expect_success 'Grep author with --use-mailmap' '
263278
git log --use-mailmap --author Santa | grep Author >actual &&
264279
test_cmp expect actual
265280
'
281+
cat >expect <<\EOF
282+
Author: Santa Claus <[email protected]>
283+
Author: Santa Claus <[email protected]>
284+
EOF
285+
286+
test_expect_success 'Grep author with log.mailmap' '
287+
git -c log.mailmap=True log --author Santa | grep Author >actual &&
288+
test_cmp expect actual
289+
'
266290

267291
>expect
268292

0 commit comments

Comments
 (0)