blame: Add option to show author email instead of name
Add a new option -e (or --show-email) to git-blame that will display the author's email instead of name on each line. This option works for both git-blame and git-annotate. Signed-off-by: Kevin Ballard <kevin@sb.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kevin Ballard committed
Oct 15, 2010 at 23:57 UTC
1b8cdce94f4fff2408f8ed26fe4fc2f187a46794
4 files changed
+38
-13
Documentation/git-blame.txt
+5
-1
@@ -8,7 +8,7 @@ git-blame - Show what revision and author last modified each line of a file
8
SYNOPSIS
9
--------
10
[verse]
11
-'git blame' [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-p] [-w] [--incremental] [-L n,m]
11
+'git blame' [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-e] [-p] [-w] [--incremental] [-L n,m]
12
[-S <revs-file>] [-M] [-C] [-C] [-C] [--since=<date>]
13
[<rev> | --contents <file> | --reverse <rev>] [--] <file>
14
@@ -65,6 +65,10 @@ include::blame-options.txt[]
65
-s::
66
Suppress the author name and timestamp from the output.
67
68
+-e::
69
+--show-email::
70
+ Show the author email instead of author name (Default: off).
71
+
72
-w::
73
Ignore whitespace when comparing the parent's version and
74
the child's to find where the lines came from.
builtin/blame.c
+22
-6
@@ -1606,6 +1606,7 @@ static const char *format_time(unsigned long time, const char *tz_str,
1606
#define OUTPUT_SHOW_NUMBER 040
1607
#define OUTPUT_SHOW_SCORE 0100
1608
#define OUTPUT_NO_AUTHOR 0200
1609
+#define OUTPUT_SHOW_EMAIL 0400
1610
1611
static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent)
1612
{
@@ -1671,12 +1672,17 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
1672
}
1673
1674
printf("%.*s", length, hex);
1674
- if (opt & OUTPUT_ANNOTATE_COMPAT)
1675
- printf("\t(%10s\t%10s\t%d)", ci.author,
1675
+ if (opt & OUTPUT_ANNOTATE_COMPAT) {
1676
+ const char *name;
1677
+ if (opt & OUTPUT_SHOW_EMAIL)
1678
+ name = ci.author_mail;
1679
+ else
1680
+ name = ci.author;
1681
+ printf("\t(%10s\t%10s\t%d)", name,
1682
format_time(ci.author_time, ci.author_tz,
1683
show_raw_time),
1684
ent->lno + 1 + cnt);
1679
- else {
1685
+ } else {
1686
if (opt & OUTPUT_SHOW_SCORE)
1687
printf(" %*d %02d",
1688
max_score_digits, ent->score,
@@ -1689,9 +1695,15 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
1695
ent->s_lno + 1 + cnt);
1696
1697
if (!(opt & OUTPUT_NO_AUTHOR)) {
1692
- int pad = longest_author - utf8_strwidth(ci.author);
1698
+ const char *name;
1699
+ int pad;
1700
+ if (opt & OUTPUT_SHOW_EMAIL)
1701
+ name = ci.author_mail;
1702
+ else
1703
+ name = ci.author;
1704
+ pad = longest_author - utf8_strwidth(name);
1705
printf(" (%s%*s %10s",
1694
- ci.author, pad, "",
1706
+ name, pad, "",
1707
format_time(ci.author_time,
1708
ci.author_tz,
1709
show_raw_time));
@@ -1829,7 +1841,10 @@ static void find_alignment(struct scoreboard *sb, int *option)
1841
if (!(suspect->commit->object.flags & METAINFO_SHOWN)) {
1842
suspect->commit->object.flags |= METAINFO_SHOWN;
1843
get_commit_info(suspect->commit, &ci, 1);
1832
- num = utf8_strwidth(ci.author);
1844
+ if (*option & OUTPUT_SHOW_EMAIL)
1845
+ num = utf8_strwidth(ci.author_mail);
1846
+ else
1847
+ num = utf8_strwidth(ci.author);
1848
if (longest_author < num)
1849
longest_author = num;
1850
}
@@ -2278,6 +2293,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
2293
OPT_BIT('t', NULL, &output_option, "Show raw timestamp (Default: off)", OUTPUT_RAW_TIMESTAMP),
2294
OPT_BIT('l', NULL, &output_option, "Show long commit SHA1 (Default: off)", OUTPUT_LONG_OBJECT_NAME),
2295
OPT_BIT('s', NULL, &output_option, "Suppress author name and timestamp (Default: off)", OUTPUT_NO_AUTHOR),
2296
+ OPT_BIT('e', "show-email", &output_option, "Show author email instead of name (Default: off)", OUTPUT_SHOW_EMAIL),
2297
OPT_BIT('w', NULL, &xdl_opts, "Ignore whitespace differences", XDF_IGNORE_WHITESPACE),
2298
OPT_STRING('S', NULL, &revs_file, "file", "Use revisions from <file> instead of calling git-rev-list"),
2299
OPT_STRING(0, "contents", &contents_from, "file", "Use <file>'s contents as the final image"),
t/annotate-tests.sh
+6
-6
@@ -39,7 +39,7 @@ test_expect_success \
39
'echo "1A quick brown fox jumps over the" >file &&
40
echo "lazy dog" >>file &&
41
git add file
42
- GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
42
+ GIT_AUTHOR_NAME="A" GIT_AUTHOR_EMAIL="A@test.git" git commit -a -m "Initial."'
43
44
test_expect_success \
45
'check all lines blamed on A' \
@@ -49,7 +49,7 @@ test_expect_success \
49
'Setup new lines blamed on B' \
50
'echo "2A quick brown fox jumps over the" >>file &&
51
echo "lazy dog" >> file &&
52
- GIT_AUTHOR_NAME="B" git commit -a -m "Second."'
52
+ GIT_AUTHOR_NAME="B" GIT_AUTHOR_EMAIL="B@test.git" git commit -a -m "Second."'
53
54
test_expect_success \
55
'Two lines blamed on A, two on B' \
@@ -60,7 +60,7 @@ test_expect_success \
60
'git checkout -b branch1 master &&
61
echo "3A slow green fox jumps into the" >> file &&
62
echo "well." >> file &&
63
- GIT_AUTHOR_NAME="B1" git commit -a -m "Branch1-1"'
63
+ GIT_AUTHOR_NAME="B1" GIT_AUTHOR_EMAIL="B1@test.git" git commit -a -m "Branch1-1"'
64
65
test_expect_success \
66
'Two lines blamed on A, two on B, two on B1' \
@@ -71,7 +71,7 @@ test_expect_success \
71
'git checkout -b branch2 master &&
72
sed -e "s/2A quick brown/4A quick brown lazy dog/" < file > file.new &&
73
mv file.new file &&
74
- GIT_AUTHOR_NAME="B2" git commit -a -m "Branch2-1"'
74
+ GIT_AUTHOR_NAME="B2" GIT_AUTHOR_EMAIL="B2@test.git" git commit -a -m "Branch2-1"'
75
76
test_expect_success \
77
'Two lines blamed on A, one on B, one on B2' \
@@ -105,7 +105,7 @@ test_expect_success \
105
test_expect_success \
106
'an incomplete line added' \
107
'echo "incomplete" | tr -d "\\012" >>file &&
108
- GIT_AUTHOR_NAME="C" git commit -a -m "Incomplete"'
108
+ GIT_AUTHOR_NAME="C" GIT_AUTHOR_EMAIL="C@test.git" git commit -a -m "Incomplete"'
109
110
test_expect_success \
111
'With incomplete lines.' \
@@ -119,7 +119,7 @@ test_expect_success \
119
echo
120
} | sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" > file &&
121
echo "incomplete" | tr -d "\\012" >>file &&
122
- GIT_AUTHOR_NAME="D" git commit -a -m "edit"'
122
+ GIT_AUTHOR_NAME="D" GIT_AUTHOR_EMAIL="D@test.git" git commit -a -m "edit"'
123
124
test_expect_success \
125
'some edit' \
t/t8002-blame.sh
+5
@@ -6,4 +6,9 @@ test_description='git blame'
6
PROG='git blame -c'
7
. "$TEST_DIRECTORY"/annotate-tests.sh
8
9
+PROG='git blame -c -e'
10
+test_expect_success 'Blame --show-email works' '
11
+ check_count "<A@test.git>" 1 "<B@test.git>" 1 "<B1@test.git>" 1 "<B2@test.git>" 1 "<author@example.com>" 1 "<C@test.git>" 1 "<D@test.git>" 1
12
+'
13
+
14
test_done