Merge branch 'kb/blame-author-email'

* kb/blame-author-email:
  blame: Add option to show author email instead of name

Conflicts:
	t/annotate-tests.sh
maint
Junio C Hamano 2010-11-29 17:52:32 -08:00
commit 4ef927a995
4 changed files with 38 additions and 13 deletions

View File

@ -8,7 +8,7 @@ git-blame - Show what revision and author last modified each line of a file
SYNOPSIS SYNOPSIS
-------- --------
[verse] [verse]
'git blame' [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-p] [-w] [--incremental] [-L n,m] 'git blame' [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-e] [-p] [-w] [--incremental] [-L n,m]
[-S <revs-file>] [-M] [-C] [-C] [-C] [--since=<date>] [-S <revs-file>] [-M] [-C] [-C] [-C] [--since=<date>]
[<rev> | --contents <file> | --reverse <rev>] [--] <file> [<rev> | --contents <file> | --reverse <rev>] [--] <file>


@ -65,6 +65,10 @@ include::blame-options.txt[]
-s:: -s::
Suppress the author name and timestamp from the output. Suppress the author name and timestamp from the output.


-e::
--show-email::
Show the author email instead of author name (Default: off).

-w:: -w::
Ignore whitespace when comparing the parent's version and Ignore whitespace when comparing the parent's version and
the child's to find where the lines came from. the child's to find where the lines came from.

View File

@ -1617,6 +1617,7 @@ static const char *format_time(unsigned long time, const char *tz_str,
#define OUTPUT_SHOW_NUMBER 040 #define OUTPUT_SHOW_NUMBER 040
#define OUTPUT_SHOW_SCORE 0100 #define OUTPUT_SHOW_SCORE 0100
#define OUTPUT_NO_AUTHOR 0200 #define OUTPUT_NO_AUTHOR 0200
#define OUTPUT_SHOW_EMAIL 0400


static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent) static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent)
{ {
@ -1682,12 +1683,17 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
} }


printf("%.*s", length, hex); printf("%.*s", length, hex);
if (opt & OUTPUT_ANNOTATE_COMPAT) if (opt & OUTPUT_ANNOTATE_COMPAT) {
printf("\t(%10s\t%10s\t%d)", ci.author, const char *name;
if (opt & OUTPUT_SHOW_EMAIL)
name = ci.author_mail;
else
name = ci.author;
printf("\t(%10s\t%10s\t%d)", name,
format_time(ci.author_time, ci.author_tz, format_time(ci.author_time, ci.author_tz,
show_raw_time), show_raw_time),
ent->lno + 1 + cnt); ent->lno + 1 + cnt);
else { } else {
if (opt & OUTPUT_SHOW_SCORE) if (opt & OUTPUT_SHOW_SCORE)
printf(" %*d %02d", printf(" %*d %02d",
max_score_digits, ent->score, max_score_digits, ent->score,
@ -1700,9 +1706,15 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
ent->s_lno + 1 + cnt); ent->s_lno + 1 + cnt);


if (!(opt & OUTPUT_NO_AUTHOR)) { if (!(opt & OUTPUT_NO_AUTHOR)) {
int pad = longest_author - utf8_strwidth(ci.author); const char *name;
int pad;
if (opt & OUTPUT_SHOW_EMAIL)
name = ci.author_mail;
else
name = ci.author;
pad = longest_author - utf8_strwidth(name);
printf(" (%s%*s %10s", printf(" (%s%*s %10s",
ci.author, pad, "", name, pad, "",
format_time(ci.author_time, format_time(ci.author_time,
ci.author_tz, ci.author_tz,
show_raw_time)); show_raw_time));
@ -1840,7 +1852,10 @@ static void find_alignment(struct scoreboard *sb, int *option)
if (!(suspect->commit->object.flags & METAINFO_SHOWN)) { if (!(suspect->commit->object.flags & METAINFO_SHOWN)) {
suspect->commit->object.flags |= METAINFO_SHOWN; suspect->commit->object.flags |= METAINFO_SHOWN;
get_commit_info(suspect->commit, &ci, 1); get_commit_info(suspect->commit, &ci, 1);
num = utf8_strwidth(ci.author); if (*option & OUTPUT_SHOW_EMAIL)
num = utf8_strwidth(ci.author_mail);
else
num = utf8_strwidth(ci.author);
if (longest_author < num) if (longest_author < num)
longest_author = num; longest_author = num;
} }
@ -2289,6 +2304,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
OPT_BIT('t', NULL, &output_option, "Show raw timestamp (Default: off)", OUTPUT_RAW_TIMESTAMP), OPT_BIT('t', NULL, &output_option, "Show raw timestamp (Default: off)", OUTPUT_RAW_TIMESTAMP),
OPT_BIT('l', NULL, &output_option, "Show long commit SHA1 (Default: off)", OUTPUT_LONG_OBJECT_NAME), OPT_BIT('l', NULL, &output_option, "Show long commit SHA1 (Default: off)", OUTPUT_LONG_OBJECT_NAME),
OPT_BIT('s', NULL, &output_option, "Suppress author name and timestamp (Default: off)", OUTPUT_NO_AUTHOR), OPT_BIT('s', NULL, &output_option, "Suppress author name and timestamp (Default: off)", OUTPUT_NO_AUTHOR),
OPT_BIT('e', "show-email", &output_option, "Show author email instead of name (Default: off)", OUTPUT_SHOW_EMAIL),
OPT_BIT('w', NULL, &xdl_opts, "Ignore whitespace differences", XDF_IGNORE_WHITESPACE), OPT_BIT('w', NULL, &xdl_opts, "Ignore whitespace differences", XDF_IGNORE_WHITESPACE),
OPT_STRING('S', NULL, &revs_file, "file", "Use revisions from <file> instead of calling git-rev-list"), OPT_STRING('S', NULL, &revs_file, "file", "Use revisions from <file> instead of calling git-rev-list"),
OPT_STRING(0, "contents", &contents_from, "file", "Use <file>'s contents as the final image"), OPT_STRING(0, "contents", &contents_from, "file", "Use <file>'s contents as the final image"),

View File

@ -39,7 +39,7 @@ test_expect_success \
'echo "1A quick brown fox jumps over the" >file && 'echo "1A quick brown fox jumps over the" >file &&
echo "lazy dog" >>file && echo "lazy dog" >>file &&
git add file && git add file &&
GIT_AUTHOR_NAME="A" git commit -a -m "Initial."' GIT_AUTHOR_NAME="A" GIT_AUTHOR_EMAIL="A@test.git" git commit -a -m "Initial."'


test_expect_success \ test_expect_success \
'check all lines blamed on A' \ 'check all lines blamed on A' \
@ -49,7 +49,7 @@ test_expect_success \
'Setup new lines blamed on B' \ 'Setup new lines blamed on B' \
'echo "2A quick brown fox jumps over the" >>file && 'echo "2A quick brown fox jumps over the" >>file &&
echo "lazy dog" >> file && echo "lazy dog" >> file &&
GIT_AUTHOR_NAME="B" git commit -a -m "Second."' GIT_AUTHOR_NAME="B" GIT_AUTHOR_EMAIL="B@test.git" git commit -a -m "Second."'


test_expect_success \ test_expect_success \
'Two lines blamed on A, two on B' \ 'Two lines blamed on A, two on B' \
@ -60,7 +60,7 @@ test_expect_success \
'git checkout -b branch1 master && 'git checkout -b branch1 master &&
echo "3A slow green fox jumps into the" >> file && echo "3A slow green fox jumps into the" >> file &&
echo "well." >> file && echo "well." >> file &&
GIT_AUTHOR_NAME="B1" git commit -a -m "Branch1-1"' GIT_AUTHOR_NAME="B1" GIT_AUTHOR_EMAIL="B1@test.git" git commit -a -m "Branch1-1"'


test_expect_success \ test_expect_success \
'Two lines blamed on A, two on B, two on B1' \ 'Two lines blamed on A, two on B, two on B1' \
@ -71,7 +71,7 @@ test_expect_success \
'git checkout -b branch2 master && 'git checkout -b branch2 master &&
sed -e "s/2A quick brown/4A quick brown lazy dog/" < file > file.new && sed -e "s/2A quick brown/4A quick brown lazy dog/" < file > file.new &&
mv file.new file && mv file.new file &&
GIT_AUTHOR_NAME="B2" git commit -a -m "Branch2-1"' GIT_AUTHOR_NAME="B2" GIT_AUTHOR_EMAIL="B2@test.git" git commit -a -m "Branch2-1"'


test_expect_success \ test_expect_success \
'Two lines blamed on A, one on B, one on B2' \ 'Two lines blamed on A, one on B, one on B2' \
@ -105,7 +105,7 @@ test_expect_success \
test_expect_success \ test_expect_success \
'an incomplete line added' \ 'an incomplete line added' \
'echo "incomplete" | tr -d "\\012" >>file && 'echo "incomplete" | tr -d "\\012" >>file &&
GIT_AUTHOR_NAME="C" git commit -a -m "Incomplete"' GIT_AUTHOR_NAME="C" GIT_AUTHOR_EMAIL="C@test.git" git commit -a -m "Incomplete"'


test_expect_success \ test_expect_success \
'With incomplete lines.' \ 'With incomplete lines.' \
@ -119,7 +119,7 @@ test_expect_success \
echo echo
} | sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" > file && } | sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" > file &&
echo "incomplete" | tr -d "\\012" >>file && echo "incomplete" | tr -d "\\012" >>file &&
GIT_AUTHOR_NAME="D" git commit -a -m "edit"' GIT_AUTHOR_NAME="D" GIT_AUTHOR_EMAIL="D@test.git" git commit -a -m "edit"'


test_expect_success \ test_expect_success \
'some edit' \ 'some edit' \

View File

@ -6,4 +6,9 @@ test_description='git blame'
PROG='git blame -c' PROG='git blame -c'
. "$TEST_DIRECTORY"/annotate-tests.sh . "$TEST_DIRECTORY"/annotate-tests.sh


PROG='git blame -c -e'
test_expect_success 'Blame --show-email works' '
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
'

test_done test_done