Cleaning up "notes" in log output
cover Cleaning up "notes" in log output
This is only the preparatory step.
The obvious next one that follows will swap the "add-sign-off" logic and appending of notes, so that sign-off will come before the notes. And then, we will insert "---" before we add notes, leave a bit in the rev_info for the later step in the codepath to tell it that it does not have to add another "---", and tweak the existing codepath that adds "---" to refrain from doing so.
Junio C Hamano (3):
pretty: remove reencode_commit_message()
pretty: prepare notes message at a centralized place pretty_print_commit(): do not append notes message
builtin/blame.c | 5 +++-- commit.h | 4 +--- log-tree.c | 17 ++++++++++++++++- pretty.c | 22 ++++------------------ 4 files changed, 24 insertions(+), 24 deletions(-)
Signature · 1 line
1.8.0.rc3.112.gdb88a5e
PATCH 1/3 pretty: remove reencode_commit_message()
This function has only two callsites, and is a thin wrapper whose usefulness is dubious. When the caller needs to learn the log output encoding, it should be able to do so by directly calling get_log_output_encoding() and calling the underlying logmsg_reencode() with it.
--- builtin/blame.c | 5 +++-- commit.h | 2 -- pretty.c | 13 ++----------- 3 files changed, 5 insertions(+), 15 deletions(-)
builtin/blame.c +3 -2
@@ -1425,7 +1425,7 @@ static void get_commit_info(struct commit *commit, int detailed) {int len; -const char *subject; +const char *subject, *encoding;char *reencoded, *message;static char author_name[1024 ];static char author_mail[1024 ];
@@ -1446,7 +1446,8 @@ static void get_commit_info(struct commit *commit,die ("Cannot read commit %s" ,sha1_to_hex (commit->object.sha1)); } - reencoded =reencode_commit_message (commit,NULL ); + encoding =get_log_output_encoding (); + reencoded =logmsg_reencode (commit, encoding); message = reencoded ? reencoded : commit->buffer; ret->author = author_name; ret->author_mail = author_mail;
commit.h +0 -2
@@ -99,8 +99,6 @@ extern int has_non_ascii(const char *text);struct rev_info ;/* in revision.h, it circularly uses enum cmit_fmt */ extern char *logmsg_reencode (const struct commit *commit,const char *output_encoding); -extern char *reencode_commit_message (const struct commit *commit, -const char **encoding_p);extern void get_commit_format (const char *arg,struct rev_info *);extern const char *format_subject (struct strbuf *sb,const char *msg,const char *line_separator);
pretty.c +2 -11
@@ -1341,16 +1341,6 @@ void pp_remainder(const struct pretty_print_context *pp, } } -char *reencode_commit_message (const struct commit *commit,const char **encoding_p) -{ -const char *encoding; - - encoding =get_log_output_encoding (); -if (encoding_p) - *encoding_p = encoding; -return logmsg_reencode (commit, encoding); -} -void pretty_print_commit (const struct pretty_print_context *pp,const struct commit *commit,struct strbuf *sb)
@@ -1367,7 +1357,8 @@ void pretty_print_commit(const struct pretty_print_context *pp,return ; } - reencoded =reencode_commit_message (commit, &encoding); + encoding =get_log_output_encoding (); + reencoded =logmsg_reencode (commit, encoding);if (reencoded) { msg = reencoded; }
Signature · 1 line
1.8.0.rc3.112.gdb88a5e
PATCH 2/3 pretty: prepare notes message at a centralized place
In reply to Junio C HamanoInstead of passing a boolean show_notes around, pass an optional string buffer that is to be inserted after the log message proper is shown.
--- commit.h | 2 +- log-tree.c | 15 ++++++++++++++- pretty.c | 10 ++++------ 3 files changed, 19 insertions(+), 8 deletions(-)
commit.h +1 -1
@@ -86,7 +86,7 @@ struct pretty_print_context {enum date_mode date_mode; unsigned date_mode_explicit:1;int need_8bit_cte; -int show_notes; +struct strbuf *after_message_body;struct reflog_walk_info *reflog_info;const char *output_encoding; };
log-tree.c +14 -1
@@ -533,6 +533,7 @@ static void show_mergetag(struct rev_info *opt, struct commit *commit)void show_log (struct rev_info *opt) {struct strbuf msgbuf =STRBUF_INIT ; +struct strbuf appendbuf =STRBUF_INIT ;struct log_info *log = opt->loginfo;struct commit *commit = log->commit, *parent = log->parent;int abbrev_commit = opt->abbrev_commit ? opt->abbrev :40 ;
@@ -540,7 +541,6 @@ void show_log(struct rev_info *opt)struct pretty_print_context ctx = {0 }; opt->loginfo =NULL ; - ctx.show_notes = opt->show_notes;if (!opt->verbose_header) {graph_show_commit (opt->graph);
@@ -648,6 +648,18 @@ void show_log(struct rev_info *opt)if (!commit->buffer)return ; +if (opt->show_notes) { +int flags; + +if (opt->commit_format ==CMIT_FMT_USERFORMAT ) + flags =0 ; +else + flags =NOTES_SHOW_HEADER |NOTES_INDENT ; +format_display_notes (commit->object.sha1, &appendbuf, +get_log_output_encoding (), flags); + ctx.after_message_body = &appendbuf; + } +/* * And then the pretty-printed message itself */
@@ -689,6 +701,7 @@ void show_log(struct rev_info *opt) }strbuf_release (&msgbuf); +strbuf_release (&appendbuf); }int log_tree_diff_flush (struct rev_info *opt)
pretty.c +4 -6
@@ -1033,9 +1033,8 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder, }return 0 ;/* unknown %g placeholder */ case 'N' : -if (c->pretty_ctx->show_notes) { -format_display_notes (commit->object.sha1, sb, -get_log_output_encoding (),0 ); +if (c->pretty_ctx->after_message_body) { +strbuf_addbuf (sb, c->pretty_ctx->after_message_body);return 1 ; }return 0 ;
@@ -1418,9 +1417,8 @@ void pretty_print_commit(const struct pretty_print_context *pp,if (pp->fmt ==CMIT_FMT_EMAIL && sb->len <= beginning_of_body)strbuf_addch (sb,'\n' ); -if (pp->show_notes) -format_display_notes (commit->object.sha1, sb, encoding, -NOTES_SHOW_HEADER |NOTES_INDENT ); +if (pp->after_message_body) +strbuf_addbuf (sb, pp->after_message_body);free (reencoded); }
Signature · 1 line
1.8.0.rc3.112.gdb88a5e
PATCH 3/3 pretty_print_commit(): do not append notes message
In reply to Junio C HamanoThe only case pretty_print_commit() appends notes message to the log message taken from the commit is when show_log() calls it with the after_message_body field set and the output format is not the userformat. No other users of this function sets this field in the pretty_print_context, as can be seen in the previous step.
Hoist the code to append the notes message to the caller.
Up to this point, no functionality change is intended.
--- log-tree.c | 2 ++ pretty.c | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-)
log-tree.c +2 -0
@@ -673,6 +673,8 @@ void show_log(struct rev_info *opt) ctx.reflog_info = opt->reflog_info; ctx.fmt = opt->commit_format;pretty_print_commit (&ctx, commit, &msgbuf); +if ((ctx.fmt !=CMIT_FMT_USERFORMAT ) && ctx.after_message_body) +strbuf_addbuf (&msgbuf, ctx.after_message_body);if (opt->add_signoff)append_signoff (&msgbuf, opt->add_signoff);
pretty.c +0 -3
@@ -1417,9 +1417,6 @@ void pretty_print_commit(const struct pretty_print_context *pp,if (pp->fmt ==CMIT_FMT_EMAIL && sb->len <= beginning_of_body)strbuf_addch (sb,'\n' ); -if (pp->after_message_body) -strbuf_addbuf (sb, pp->after_message_body); -free (reencoded); }
Signature · 1 line
1.8.0.rc3.112.gdb88a5e