From: Ramkumar Ramachandra Date: Sun, 09 Jun 2013 17:54:26 GMT Subject: [PATCH v2 07/15] pretty: allow passing NULL commit to format_commit_message() Message-ID: <1370800474-8940-8-git-send-email-artagnon@gmail.com> In-Reply-To: <1370800474-8940-1-git-send-email-artagnon@gmail.com> From: Nguyễn Thái Ngọc Duy The new formatter, for-each-ref, may use non-commit placeholders only. While it could audit the format line and warn/exclude commit placeholders, that's a lot more work than simply ignore them. Unrecognized placeholders are displayed as-is, pretty obvious that they are not handled. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Ramkumar Ramachandra --- pretty.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pretty.c b/pretty.c index 0063f2d..816aa32 100644 --- a/pretty.c +++ b/pretty.c @@ -1156,6 +1156,9 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ } /* these depend on the commit */ + if (!commit) + return 0; + if (!commit->object.parsed) parse_object(commit->object.sha1); @@ -1276,6 +1279,9 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ } + if (!c->message) + return 0; + /* For the rest we have to parse the commit header. */ if (!c->commit_header_parsed) parse_commit_header(c); @@ -1510,9 +1516,10 @@ void format_commit_message(const struct commit *commit, context.commit = commit; context.pretty_ctx = pretty_ctx; context.wrap_start = sb->len; - context.message = logmsg_reencode(commit, - &context.commit_encoding, - output_enc); + if (commit) + context.message = logmsg_reencode(commit, + &context.commit_encoding, + output_enc); strbuf_expand(sb, format, format_commit_item, &context); rewrap_message_tail(sb, &context, 0, 0, 0); @@ -1535,7 +1542,8 @@ void format_commit_message(const struct commit *commit, } free(context.commit_encoding); - logmsg_free(context.message, commit); + if (commit) + logmsg_free(context.message, commit); free(context.signature_check.gpg_output); free(context.signature_check.signer); } -- 1.8.3.247.g485169c