From 02646fe55dbbbdd8559f7ed2f38385ffb6b9571c Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Mon, 3 May 2010 21:57:10 -0500 Subject: [PATCH 1/5] Documentation/shortlog: scripted users should not rely on implicit HEAD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When passed no revision arguments, ‘git shortlog’ reads a log from stdin if and only if stdin is not a tty. So scripts that need to function identically when standard input is a terminal (as when run interactively) and not (as when run through a cron job) should either supply a log themselves or specify the desired revisions explicitly. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- Documentation/git-shortlog.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Documentation/git-shortlog.txt b/Documentation/git-shortlog.txt index dfd4d0c223..f11ea90237 100644 --- a/Documentation/git-shortlog.txt +++ b/Documentation/git-shortlog.txt @@ -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[[,[,]]]] [...] +'git shortlog' [-n|--numbered] [-s|--summary] [-e|--email] [-w[[,[,]]]] ... 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 ------- From ae00dc191a8da2309a6d7c68a254ede1357d877d Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Mon, 3 May 2010 21:57:36 -0500 Subject: [PATCH 2/5] t4201 (shortlog): guard setup with test_expect_success Follow the current prevailing style. This also has the benefit of capturing any stray output and noticing if any of the setup commands start failing. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/t4201-shortlog.sh | 60 ++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh index a01e55bf6b..438a826473 100755 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -8,30 +8,38 @@ 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 - -cat > expect << EOF +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 @@ -44,13 +52,15 @@ A U Thor (5): 56 78 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 out && + test_cmp expect out +' iconvfromutf8toiso88591() { printf "%s" "$*" | iconv -f UTF-8 -t ISO8859-1 From ed715b5e393f922b7726460c348c8cb7eb7de49b Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Mon, 3 May 2010 21:58:04 -0500 Subject: [PATCH 3/5] t4201 (shortlog): Test output format with multiple authors Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/t4201-shortlog.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh index 438a826473..6bfd0c0582 100755 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -36,6 +36,10 @@ test_expect_success 'setup' ' echo 5 >a1 && git commit --quiet -m "a 12 34 56 78" a1 + + echo 6 >a1 && + git commit --quiet -m "Commit by someone else" \ + --author="Someone else " a1 ' test_expect_success 'shortlog wrapping' ' @@ -51,6 +55,9 @@ 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 From 600372497c668045a365b9eab76987ee19405f7a Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Mon, 3 May 2010 21:59:55 -0500 Subject: [PATCH 4/5] shortlog: Document and test --format option Do not document the --pretty synonym, since it takes too long to explain the name to people. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- Documentation/git-shortlog.txt | 8 +++++ t/t4201-shortlog.sh | 53 +++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/Documentation/git-shortlog.txt b/Documentation/git-shortlog.txt index f11ea90237..bc1ac77495 100644 --- a/Documentation/git-shortlog.txt +++ b/Documentation/git-shortlog.txt @@ -44,6 +44,14 @@ OPTIONS --email:: Show the email address of each author. +--format[='']:: + Instead of the commit subject, use some other information to + describe each commit. '' 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[[,[,]]]:: Linewrap the output by wrapping each line at `width`. The first line of each entry is indented by `indent1` spaces, and the second diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh index 6bfd0c0582..13fdeb2653 100755 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -39,7 +39,58 @@ test_expect_success 'setup' ' echo 6 >a1 && git commit --quiet -m "Commit by someone else" \ - --author="Someone else " a1 + --author="Someone else " a1 && + + 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_failure '--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' ' From c197702156e2164074327f5e870ab0d3021977fc Mon Sep 17 00:00:00 2001 From: Will Palmer Date: Mon, 3 May 2010 22:18:57 -0500 Subject: [PATCH 5/5] pretty: Respect --abbrev option Prior to this, the output of git log -1 --format=%h was always 7 characters long, without regard to whether --abbrev had been passed. Signed-off-by: Will Palmer Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin-shortlog.c | 3 ++- pretty.c | 7 ++++--- shortlog.h | 1 + t/t4201-shortlog.sh | 2 +- t/t6006-rev-list-format.sh | 31 +++++++++++++++++++++++++++++++ 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/builtin-shortlog.c b/builtin-shortlog.c index ecd2d45a00..6f36362818 100644 --- a/builtin-shortlog.c +++ b/builtin-shortlog.c @@ -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 @@ parse_done: } 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)) diff --git a/pretty.c b/pretty.c index d493cade26..6b3550b1f1 100644 --- a/pretty.c +++ b/pretty.c @@ -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; diff --git a/shortlog.h b/shortlog.h index bc02cc29ef..de4f86fb97 100644 --- a/shortlog.h +++ b/shortlog.h @@ -12,6 +12,7 @@ struct shortlog { int in1; int in2; int user_format; + int abbrev; char *common_repo_prefix; int email; diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh index 13fdeb2653..cdb70b4b33 100755 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -79,7 +79,7 @@ test_expect_success 'pretty format' ' test_cmp expect log.predictable ' -test_expect_failure '--abbrev' ' +test_expect_success '--abbrev' ' sed s/SUBJECT/OBJID/ expect.template >expect && git shortlog --format="%h" --abbrev=5 HEAD >log && fuzz log >log.predictable && diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index d24ca5c077..313897bbc0 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -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" fuzzy2 && + sed -e "s/$_x40/LONG/g" -e "s/$_x05/SHORT/g" 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 && + len=$(wc -c 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 &&