Skip to content

Commit

Permalink
Add .mailmap support
Browse files Browse the repository at this point in the history
It's off by default, enable by adding `set mailmap = yes` to tigrc.

Fixes jonas#411
  • Loading branch information
jonas committed Jun 7, 2015
1 parent 4024a73 commit b7f06a8
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Jonas Fonseca <[email protected]> <[email protected]>
Jonas Fonseca <[email protected]> <[email protected]>
Jonas Fonseca <[email protected]> <[email protected]>
2 changes: 2 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions doc/tigrc.5.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions include/tig/git.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions include/tig/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
13 changes: 13 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 5 additions & 3 deletions src/refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
};

Expand Down
65 changes: 65 additions & 0 deletions test/main/mailmap-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/sh

. libtest.sh
. libgit.sh

export LINES=15

git_clone 'repo-one'

cat >"$work_dir/.mailmap" <<EOF
Thoreau <[email protected]> A. U. Thor <[email protected]>"
Ti-Poil <[email protected]> René Lévesque <[email protected]>"
龙 <[email protected]> 作者 <[email protected]>"
Stargazer <[email protected]> Jørgen Thygesen Brahe <[email protected]>"
Full Throttle <[email protected]> Max Power <[email protected]>"
¯\_(ツ)_/¯ <[email protected]> Committer <[email protected]>
EOF

tigrc <<EOF
set mailmap = yes
# set diff-options = --use-mailmap
# set main-options = --use-mailmap
EOF

steps '
:save-display mailmapped.screen
:view-diff
:save-display mailmapped-diff.screen
'

test_tig

assert_equals 'mailmapped.screen' <<EOF
2010-04-07 05:37 Full Throttle o [master] {origin/master} {origin/HEAD} Commit 1
2010-03-29 17:15 Stargazer o Commit 10 D
2010-03-21 04:53 龙 o Commit 10 C
2010-03-12 16:31 Ti-Poil o Commit 10 B
2010-03-04 04:09 Thoreau o Commit 10 A
2010-02-23 15:46 Full Throttle o Commit 9 E
2010-02-15 03:24 Stargazer o Commit 9 D
2010-02-06 15:02 龙 o Commit 9 C
2010-01-29 02:40 Ti-Poil o Commit 9 B
2010-01-20 14:18 Thoreau o Commit 9 A
2010-01-12 01:56 Full Throttle o Commit 8 E
2010-01-03 13:33 Stargazer o Commit 8 D
2009-12-26 01:11 龙 o Commit 8 C
[main] 5cb3412a5e06e506840495b91acc885037a48b72 - commit 1 of 50 26%
EOF

assert_equals 'mailmapped-diff.screen' <<EOF
commit 5cb3412a5e06e506840495b91acc885037a48b72
Refs: [master], {origin/master}, {origin/HEAD}
Author: Full Throttle <[email protected]>
AuthorDate: Wed Apr 7 05:37:40 2010 +0000
Commit: ¯\_(ツ)_/¯ <[email protected]>
CommitDate: Wed Apr 7 05:37:40 2010 +0000
Commit 10 E
[diff] 5cb3412a5e06e506840495b91acc885037a48b72 - line 1 of 8 100%
EOF
1 change: 1 addition & 0 deletions tigrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b7f06a8

Please sign in to comment.