From: Junio C Hamano Date: Sun, 9 May 2010 05:36:40 +0000 (-0700) Subject: Merge branch 'eb/unpretty-b-format' X-Git-Tag: v1.7.2-rc0~150 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/67e5c87cd60668c97712b14af8562b558239a757?ds=inline;hp=-c Merge branch 'eb/unpretty-b-format' * eb/unpretty-b-format: Add `%B' in format strings for raw commit body in `git log' and friends --- 67e5c87cd60668c97712b14af8562b558239a757 diff --combined pretty.c index 7cb3a2af50,14c9568c54..742b48bbd6 --- a/pretty.c +++ b/pretty.c @@@ -775,13 -775,10 +775,13 @@@ static size_t format_commit_one(struct } return 0; /* unknown %g placeholder */ case 'N': - format_display_notes(commit->object.sha1, sb, - git_log_output_encoding ? git_log_output_encoding - : git_commit_encoding, 0); - return 1; + if (c->pretty_ctx->show_notes) { + format_display_notes(commit->object.sha1, sb, + git_log_output_encoding ? git_log_output_encoding + : git_commit_encoding, 0); + return 1; + } + return 0; } /* For the rest we have to parse the commit header. */ @@@ -800,6 -797,10 +800,10 @@@ case 'e': /* encoding */ strbuf_add(sb, msg + c->encoding.off, c->encoding.len); return 1; + case 'B': /* raw body */ + /* message_off is always left at the initial newline */ + strbuf_addstr(sb, msg + c->message_off + 1); + return 1; } /* Now we need to parse the commit message. */ @@@ -858,35 -859,6 +862,35 @@@ static size_t format_commit_item(struc return consumed + 1; } +static size_t userformat_want_item(struct strbuf *sb, const char *placeholder, + void *context) +{ + struct userformat_want *w = context; + + if (*placeholder == '+' || *placeholder == '-') + placeholder++; + + switch (*placeholder) { + case 'N': + w->notes = 1; + break; + } + return 0; +} + +void userformat_find_requirements(const char *fmt, struct userformat_want *w) +{ + struct strbuf dummy = STRBUF_INIT; + + if (!fmt) { + if (!user_format) + return; + fmt = user_format; + } + strbuf_expand(&dummy, user_format, userformat_want_item, w); + strbuf_release(&dummy); +} + void format_commit_message(const struct commit *commit, const char *format, struct strbuf *sb, const struct pretty_print_context *pretty_ctx) diff --combined t/t6006-rev-list-format.sh index a49b7c5722,5d15f18366..9992be69f4 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@@ -101,6 -101,15 +101,15 @@@ commit 131a310eb913d107dd3c09a65d165117 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 EOF + test_format raw-body %B <<'EOF' + commit 131a310eb913d107dd3c09a65d1651175898735d + changed foo + + commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 + added foo + + EOF + test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF' commit 131a310eb913d107dd3c09a65d1651175898735d foobarbazxyzzy @@@ -209,13 -218,4 +218,13 @@@ test_expect_success '%gd shortens ref n test_cmp expect.gd-short actual.gd-short ' +test_expect_success 'oneline with empty message' ' + git commit -m "dummy" --allow-empty && + git commit -m "dummy" --allow-empty && + git filter-branch --msg-filter "sed -e s/dummy//" HEAD^^.. && + git rev-list --oneline HEAD >test.txt && + test $(git rev-list --oneline HEAD | wc -l) -eq 5 && + test $(git rev-list --oneline --graph HEAD | wc -l) -eq 5 +' + test_done