diff --git a/.mailmap b/.mailmap new file mode 100644 index 000000000..85f8e939d --- /dev/null +++ b/.mailmap @@ -0,0 +1,3 @@ +Jonas Fonseca +Jonas Fonseca +Jonas Fonseca diff --git a/NEWS.adoc b/NEWS.adoc index ad98b06c3..4a3c6ddc9 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -12,6 +12,8 @@ Incompatibilities: Improvements: - Add support for key combos. (GH #67) + - Use .mailmap to show canonical name and email addresses, off by default. + Add `set mailmap = yes` to `~/.tigrc` to enable. (GH #411) - See `contrib/vim.tigrc` for Vim-like keybindings. (GH #273, #351) - Add GitHub inspired file finder to search for and open any file. (GH #342) - Add `search` keymap for navigation file finder search results. diff --git a/doc/tigrc.5.adoc b/doc/tigrc.5.adoc index dccf72f5c..f2cf35d02 100644 --- a/doc/tigrc.5.adoc +++ b/doc/tigrc.5.adoc @@ -270,6 +270,11 @@ The following variables can be set: Ignore case in searches. By default, the search is case sensitive. +'mailmap' (bool):: + + Read canonical name and email addresses for authors and committers from + `.mailmap`. Off by default. See `git-shortlog(1)`. + 'wrap-lines' (bool):: Wrap long lines. By default, lines are not wrapped. diff --git a/include/tig/git.h b/include/tig/git.h index bbb639c44..329490df4 100644 --- a/include/tig/git.h +++ b/include/tig/git.h @@ -52,10 +52,6 @@ (commit_order_arg), (mainargs), (diffargs), (revargs), "--date=raw", "--parents", \ "--no-color", (pretty_arg), "--", (fileargs), NULL -#define GIT_MAIN_LOG_CUSTOM(encoding_arg, commit_order_arg, mainargs, diffargs, revargs, fileargs) \ - GIT_MAIN_LOG(encoding_arg, commit_order_arg, mainargs, diffargs, revargs, fileargs, \ - "--pretty=format:commit %m %H %P%x00%an <%ae> %ad%x00%s") - #define GIT_MAIN_LOG_RAW(encoding_arg, commit_order_arg, mainargs, diffargs, revargs, fileargs) \ GIT_MAIN_LOG(encoding_arg, commit_order_arg, mainargs, diffargs, revargs, fileargs, \ "--pretty=raw") diff --git a/include/tig/options.h b/include/tig/options.h index d6249b840..c3becab9f 100644 --- a/include/tig/options.h +++ b/include/tig/options.h @@ -48,6 +48,7 @@ typedef struct view_column *view_settings; _(line_graphics, enum graphic, VIEW_NO_FLAGS) \ _(log_options, const char **, VIEW_LOG_LIKE) \ _(log_view, view_settings, VIEW_NO_FLAGS) \ + _(mailmap, bool, VIEW_DIFF_LIKE | VIEW_LOG_LIKE) \ _(main_options, const char **, VIEW_LOG_LIKE) \ _(main_view, view_settings, VIEW_NO_FLAGS) \ _(mouse, bool, VIEW_NO_FLAGS) \ @@ -176,6 +177,8 @@ void update_options_from_argv(const char *argv[]); const char *ignore_space_arg(); const char *commit_order_arg(); const char *commit_order_arg_with_graph(enum graph_display graph_display); +const char *log_custom_pretty_arg(); +const char *use_mailmap_arg(); const char *diff_context_arg(); const char *show_notes_arg(); diff --git a/src/diff.c b/src/diff.c index 8cad58fc7..9c693fa86 100644 --- a/src/diff.c +++ b/src/diff.c @@ -26,7 +26,7 @@ diff_open(struct view *view, enum open_flags flags) { const char *diff_argv[] = { "git", "show", encoding_arg, "--pretty=fuller", "--root", - "--patch-with-stat", + "--patch-with-stat", use_mailmap_arg(), show_notes_arg(), diff_context_arg(), ignore_space_arg(), "%(diffargs)", "%(cmdlineargs)", "--no-color", "%(commit)", "--", "%(fileargs)", NULL diff --git a/src/main.c b/src/main.c index 305f4e94a..2a72bc6bd 100644 --- a/src/main.c +++ b/src/main.c @@ -239,8 +239,9 @@ main_open(struct view *view, enum open_flags flags) struct view_column *commit_title_column = get_view_column(view, VIEW_COLUMN_COMMIT_TITLE); enum graph_display graph_display = main_with_graph(view, commit_title_column, flags); const char *pretty_custom_argv[] = { - GIT_MAIN_LOG_CUSTOM(encoding_arg, commit_order_arg_with_graph(graph_display), - "%(mainargs)", "%(cmdlineargs)", "%(revargs)", "%(fileargs)") + GIT_MAIN_LOG(encoding_arg, commit_order_arg_with_graph(graph_display), + "%(mainargs)", "%(cmdlineargs)", "%(revargs)", "%(fileargs)", + log_custom_pretty_arg()) }; const char *pretty_raw_argv[] = { GIT_MAIN_LOG_RAW(encoding_arg, commit_order_arg_with_graph(graph_display), diff --git a/src/options.c b/src/options.c index 90c992d4c..45afdcab7 100644 --- a/src/options.c +++ b/src/options.c @@ -144,6 +144,19 @@ diff_context_arg() return opt_diff_context_arg; } +const char * +use_mailmap_arg() +{ + return opt_mailmap ? "--use-mailmap" : ""; +} + +const char * +log_custom_pretty_arg(void) +{ + return opt_mailmap + ? "--pretty=format:commit %m %H %P%x00%aN <%aE> %ad%x00%s" + : "--pretty=format:commit %m %H %P%x00%an <%ae> %ad%x00%s"; +} #define ENUM_ARG(enum_name, arg_string) ENUM_MAP_ENTRY(arg_string, enum_name) diff --git a/src/refs.c b/src/refs.c index 9f4f99c89..aa23122a2 100644 --- a/src/refs.c +++ b/src/refs.c @@ -64,9 +64,10 @@ refs_request(struct view *view, enum request request, struct line *line) { const struct ref *ref = reference->ref; const char *all_references_argv[] = { - GIT_MAIN_LOG_CUSTOM(encoding_arg, commit_order_arg(), + GIT_MAIN_LOG(encoding_arg, commit_order_arg(), "%(mainargs)", "", - refs_is_all(reference) ? "--all" : ref->name, "") + refs_is_all(reference) ? "--all" : ref->name, "", + log_custom_pretty_arg()) }; if (!argv_format(main_view.env, &main_view.argv, all_references_argv, FALSE, FALSE)) @@ -142,7 +143,8 @@ refs_open(struct view *view, enum open_flags flags) { const char *refs_log[] = { "git", "log", encoding_arg, "--no-color", "--date=raw", - "--pretty=format:%H%x00%an <%ae> %ad%x00%s", + opt_mailmap ? "--pretty=format:%H%x00%aN <%aE> %ad%x00%s" + : "--pretty=format:%H%x00%an <%ae> %ad%x00%s", "--all", "--simplify-by-decoration", NULL }; diff --git a/test/main/mailmap-test b/test/main/mailmap-test new file mode 100755 index 000000000..d25cf2bef --- /dev/null +++ b/test/main/mailmap-test @@ -0,0 +1,65 @@ +#!/bin/sh + +. libtest.sh +. libgit.sh + +export LINES=15 + +git_clone 'repo-one' + +cat >"$work_dir/.mailmap" < A. U. Thor " +Ti-Poil René Lévesque " +龙 作者 " +Stargazer Jørgen Thygesen Brahe " +Full Throttle Max Power " +¯\_(ツ)_/¯ Committer +EOF + +tigrc < +AuthorDate: Wed Apr 7 05:37:40 2010 +0000 +Commit: ¯\_(ツ)_/¯ +CommitDate: Wed Apr 7 05:37:40 2010 +0000 + + Commit 10 E + + + + + +[diff] 5cb3412a5e06e506840495b91acc885037a48b72 - line 1 of 8 100% +EOF diff --git a/tigrc b/tigrc index bb098f464..79e667a9b 100644 --- a/tigrc +++ b/tigrc @@ -95,6 +95,7 @@ set show-notes = yes # When non-bool passed as `--show-notes=...` (diff) #set blame-options = -C -C -C # User-defined options for `tig blame` (git-blame) #set log-options = --pretty=raw # User-defined options for `tig log` (git-log) #set main-options = -n 1000 # User-defined options for `tig` (git-log) +#set mailmap = yes # Use .mailmap to show canonical name and email address # Misc set refresh-mode = auto # Enum: manual, auto, after-command, periodic