* [PATCH] blame: Add option to show author email instead of name
@ 2010-10-16 6:57 Kevin Ballard
2010-10-19 19:02 ` Junio C Hamano
0 siblings, 1 reply; 11+ messages in thread
From: Kevin Ballard @ 2010-10-16 6:57 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Kevin Ballard
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>
---
Documentation/git-blame.txt | 6 +++++-
builtin/blame.c | 27 +++++++++++++++++++++------
t/annotate-tests.sh | 12 ++++++------
t/t8002-blame.sh | 5 +++++
4 files changed, 37 insertions(+), 13 deletions(-)
diff --git a/Documentation/git-blame.txt b/Documentation/git-blame.txt
index a27f439..c71671b 100644
--- a/Documentation/git-blame.txt
+++ b/Documentation/git-blame.txt
@@ -8,7 +8,7 @@ git-blame - Show what revision and author last modified each line of a file
SYNOPSIS
--------
[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>]
[<rev> | --contents <file> | --reverse <rev>] [--] <file>
@@ -65,6 +65,10 @@ include::blame-options.txt[]
-s::
Suppress the author name and timestamp from the output.
+-e::
+--show-email::
+ Show the author email instead of author name (Default: off).
+
-w::
Ignore whitespace when comparing the parent's version and
the child's to find where the lines came from.
diff --git a/builtin/blame.c b/builtin/blame.c
index 1015354..0f0317c 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -1606,6 +1606,7 @@ static const char *format_time(unsigned long time, const char *tz_str,
#define OUTPUT_SHOW_NUMBER 040
#define OUTPUT_SHOW_SCORE 0100
#define OUTPUT_NO_AUTHOR 0200
+#define OUTPUT_SHOW_EMAIL 0400
static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent)
{
@@ -1671,12 +1672,17 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
}
printf("%.*s", length, hex);
- if (opt & OUTPUT_ANNOTATE_COMPAT)
- printf("\t(%10s\t%10s\t%d)", ci.author,
+ if (opt & OUTPUT_ANNOTATE_COMPAT) {
+ 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,
show_raw_time),
ent->lno + 1 + cnt);
- else {
+ } else {
if (opt & OUTPUT_SHOW_SCORE)
printf(" %*d %02d",
max_score_digits, ent->score,
@@ -1689,9 +1695,14 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
ent->s_lno + 1 + cnt);
if (!(opt & OUTPUT_NO_AUTHOR)) {
- int pad = longest_author - utf8_strwidth(ci.author);
+ char *name;
+ if (opt & OUTPUT_SHOW_EMAIL)
+ name = ci.author_mail;
+ else
+ name = ci.author;
+ int pad = longest_author - utf8_strwidth(name);
printf(" (%s%*s %10s",
- ci.author, pad, "",
+ name, pad, "",
format_time(ci.author_time,
ci.author_tz,
show_raw_time));
@@ -1829,7 +1840,10 @@ static void find_alignment(struct scoreboard *sb, int *option)
if (!(suspect->commit->object.flags & METAINFO_SHOWN)) {
suspect->commit->object.flags |= METAINFO_SHOWN;
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)
longest_author = num;
}
@@ -2278,6 +2292,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('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('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_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"),
diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh
index 4e37a66..32dd159 100644
--- a/t/annotate-tests.sh
+++ b/t/annotate-tests.sh
@@ -42,7 +42,7 @@ test_expect_success \
'echo "1A quick brown fox jumps over the" >file &&
echo "lazy dog" >>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 \
'check all lines blamed on A' \
@@ -52,7 +52,7 @@ test_expect_success \
'Setup new lines blamed on B' \
'echo "2A quick brown fox jumps over the" >>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 \
'Two lines blamed on A, two on B' \
@@ -63,7 +63,7 @@ test_expect_success \
'git checkout -b branch1 master &&
echo "3A slow green fox jumps into the" >> 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 \
'Two lines blamed on A, two on B, two on B1' \
@@ -74,7 +74,7 @@ test_expect_success \
'git checkout -b branch2 master &&
sed -e "s/2A quick brown/4A quick brown lazy dog/" < file > file.new &&
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 \
'Two lines blamed on A, one on B, one on B2' \
@@ -108,7 +108,7 @@ test_expect_success \
test_expect_success \
'an incomplete line added' \
'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 \
'With incomplete lines.' \
@@ -122,7 +122,7 @@ test_expect_success \
echo
} | sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" > 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 \
'some edit' \
diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh
index 597cf04..d3a51e1 100755
--- a/t/t8002-blame.sh
+++ b/t/t8002-blame.sh
@@ -6,4 +6,9 @@ test_description='git blame'
PROG='git blame -c'
. "$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
--
1.7.3.1.211.g4f60f
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] blame: Add option to show author email instead of name
2010-10-16 6:57 [PATCH] blame: Add option to show author email instead of name Kevin Ballard
@ 2010-10-19 19:02 ` Junio C Hamano
2010-10-20 0:42 ` [PATCH v2] " Kevin Ballard
0 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2010-10-19 19:02 UTC (permalink / raw)
To: Kevin Ballard; +Cc: git
Kevin Ballard <kevin@sb.org> writes:
> 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.
Some nits.
CC builtin/blame.o
cc1: warnings being treated as errors
builtin/blame.c: In function 'emit_other':
builtin/blame.c:1678: error: assignment discards qualifiers from pointer target type
builtin/blame.c:1680: error: assignment discards qualifiers from pointer target type
builtin/blame.c:1700: error: assignment discards qualifiers from pointer target type
builtin/blame.c:1702: error: assignment discards qualifiers from pointer target type
builtin/blame.c:1703: error: ISO C90 forbids mixed declarations and code
make: *** [builtin/blame.o] Error 1
builtin/blame.c | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/builtin/blame.c b/builtin/blame.c
index 0f0317c..df45e5c 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -1673,7 +1673,7 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
printf("%.*s", length, hex);
if (opt & OUTPUT_ANNOTATE_COMPAT) {
- char *name;
+ const char *name;
if (opt & OUTPUT_SHOW_EMAIL)
name = ci.author_mail;
else
@@ -1695,12 +1695,13 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
ent->s_lno + 1 + cnt);
if (!(opt & OUTPUT_NO_AUTHOR)) {
- char *name;
+ const char *name;
+ int pad;
if (opt & OUTPUT_SHOW_EMAIL)
name = ci.author_mail;
else
name = ci.author;
- int pad = longest_author - utf8_strwidth(name);
+ pad = longest_author - utf8_strwidth(name);
printf(" (%s%*s %10s",
name, pad, "",
format_time(ci.author_time,
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2] blame: Add option to show author email instead of name
2010-10-19 19:02 ` Junio C Hamano
@ 2010-10-20 0:42 ` Kevin Ballard
2010-10-21 18:05 ` Jonathan Nieder
0 siblings, 1 reply; 11+ messages in thread
From: Kevin Ballard @ 2010-10-20 0:42 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Kevin Ballard
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>
---
Thanks for the nitpicks. I should have caught those myself.
I did notice that you had one more warning than I see when I compile;
namely, the ISO C90 warning. What did you set to get that? Both -ansi
and -pedantic trigger other errors. I also checked CodingGuidelines
and it doesn't mention what specific flags I should be passing to GCC
for things like this.
Documentation/git-blame.txt | 6 +++++-
builtin/blame.c | 28 ++++++++++++++++++++++------
t/annotate-tests.sh | 12 ++++++------
t/t8002-blame.sh | 5 +++++
4 files changed, 38 insertions(+), 13 deletions(-)
diff --git a/Documentation/git-blame.txt b/Documentation/git-blame.txt
index a27f439..c71671b 100644
--- a/Documentation/git-blame.txt
+++ b/Documentation/git-blame.txt
@@ -8,7 +8,7 @@ git-blame - Show what revision and author last modified each line of a file
SYNOPSIS
--------
[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>]
[<rev> | --contents <file> | --reverse <rev>] [--] <file>
@@ -65,6 +65,10 @@ include::blame-options.txt[]
-s::
Suppress the author name and timestamp from the output.
+-e::
+--show-email::
+ Show the author email instead of author name (Default: off).
+
-w::
Ignore whitespace when comparing the parent's version and
the child's to find where the lines came from.
diff --git a/builtin/blame.c b/builtin/blame.c
index 1015354..df45e5c 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -1606,6 +1606,7 @@ static const char *format_time(unsigned long time, const char *tz_str,
#define OUTPUT_SHOW_NUMBER 040
#define OUTPUT_SHOW_SCORE 0100
#define OUTPUT_NO_AUTHOR 0200
+#define OUTPUT_SHOW_EMAIL 0400
static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent)
{
@@ -1671,12 +1672,17 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
}
printf("%.*s", length, hex);
- if (opt & OUTPUT_ANNOTATE_COMPAT)
- printf("\t(%10s\t%10s\t%d)", ci.author,
+ if (opt & OUTPUT_ANNOTATE_COMPAT) {
+ 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,
show_raw_time),
ent->lno + 1 + cnt);
- else {
+ } else {
if (opt & OUTPUT_SHOW_SCORE)
printf(" %*d %02d",
max_score_digits, ent->score,
@@ -1689,9 +1695,15 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
ent->s_lno + 1 + cnt);
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",
- ci.author, pad, "",
+ name, pad, "",
format_time(ci.author_time,
ci.author_tz,
show_raw_time));
@@ -1829,7 +1841,10 @@ static void find_alignment(struct scoreboard *sb, int *option)
if (!(suspect->commit->object.flags & METAINFO_SHOWN)) {
suspect->commit->object.flags |= METAINFO_SHOWN;
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)
longest_author = num;
}
@@ -2278,6 +2293,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('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('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_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"),
diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh
index 141b60c..e0e5b8a 100644
--- a/t/annotate-tests.sh
+++ b/t/annotate-tests.sh
@@ -39,7 +39,7 @@ test_expect_success \
'echo "1A quick brown fox jumps over the" >file &&
echo "lazy dog" >>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 \
'check all lines blamed on A' \
@@ -49,7 +49,7 @@ test_expect_success \
'Setup new lines blamed on B' \
'echo "2A quick brown fox jumps over the" >>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 \
'Two lines blamed on A, two on B' \
@@ -60,7 +60,7 @@ test_expect_success \
'git checkout -b branch1 master &&
echo "3A slow green fox jumps into the" >> 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 \
'Two lines blamed on A, two on B, two on B1' \
@@ -71,7 +71,7 @@ test_expect_success \
'git checkout -b branch2 master &&
sed -e "s/2A quick brown/4A quick brown lazy dog/" < file > file.new &&
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 \
'Two lines blamed on A, one on B, one on B2' \
@@ -105,7 +105,7 @@ test_expect_success \
test_expect_success \
'an incomplete line added' \
'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 \
'With incomplete lines.' \
@@ -119,7 +119,7 @@ test_expect_success \
echo
} | sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" > 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 \
'some edit' \
diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh
index 597cf04..d3a51e1 100755
--- a/t/t8002-blame.sh
+++ b/t/t8002-blame.sh
@@ -6,4 +6,9 @@ test_description='git blame'
PROG='git blame -c'
. "$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
--
1.7.3.1.211.g4f60f
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2] blame: Add option to show author email instead of name
2010-10-20 0:42 ` [PATCH v2] " Kevin Ballard
@ 2010-10-21 18:05 ` Jonathan Nieder
2010-10-21 20:28 ` Kevin Ballard
0 siblings, 1 reply; 11+ messages in thread
From: Jonathan Nieder @ 2010-10-21 18:05 UTC (permalink / raw)
To: Kevin Ballard; +Cc: git, Junio C Hamano
Kevin Ballard wrote:
> +++ b/t/t8002-blame.sh
> @@ -6,4 +6,9 @@ test_description='git blame'
> PROG='git blame -c'
> . "$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
> +'
> +
Bonus nit: does this belong in annotate-tests.sh or does it only apply
to "git blame" and not "git annotate"? If the latter, a note in the
commit message would be helpful.
Thanks for your work.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2] blame: Add option to show author email instead of name
2010-10-21 18:05 ` Jonathan Nieder
@ 2010-10-21 20:28 ` Kevin Ballard
2010-10-21 20:32 ` Jonathan Nieder
0 siblings, 1 reply; 11+ messages in thread
From: Kevin Ballard @ 2010-10-21 20:28 UTC (permalink / raw)
To: Jonathan Nieder; +Cc: git, Junio C Hamano
On Oct 21, 2010, at 11:05 AM, Jonathan Nieder wrote:
> Kevin Ballard wrote:
>
>> +++ b/t/t8002-blame.sh
>> @@ -6,4 +6,9 @@ test_description='git blame'
>> PROG='git blame -c'
>> . "$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
>> +'
>> +
>
> Bonus nit: does this belong in annotate-tests.sh or does it only apply
> to "git blame" and not "git annotate"? If the latter, a note in the
> commit message would be helpful.
--show-email originally only applied to git-blame. I tweaked the patch to make it apply to git-annotate simply because check_count can't handle the format of git-blame, but the intention of the change wasn't to make it apply to git-annotate in the first place. You'll note I also didn't document it in the manpage for git-annotate. If you think it's better to move it into annotate-tests.sh, I can do that, but that does mean officially declaring git-annotate as supporting --show-email.
-Kevin Ballard
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2] blame: Add option to show author email instead of name
2010-10-21 20:28 ` Kevin Ballard
@ 2010-10-21 20:32 ` Jonathan Nieder
2010-10-21 20:38 ` Kevin Ballard
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Jonathan Nieder @ 2010-10-21 20:32 UTC (permalink / raw)
To: Kevin Ballard; +Cc: git, Junio C Hamano
Kevin Ballard wrote:
> On Oct 21, 2010, at 11:05 AM, Jonathan Nieder wrote:
>> Bonus nit: does this belong in annotate-tests.sh or does it only apply
>> to "git blame" and not "git annotate"? If the latter, a note in the
>> commit message would be helpful.
>
> --show-email originally only applied to git-blame. I tweaked the
> patch to make it apply to git-annotate simply because check_count
> can't handle the format of git-blame, but the intention of the
> change wasn't to make it apply to git-annotate in the first place.
> You'll note I also didn't document it in the manpage for
> git-annotate. If you think it's better to move it into
> annotate-tests.sh, I can do that, but that does mean officially
> declaring git-annotate as supporting --show-email.
No preference, since I never use "git annotate" myself. In fact,
long term, I'd rather see a "git blame --format=<template>" appearing
and "git annotate" replaced with a thin script wrapping "git blame".
Anyway, whatever you decide, it would be nice to document it in the
commit message, no? e.g.:
The tests and documentation only affect "git blame",
because...
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2] blame: Add option to show author email instead of name
2010-10-21 20:32 ` Jonathan Nieder
@ 2010-10-21 20:38 ` Kevin Ballard
2010-10-21 20:49 ` [PATCH v3] " Kevin Ballard
2010-10-21 20:53 ` [PATCH v2] " Jeff King
2 siblings, 0 replies; 11+ messages in thread
From: Kevin Ballard @ 2010-10-21 20:38 UTC (permalink / raw)
To: Jonathan Nieder; +Cc: git, Junio C Hamano
On Oct 21, 2010, at 1:32 PM, Jonathan Nieder wrote:
> Kevin Ballard wrote:
>> On Oct 21, 2010, at 11:05 AM, Jonathan Nieder wrote:
>
>>> Bonus nit: does this belong in annotate-tests.sh or does it only apply
>>> to "git blame" and not "git annotate"? If the latter, a note in the
>>> commit message would be helpful.
>>
>> --show-email originally only applied to git-blame. I tweaked the
>> patch to make it apply to git-annotate simply because check_count
>> can't handle the format of git-blame, but the intention of the
>> change wasn't to make it apply to git-annotate in the first place.
>> You'll note I also didn't document it in the manpage for
>> git-annotate. If you think it's better to move it into
>> annotate-tests.sh, I can do that, but that does mean officially
>> declaring git-annotate as supporting --show-email.
>
> No preference, since I never use "git annotate" myself. In fact,
> long term, I'd rather see a "git blame --format=<template>" appearing
> and "git annotate" replaced with a thin script wrapping "git blame".
>
> Anyway, whatever you decide, it would be nice to document it in the
> commit message, no? e.g.:
>
> The tests and documentation only affect "git blame",
> because...
Will do.
-Kevin Ballard
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3] blame: Add option to show author email instead of name
2010-10-21 20:32 ` Jonathan Nieder
2010-10-21 20:38 ` Kevin Ballard
@ 2010-10-21 20:49 ` Kevin Ballard
2010-10-21 20:53 ` [PATCH v2] " Jeff King
2 siblings, 0 replies; 11+ messages in thread
From: Kevin Ballard @ 2010-10-21 20:49 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Kevin Ballard, Jonathan Nieder
Add a new option -e (or --show-email) to git-blame that will display
the author's email instead of name on each line.
Note that this option is supported on git-annotate, but there are no
tests ensuring this, nor is it documented. The support in git-annotate
only exists because the tests for git-blame require the -c option
and thus are really tests for git-annotate. This may change at a future
date.
Signed-off-by: Kevin Ballard <kevin@sb.org>
---
The only change here is the commit message, as requested by Jonathan Nieder.
Documentation/git-blame.txt | 6 +++++-
builtin/blame.c | 28 ++++++++++++++++++++++------
t/annotate-tests.sh | 12 ++++++------
t/t8002-blame.sh | 5 +++++
4 files changed, 38 insertions(+), 13 deletions(-)
diff --git a/Documentation/git-blame.txt b/Documentation/git-blame.txt
index a27f439..c71671b 100644
--- a/Documentation/git-blame.txt
+++ b/Documentation/git-blame.txt
@@ -8,7 +8,7 @@ git-blame - Show what revision and author last modified each line of a file
SYNOPSIS
--------
[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>]
[<rev> | --contents <file> | --reverse <rev>] [--] <file>
@@ -65,6 +65,10 @@ include::blame-options.txt[]
-s::
Suppress the author name and timestamp from the output.
+-e::
+--show-email::
+ Show the author email instead of author name (Default: off).
+
-w::
Ignore whitespace when comparing the parent's version and
the child's to find where the lines came from.
diff --git a/builtin/blame.c b/builtin/blame.c
index 1015354..df45e5c 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -1606,6 +1606,7 @@ static const char *format_time(unsigned long time, const char *tz_str,
#define OUTPUT_SHOW_NUMBER 040
#define OUTPUT_SHOW_SCORE 0100
#define OUTPUT_NO_AUTHOR 0200
+#define OUTPUT_SHOW_EMAIL 0400
static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent)
{
@@ -1671,12 +1672,17 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
}
printf("%.*s", length, hex);
- if (opt & OUTPUT_ANNOTATE_COMPAT)
- printf("\t(%10s\t%10s\t%d)", ci.author,
+ if (opt & OUTPUT_ANNOTATE_COMPAT) {
+ 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,
show_raw_time),
ent->lno + 1 + cnt);
- else {
+ } else {
if (opt & OUTPUT_SHOW_SCORE)
printf(" %*d %02d",
max_score_digits, ent->score,
@@ -1689,9 +1695,15 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
ent->s_lno + 1 + cnt);
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",
- ci.author, pad, "",
+ name, pad, "",
format_time(ci.author_time,
ci.author_tz,
show_raw_time));
@@ -1829,7 +1841,10 @@ static void find_alignment(struct scoreboard *sb, int *option)
if (!(suspect->commit->object.flags & METAINFO_SHOWN)) {
suspect->commit->object.flags |= METAINFO_SHOWN;
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)
longest_author = num;
}
@@ -2278,6 +2293,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('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('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_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"),
diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh
index 141b60c..e0e5b8a 100644
--- a/t/annotate-tests.sh
+++ b/t/annotate-tests.sh
@@ -39,7 +39,7 @@ test_expect_success \
'echo "1A quick brown fox jumps over the" >file &&
echo "lazy dog" >>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 \
'check all lines blamed on A' \
@@ -49,7 +49,7 @@ test_expect_success \
'Setup new lines blamed on B' \
'echo "2A quick brown fox jumps over the" >>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 \
'Two lines blamed on A, two on B' \
@@ -60,7 +60,7 @@ test_expect_success \
'git checkout -b branch1 master &&
echo "3A slow green fox jumps into the" >> 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 \
'Two lines blamed on A, two on B, two on B1' \
@@ -71,7 +71,7 @@ test_expect_success \
'git checkout -b branch2 master &&
sed -e "s/2A quick brown/4A quick brown lazy dog/" < file > file.new &&
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 \
'Two lines blamed on A, one on B, one on B2' \
@@ -105,7 +105,7 @@ test_expect_success \
test_expect_success \
'an incomplete line added' \
'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 \
'With incomplete lines.' \
@@ -119,7 +119,7 @@ test_expect_success \
echo
} | sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" > 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 \
'some edit' \
diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh
index 597cf04..d3a51e1 100755
--- a/t/t8002-blame.sh
+++ b/t/t8002-blame.sh
@@ -6,4 +6,9 @@ test_description='git blame'
PROG='git blame -c'
. "$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
--
1.7.3.1.220.g19a98
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2] blame: Add option to show author email instead of name
2010-10-21 20:32 ` Jonathan Nieder
2010-10-21 20:38 ` Kevin Ballard
2010-10-21 20:49 ` [PATCH v3] " Kevin Ballard
@ 2010-10-21 20:53 ` Jeff King
2010-10-21 20:54 ` Kevin Ballard
2 siblings, 1 reply; 11+ messages in thread
From: Jeff King @ 2010-10-21 20:53 UTC (permalink / raw)
To: Jonathan Nieder; +Cc: Kevin Ballard, git, Junio C Hamano
On Thu, Oct 21, 2010 at 03:32:10PM -0500, Jonathan Nieder wrote:
> No preference, since I never use "git annotate" myself. In fact,
> long term, I'd rather see a "git blame --format=<template>" appearing
> and "git annotate" replaced with a thin script wrapping "git blame".
Isn't that what it is already?
$ grep blame builtin/annotate.c
return cmd_blame(argc + 1, nargv, prefix);
-Peff
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2] blame: Add option to show author email instead of name
2010-10-21 20:53 ` [PATCH v2] " Jeff King
@ 2010-10-21 20:54 ` Kevin Ballard
2010-10-21 20:58 ` Jeff King
0 siblings, 1 reply; 11+ messages in thread
From: Kevin Ballard @ 2010-10-21 20:54 UTC (permalink / raw)
To: Jeff King; +Cc: Jonathan Nieder, git, Junio C Hamano
On Oct 21, 2010, at 1:53 PM, Jeff King wrote:
> On Thu, Oct 21, 2010 at 03:32:10PM -0500, Jonathan Nieder wrote:
>
>> No preference, since I never use "git annotate" myself. In fact,
>> long term, I'd rather see a "git blame --format=<template>" appearing
>> and "git annotate" replaced with a thin script wrapping "git blame".
>
> Isn't that what it is already?
>
> $ grep blame builtin/annotate.c
> return cmd_blame(argc + 1, nargv, prefix);
>
> -Peff
IIRC, git-annotate is equivalent to `git blame -c`, which is why the tests for git-blame
are so useless (they're all tests for `git blame -c`, which makes them identical to the
tests for git-annotate).
-Kevin Ballard
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2] blame: Add option to show author email instead of name
2010-10-21 20:54 ` Kevin Ballard
@ 2010-10-21 20:58 ` Jeff King
0 siblings, 0 replies; 11+ messages in thread
From: Jeff King @ 2010-10-21 20:58 UTC (permalink / raw)
To: Kevin Ballard; +Cc: Jonathan Nieder, git, Junio C Hamano
On Thu, Oct 21, 2010 at 01:54:22PM -0700, Kevin Ballard wrote:
> > Isn't that what it is already?
> >
> > $ grep blame builtin/annotate.c
> > return cmd_blame(argc + 1, nargv, prefix);
>
> IIRC, git-annotate is equivalent to `git blame -c`, which is why the
> tests for git-blame are so useless (they're all tests for `git blame
> -c`, which makes them identical to the tests for git-annotate).
Yeah, I believe that t8002 is totally redundant with t8001 these days. I
wonder if we should just drop t8001 entirely.
The other blame tests use the "native" format. It would be nice to have
some --porcelain and --incremental tests, too, but I expect it is too
boring for anyone to volunteer to work on. :)
-Peff
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2010-10-21 20:58 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-16 6:57 [PATCH] blame: Add option to show author email instead of name Kevin Ballard
2010-10-19 19:02 ` Junio C Hamano
2010-10-20 0:42 ` [PATCH v2] " Kevin Ballard
2010-10-21 18:05 ` Jonathan Nieder
2010-10-21 20:28 ` Kevin Ballard
2010-10-21 20:32 ` Jonathan Nieder
2010-10-21 20:38 ` Kevin Ballard
2010-10-21 20:49 ` [PATCH v3] " Kevin Ballard
2010-10-21 20:53 ` [PATCH v2] " Jeff King
2010-10-21 20:54 ` Kevin Ballard
2010-10-21 20:58 ` Jeff King
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).