[WIP-PATCH 2/3] pretty: prepare notes message at a centralized place

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Instead of passing a boolean show_notes around, pass an optional
string buffer that is to be inserted after the log message proper is
shown.

Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx>
---
 commit.h   |  2 +-
 log-tree.c | 15 ++++++++++++++-
 pretty.c   | 10 ++++------
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/commit.h b/commit.h
index a822af8..e119788 100644
--- a/commit.h
+++ b/commit.h
@@ -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;
 };
diff --git a/log-tree.c b/log-tree.c
index c894930..95ff405 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -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)
diff --git a/pretty.c b/pretty.c
index c311a68..bdd991c 100644
--- a/pretty.c
+++ b/pretty.c
@@ -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);
 }
-- 
1.8.0.rc3.112.gdb88a5e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]