Merge branch 'jn/shortlog' into maint

* jn/shortlog:
  pretty: Respect --abbrev option
  shortlog: Document and test --format option
  t4201 (shortlog): Test output format with multiple authors
  t4201 (shortlog): guard setup with test_expect_success
  Documentation/shortlog: scripted users should not rely on implicit HEAD
This commit is contained in:
Junio C Hamano 2010-06-16 16:22:51 -07:00
commit 799c34449e
6 changed files with 144 additions and 29 deletions

View file

@ -9,7 +9,7 @@ SYNOPSIS
--------
[verse]
git log --pretty=short | 'git shortlog' [-h] [-n] [-s] [-e] [-w]
'git shortlog' [-n|--numbered] [-s|--summary] [-e|--email] [-w[<width>[,<indent1>[,<indent2>]]]] [<committish>...]
'git shortlog' [-n|--numbered] [-s|--summary] [-e|--email] [-w[<width>[,<indent1>[,<indent2>]]]] <commit>...
DESCRIPTION
-----------
@ -19,6 +19,11 @@ the first line of the commit message will be shown.
Additionally, "[PATCH]" will be stripped from the commit description.
If no revisions are passed on the command line and either standard input
is not a terminal or there is no current branch, 'git shortlog' will
output a summary of the log read from standard input, without
reference to the current repository.
OPTIONS
-------
@ -39,6 +44,14 @@ OPTIONS
--email::
Show the email address of each author.
--format[='<format>']::
Instead of the commit subject, use some other information to
describe each commit. '<format>' can be any string accepted
by the `--format` option of 'git log', such as '{asterisk} [%h] %s'.
(See the "PRETTY FORMATS" section of linkgit:git-log[1].)
Each pretty-printed commit will be rewrapped before it is shown.
-w[<width>[,<indent1>[,<indent2>]]]::
Linewrap the output by wrapping each line at `width`. The first
line of each entry is indented by `indent1` spaces, and the second

View file

@ -162,7 +162,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
sha1_to_hex(commit->object.sha1));
if (log->user_format) {
struct pretty_print_context ctx = {0};
ctx.abbrev = DEFAULT_ABBREV;
ctx.abbrev = log->abbrev;
ctx.subject = "";
ctx.after_subject = "";
ctx.date_mode = DATE_NORMAL;
@ -290,6 +290,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
}
log.user_format = rev.commit_format == CMIT_FMT_USERFORMAT;
log.abbrev = rev.abbrev;
/* assume HEAD if from a tty */
if (!nongit && !rev.pending.nr && isatty(0))

View file

@ -716,7 +716,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
if (add_again(sb, &c->abbrev_commit_hash))
return 1;
strbuf_addstr(sb, find_unique_abbrev(commit->object.sha1,
DEFAULT_ABBREV));
c->pretty_ctx->abbrev));
c->abbrev_commit_hash.len = sb->len - c->abbrev_commit_hash.off;
return 1;
case 'T': /* tree hash */
@ -726,7 +726,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
if (add_again(sb, &c->abbrev_tree_hash))
return 1;
strbuf_addstr(sb, find_unique_abbrev(commit->tree->object.sha1,
DEFAULT_ABBREV));
c->pretty_ctx->abbrev));
c->abbrev_tree_hash.len = sb->len - c->abbrev_tree_hash.off;
return 1;
case 'P': /* parent hashes */
@ -743,7 +743,8 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
if (p != commit->parents)
strbuf_addch(sb, ' ');
strbuf_addstr(sb, find_unique_abbrev(
p->item->object.sha1, DEFAULT_ABBREV));
p->item->object.sha1,
c->pretty_ctx->abbrev));
}
c->abbrev_parent_hashes.len = sb->len -
c->abbrev_parent_hashes.off;

View file

@ -12,6 +12,7 @@ struct shortlog {
int in1;
int in2;
int user_format;
int abbrev;
char *common_repo_prefix;
int email;

View file

@ -8,30 +8,93 @@ test_description='git shortlog
. ./test-lib.sh
echo 1 > a1
git add a1
tree=$(git write-tree)
commit=$( (echo "Test"; echo) | git commit-tree $tree )
git update-ref HEAD $commit
test_expect_success 'setup' '
echo 1 >a1 &&
git add a1 &&
tree=$(git write-tree) &&
commit=$(printf "%s\n" "Test" "" | git commit-tree "$tree") &&
git update-ref HEAD "$commit" &&
echo 2 > a1
git commit --quiet -m "This is a very, very long first line for the commit message to see if it is wrapped correctly" a1
echo 2 >a1 &&
git commit --quiet -m "This is a very, very long first line for the commit message to see if it is wrapped correctly" a1 &&
# test if the wrapping is still valid when replacing all i's by treble clefs.
echo 3 > a1
git commit --quiet -m "$(echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" | sed "s/i/1234/g" | tr 1234 '\360\235\204\236')" a1
# test if the wrapping is still valid
# when replacing all is by treble clefs.
echo 3 >a1 &&
git commit --quiet -m "$(
echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" |
sed "s/i/1234/g" |
tr 1234 "\360\235\204\236")" a1 &&
# now fsck up the utf8
git config i18n.commitencoding non-utf-8
echo 4 > a1
git commit --quiet -m "$(echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" | sed "s/i/1234/g" | tr 1234 '\370\235\204\236')" a1
# now fsck up the utf8
git config i18n.commitencoding non-utf-8 &&
echo 4 >a1 &&
git commit --quiet -m "$(
echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" |
sed "s/i/1234/g" |
tr 1234 "\370\235\204\236")" a1 &&
echo 5 > a1
git commit --quiet -m "a 12 34 56 78" a1
echo 5 >a1 &&
git commit --quiet -m "a 12 34 56 78" a1
git shortlog -w HEAD > out
echo 6 >a1 &&
git commit --quiet -m "Commit by someone else" \
--author="Someone else <not!me>" a1 &&
cat > expect << EOF
cat >expect.template <<-\EOF
A U Thor (5):
SUBJECT
SUBJECT
SUBJECT
SUBJECT
SUBJECT
Someone else (1):
SUBJECT
EOF
'
fuzz() {
file=$1 &&
sed "
s/$_x40/OBJECT_NAME/g
s/$_x05/OBJID/g
s/^ \{6\}[CTa].*/ SUBJECT/g
s/^ \{8\}[^ ].*/ CONTINUATION/g
" <"$file" >"$file.fuzzy" &&
sed "/CONTINUATION/ d" <"$file.fuzzy"
}
test_expect_success 'default output format' '
git shortlog HEAD >log &&
fuzz log >log.predictable &&
test_cmp expect.template log.predictable
'
test_expect_success 'pretty format' '
sed s/SUBJECT/OBJECT_NAME/ expect.template >expect &&
git shortlog --format="%H" HEAD >log &&
fuzz log >log.predictable &&
test_cmp expect log.predictable
'
test_expect_success '--abbrev' '
sed s/SUBJECT/OBJID/ expect.template >expect &&
git shortlog --format="%h" --abbrev=5 HEAD >log &&
fuzz log >log.predictable &&
test_cmp expect log.predictable
'
test_expect_success 'output from user-defined format is re-wrapped' '
sed "s/SUBJECT/two lines/" expect.template >expect &&
git shortlog --format="two%nlines" HEAD >log &&
fuzz log >log.predictable &&
test_cmp expect log.predictable
'
test_expect_success 'shortlog wrapping' '
cat >expect <<\EOF &&
A U Thor (5):
Test
This is a very, very long first line for the commit message to see if
@ -43,14 +106,19 @@ A U Thor (5):
a 12 34
56 78
Someone else (1):
Commit by someone else
EOF
git shortlog -w HEAD >out &&
test_cmp expect out
'
test_expect_success 'shortlog wrapping' 'test_cmp expect out'
git log HEAD > log
GIT_DIR=non-existing git shortlog -w < log > out
test_expect_success 'shortlog from non-git directory' 'test_cmp expect out'
test_expect_success 'shortlog from non-git directory' '
git log HEAD >log &&
GIT_DIR=non-existing git shortlog -w <log >out &&
test_cmp expect out
'
iconvfromutf8toiso88591() {
printf "%s" "$*" | iconv -f UTF-8 -t ISO8859-1

View file

@ -191,6 +191,31 @@ test_expect_success 'add LF before non-empty (2)' '
grep "^$" actual
'
test_expect_success '--abbrev' '
echo SHORT SHORT SHORT >expect2 &&
echo LONG LONG LONG >expect3 &&
git log -1 --format="%h %h %h" HEAD >actual1 &&
git log -1 --abbrev=5 --format="%h %h %h" HEAD >actual2 &&
git log -1 --abbrev=5 --format="%H %H %H" HEAD >actual3 &&
sed -e "s/$_x40/LONG/g" -e "s/$_x05/SHORT/g" <actual2 >fuzzy2 &&
sed -e "s/$_x40/LONG/g" -e "s/$_x05/SHORT/g" <actual3 >fuzzy3 &&
test_cmp expect2 fuzzy2 &&
test_cmp expect3 fuzzy3 &&
! test_cmp actual1 actual2
'
test_expect_success '%H is not affected by --abbrev-commit' '
git log -1 --format=%H --abbrev-commit --abbrev=20 HEAD >actual &&
len=$(wc -c <actual) &&
test $len = 41
'
test_expect_success '%h is not affected by --abbrev-commit' '
git log -1 --format=%h --abbrev-commit --abbrev=20 HEAD >actual &&
len=$(wc -c <actual) &&
test $len = 21
'
test_expect_success '"%h %gD: %gs" is same as git-reflog' '
git reflog >expect &&
git log -g --format="%h %gD: %gs" >actual &&
@ -203,6 +228,12 @@ test_expect_success '"%h %gD: %gs" is same as git-reflog (with date)' '
test_cmp expect actual
'
test_expect_success '"%h %gD: %gs" is same as git-reflog (with --abbrev)' '
git reflog --abbrev=13 --date=raw >expect &&
git log -g --abbrev=13 --format="%h %gD: %gs" --date=raw >actual &&
test_cmp expect actual
'
test_expect_success '%gd shortens ref name' '
echo "master@{0}" >expect.gd-short &&
git log -g -1 --format=%gd refs/heads/master >actual.gd-short &&