{"thread":{"id":"31856","subject":"[WIP-PATCH 1/3] pretty: remove reencode_commit_message()","startedAt":"2012-10-18T02:20:15Z","lastAt":"2012-10-18T02:20:18Z","messageCount":4,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"201461","messageId":"1350526818-354-1-git-send-email-gitster@pobox.com","threadId":"31856","inReplyTo":null,"subject":"[WIP-PATCH 0/3] Cleaning up \"notes\" in log output","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-10-18T02:20:15Z","receivedAt":"2012-10-18T02:20:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This is only the preparatory step.\n\nThe obvious next one that follows will swap the \"add-sign-off\" logic\nand appending of notes, so that sign-off will come before the notes.\nAnd then, we will insert \"---\" before we add notes, leave a bit in\nthe rev_info for the later step in the codepath to tell it that it\ndoes not have to add another \"---\", and tweak the existing codepath\nthat adds \"---\" to refrain from doing so.\n\nJunio C Hamano (3):\n  pretty: remove reencode_commit_message()\n  pretty: prepare notes message at a centralized place\n  pretty_print_commit(): do not append notes message\n\n builtin/blame.c |  5 +++--\n commit.h        |  4 +---\n log-tree.c      | 17 ++++++++++++++++-\n pretty.c        | 22 ++++------------------\n 4 files changed, 24 insertions(+), 24 deletions(-)\n\n-- \n1.8.0.rc3.112.gdb88a5e\n"},{"id":"201459","messageId":"1350526818-354-2-git-send-email-gitster@pobox.com","threadId":"31856","inReplyTo":"1350526818-354-1-git-send-email-gitster@pobox.com","subject":"[WIP-PATCH 1/3] pretty: remove reencode_commit_message()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-10-18T02:20:16Z","receivedAt":"2012-10-18T02:20:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This function has only two callsites, and is a thin wrapper whose\nusefulness is dubious.  When the caller needs to learn the log\noutput encoding, it should be able to do so by directly calling\nget_log_output_encoding() and calling the underlying\nlogmsg_reencode() with it.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin/blame.c |  5 +++--\n commit.h        |  2 --\n pretty.c        | 13 ++-----------\n 3 files changed, 5 insertions(+), 15 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex c27ef21..cfae569 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -1425,7 +1425,7 @@ static void get_commit_info(struct commit *commit,\n \t\t\t    int detailed)\n {\n \tint len;\n-\tconst char *subject;\n+\tconst char *subject, *encoding;\n \tchar *reencoded, *message;\n \tstatic char author_name[1024];\n \tstatic char author_mail[1024];\n@@ -1446,7 +1446,8 @@ static void get_commit_info(struct commit *commit,\n \t\t\tdie(\"Cannot read commit %s\",\n \t\t\t    sha1_to_hex(commit->object.sha1));\n \t}\n-\treencoded = reencode_commit_message(commit, NULL);\n+\tencoding = get_log_output_encoding();\n+\treencoded = logmsg_reencode(commit, encoding);\n \tmessage   = reencoded ? reencoded : commit->buffer;\n \tret->author = author_name;\n \tret->author_mail = author_mail;\ndiff --git a/commit.h b/commit.h\nindex 9f21313..a822af8 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -99,8 +99,6 @@ extern int has_non_ascii(const char *text);\n struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */\n extern char *logmsg_reencode(const struct commit *commit,\n \t\t\t     const char *output_encoding);\n-extern char *reencode_commit_message(const struct commit *commit,\n-\t\t\t\t     const char **encoding_p);\n extern void get_commit_format(const char *arg, struct rev_info *);\n extern const char *format_subject(struct strbuf *sb, const char *msg,\n \t\t\t\t  const char *line_separator);\ndiff --git a/pretty.c b/pretty.c\nindex 8b1ea9f..c311a68 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1341,16 +1341,6 @@ void pp_remainder(const struct pretty_print_context *pp,\n \t}\n }\n \n-char *reencode_commit_message(const struct commit *commit, const char **encoding_p)\n-{\n-\tconst char *encoding;\n-\n-\tencoding = get_log_output_encoding();\n-\tif (encoding_p)\n-\t\t*encoding_p = encoding;\n-\treturn logmsg_reencode(commit, encoding);\n-}\n-\n void pretty_print_commit(const struct pretty_print_context *pp,\n \t\t\t const struct commit *commit,\n \t\t\t struct strbuf *sb)\n@@ -1367,7 +1357,8 @@ void pretty_print_commit(const struct pretty_print_context *pp,\n \t\treturn;\n \t}\n \n-\treencoded = reencode_commit_message(commit, &encoding);\n+\tencoding = get_log_output_encoding();\n+\treencoded = logmsg_reencode(commit, encoding);\n \tif (reencoded) {\n \t\tmsg = reencoded;\n \t}\n-- \n1.8.0.rc3.112.gdb88a5e\n"},{"id":"201460","messageId":"1350526818-354-3-git-send-email-gitster@pobox.com","threadId":"31856","inReplyTo":"1350526818-354-1-git-send-email-gitster@pobox.com","subject":"[WIP-PATCH 2/3] pretty: prepare notes message at a centralized place","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-10-18T02:20:17Z","receivedAt":"2012-10-18T02:20:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Instead of passing a boolean show_notes around, pass an optional\nstring buffer that is to be inserted after the log message proper is\nshown.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n commit.h   |  2 +-\n log-tree.c | 15 ++++++++++++++-\n pretty.c   | 10 ++++------\n 3 files changed, 19 insertions(+), 8 deletions(-)\n\ndiff --git a/commit.h b/commit.h\nindex a822af8..e119788 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -86,7 +86,7 @@ struct pretty_print_context {\n \tenum date_mode date_mode;\n \tunsigned date_mode_explicit:1;\n \tint need_8bit_cte;\n-\tint show_notes;\n+\tstruct strbuf *after_message_body;\n \tstruct reflog_walk_info *reflog_info;\n \tconst char *output_encoding;\n };\ndiff --git a/log-tree.c b/log-tree.c\nindex c894930..95ff405 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -533,6 +533,7 @@ static void show_mergetag(struct rev_info *opt, struct commit *commit)\n void show_log(struct rev_info *opt)\n {\n \tstruct strbuf msgbuf = STRBUF_INIT;\n+\tstruct strbuf appendbuf = STRBUF_INIT;\n \tstruct log_info *log = opt->loginfo;\n \tstruct commit *commit = log->commit, *parent = log->parent;\n \tint abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;\n@@ -540,7 +541,6 @@ void show_log(struct rev_info *opt)\n \tstruct pretty_print_context ctx = {0};\n \n \topt->loginfo = NULL;\n-\tctx.show_notes = opt->show_notes;\n \tif (!opt->verbose_header) {\n \t\tgraph_show_commit(opt->graph);\n \n@@ -648,6 +648,18 @@ void show_log(struct rev_info *opt)\n \tif (!commit->buffer)\n \t\treturn;\n \n+\tif (opt->show_notes) {\n+\t\tint flags;\n+\n+\t\tif (opt->commit_format == CMIT_FMT_USERFORMAT)\n+\t\t\tflags = 0;\n+\t\telse\n+\t\t\tflags = NOTES_SHOW_HEADER | NOTES_INDENT;\n+\t\tformat_display_notes(commit->object.sha1, &appendbuf,\n+\t\t\t\t     get_log_output_encoding(), flags);\n+\t\tctx.after_message_body = &appendbuf;\n+\t}\n+\n \t/*\n \t * And then the pretty-printed message itself\n \t */\n@@ -689,6 +701,7 @@ void show_log(struct rev_info *opt)\n \t}\n \n \tstrbuf_release(&msgbuf);\n+\tstrbuf_release(&appendbuf);\n }\n \n int log_tree_diff_flush(struct rev_info *opt)\ndiff --git a/pretty.c b/pretty.c\nindex c311a68..bdd991c 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1033,9 +1033,8 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,\n \t\t}\n \t\treturn 0;\t/* unknown %g placeholder */\n \tcase 'N':\n-\t\tif (c->pretty_ctx->show_notes) {\n-\t\t\tformat_display_notes(commit->object.sha1, sb,\n-\t\t\t\t    get_log_output_encoding(), 0);\n+\t\tif (c->pretty_ctx->after_message_body) {\n+\t\t\tstrbuf_addbuf(sb, c->pretty_ctx->after_message_body);\n \t\t\treturn 1;\n \t\t}\n \t\treturn 0;\n@@ -1418,9 +1417,8 @@ void pretty_print_commit(const struct pretty_print_context *pp,\n \tif (pp->fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)\n \t\tstrbuf_addch(sb, '\\n');\n \n-\tif (pp->show_notes)\n-\t\tformat_display_notes(commit->object.sha1, sb, encoding,\n-\t\t\t\t     NOTES_SHOW_HEADER | NOTES_INDENT);\n+\tif (pp->after_message_body)\n+\t\tstrbuf_addbuf(sb, pp->after_message_body);\n \n \tfree(reencoded);\n }\n-- \n1.8.0.rc3.112.gdb88a5e\n"},{"id":"201462","messageId":"1350526818-354-4-git-send-email-gitster@pobox.com","threadId":"31856","inReplyTo":"1350526818-354-1-git-send-email-gitster@pobox.com","subject":"[WIP-PATCH 3/3] pretty_print_commit(): do not append notes message","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-10-18T02:20:18Z","receivedAt":"2012-10-18T02:20:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The only case pretty_print_commit() appends notes message to the log\nmessage taken from the commit is when show_log() calls it with the\nafter_message_body field set and the output format is not the\nuserformat.  No other users of this function sets this field in the\npretty_print_context, as can be seen in the previous step.\n\nHoist the code to append the notes message to the caller.\n\nUp to this point, no functionality change is intended.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n log-tree.c | 2 ++\n pretty.c   | 3 ---\n 2 files changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex 95ff405..6e141f0 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -673,6 +673,8 @@ void show_log(struct rev_info *opt)\n \tctx.reflog_info = opt->reflog_info;\n \tctx.fmt = opt->commit_format;\n \tpretty_print_commit(&ctx, commit, &msgbuf);\n+\tif ((ctx.fmt != CMIT_FMT_USERFORMAT) && ctx.after_message_body)\n+\t\tstrbuf_addbuf(&msgbuf, ctx.after_message_body);\n \n \tif (opt->add_signoff)\n \t\tappend_signoff(&msgbuf, opt->add_signoff);\ndiff --git a/pretty.c b/pretty.c\nindex bdd991c..ad27325 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1417,9 +1417,6 @@ void pretty_print_commit(const struct pretty_print_context *pp,\n \tif (pp->fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)\n \t\tstrbuf_addch(sb, '\\n');\n \n-\tif (pp->after_message_body)\n-\t\tstrbuf_addbuf(sb, pp->after_message_body);\n-\n \tfree(reencoded);\n }\n \n-- \n1.8.0.rc3.112.gdb88a5e\n"}]}