[PATCH 184/194] pretty: add repository argument to format_commit_message

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

 



Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx>
---
 archive.c                                  |  3 ++-
 builtin/commit.c                           | 17 +++++++++++------
 builtin/fmt-merge-msg.c                    |  2 +-
 builtin/notes.c                            |  3 ++-
 builtin/shortlog.c                         |  5 +++--
 contrib/coccinelle/submodule_reading.cocci | 10 ++++++++++
 log-tree.c                                 |  2 +-
 notes-cache.c                              |  2 +-
 pretty.c                                   |  5 +++--
 pretty.h                                   |  4 +++-
 sha1_name.c                                |  3 ++-
 submodule.c                                |  5 +++--
 t/helper/test-revision-walking.c           |  2 +-
 13 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/archive.c b/archive.c
index 6f38a5cf55..cb0b1d595c 100644
--- a/archive.c
+++ b/archive.c
@@ -56,7 +56,8 @@ static void format_subst(const struct commit *commit,
 		strbuf_add(&fmt, b + 8, c - b - 8);
 
 		strbuf_add(buf, src, b - src);
-		format_commit_message(commit, fmt.buf, buf, &ctx);
+		format_commit_message(the_repository, commit, fmt.buf, buf,
+				      &ctx);
 		len -= c + 1 - src;
 		src  = c + 1;
 	}
diff --git a/builtin/commit.c b/builtin/commit.c
index c903893767..a6ddf6dd23 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -696,7 +696,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 			if (!c)
 				die(_("could not lookup commit %s"), squash_message);
 			ctx.output_encoding = get_commit_output_encoding();
-			format_commit_message(c, "squash! %s\n\n", &sb,
+			format_commit_message(the_repository, c,
+					      "squash! %s\n\n", &sb,
 					      &ctx);
 		}
 	}
@@ -729,7 +730,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		if (!commit)
 			die(_("could not lookup commit %s"), fixup_message);
 		ctx.output_encoding = get_commit_output_encoding();
-		format_commit_message(commit, "fixup! %s\n\n",
+		format_commit_message(the_repository, commit, "fixup! %s\n\n",
 				      &sb, &ctx);
 		hook_arg1 = "message";
 	} else if (!stat(git_path_merge_msg(the_repository), &statbuf)) {
@@ -1069,7 +1070,8 @@ static const char *find_author_by_nickname(const char *name)
 		struct pretty_print_context ctx = {0};
 		ctx.date_mode.type = DATE_NORMAL;
 		strbuf_release(&buf);
-		format_commit_message(commit, "%aN <%aE>", &buf, &ctx);
+		format_commit_message(the_repository, commit, "%aN <%aE>",
+				      &buf, &ctx);
 		clear_mailmap(&mailmap);
 		return strbuf_detach(&buf, NULL);
 	}
@@ -1472,15 +1474,18 @@ static void print_summary(const char *prefix, const struct object_id *oid,
 
 	strbuf_addstr(&format, "format:%h] %s");
 
-	format_commit_message(commit, "%an <%ae>", &author_ident, &pctx);
-	format_commit_message(commit, "%cn <%ce>", &committer_ident, &pctx);
+	format_commit_message(the_repository, commit, "%an <%ae>",
+			      &author_ident, &pctx);
+	format_commit_message(the_repository, commit, "%cn <%ce>",
+			      &committer_ident, &pctx);
 	if (strbuf_cmp(&author_ident, &committer_ident)) {
 		strbuf_addstr(&format, "\n Author: ");
 		strbuf_addbuf_percentquote(&format, &author_ident);
 	}
 	if (author_date_is_interesting()) {
 		struct strbuf date = STRBUF_INIT;
-		format_commit_message(commit, "%ad", &date, &pctx);
+		format_commit_message(the_repository, commit, "%ad", &date,
+				      &pctx);
 		strbuf_addstr(&format, "\n Date: ");
 		strbuf_addbuf_percentquote(&format, &date);
 		strbuf_release(&date);
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 6dedb92d61..591cf95346 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -374,7 +374,7 @@ static void shortlog(const char *name,
 		if (subjects.nr > limit)
 			continue;
 
-		format_commit_message(commit, "%s", &sb, &ctx);
+		format_commit_message(the_repository, commit, "%s", &sb, &ctx);
 		strbuf_ltrim(&sb);
 
 		if (!sb.len)
diff --git a/builtin/notes.c b/builtin/notes.c
index 9100ac5ce0..8633da1d5e 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -736,7 +736,8 @@ static int merge_commit(struct notes_merge_options *o)
 
 	/* Reuse existing commit message in reflog message */
 	memset(&pretty_ctx, 0, sizeof(pretty_ctx));
-	format_commit_message(partial, "%s", &msg, &pretty_ctx);
+	format_commit_message(the_repository, partial, "%s", &msg,
+			      &pretty_ctx);
 	strbuf_trim(&msg);
 	strbuf_insert(&msg, 0, "notes: ", 7);
 	update_ref(msg.buf, o->local_ref, &oid,
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index e29875b843..61a8c9a6e9 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -169,12 +169,13 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
 		(log->email ? "%cN <%cE>" : "%cN") :
 		(log->email ? "%aN <%aE>" : "%aN");
 
-	format_commit_message(commit, fmt, &author, &ctx);
+	format_commit_message(the_repository, commit, fmt, &author, &ctx);
 	if (!log->summary) {
 		if (log->user_format)
 			pretty_print_commit(&ctx, commit, &oneline);
 		else
-			format_commit_message(commit, "%s", &oneline, &ctx);
+			format_commit_message(the_repository, commit, "%s",
+					      &oneline, &ctx);
 	}
 
 	insert_one_record(log, author.buf, oneline.len ? oneline.buf : "<none>");
diff --git a/contrib/coccinelle/submodule_reading.cocci b/contrib/coccinelle/submodule_reading.cocci
index b3e3d88626..30935ac21d 100644
--- a/contrib/coccinelle/submodule_reading.cocci
+++ b/contrib/coccinelle/submodule_reading.cocci
@@ -14,3 +14,13 @@ expression G;
  logmsg_reencode(
 +the_repository,
  E, F, G)
+
+@@
+expression E;
+expression F;
+expression G;
+expression H;
+@@
+ format_commit_message(
++the_repository,
+ E, F, G, H)
diff --git a/log-tree.c b/log-tree.c
index c6d2883190..e32a2fe71c 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -341,7 +341,7 @@ void fmt_output_commit(struct strbuf *filename,
 	struct pretty_print_context ctx = {0};
 	struct strbuf subject = STRBUF_INIT;
 
-	format_commit_message(commit, "%f", &subject, &ctx);
+	format_commit_message(the_repository, commit, "%f", &subject, &ctx);
 	fmt_output_subject(filename, subject.buf, info);
 	strbuf_release(&subject);
 }
diff --git a/notes-cache.c b/notes-cache.c
index a4a6ccab97..89c2284192 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -21,7 +21,7 @@ static int notes_cache_match_validity(const char *ref, const char *validity)
 		return 0;
 
 	memset(&pretty_ctx, 0, sizeof(pretty_ctx));
-	format_commit_message(commit, "%s", &msg, &pretty_ctx);
+	format_commit_message(the_repository, commit, "%s", &msg, &pretty_ctx);
 	strbuf_trim(&msg);
 
 	ret = !strcmp(msg.buf, validity);
diff --git a/pretty.c b/pretty.c
index a0c95280f6..30d53369b5 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1503,7 +1503,7 @@ void userformat_find_requirements(const char *fmt, struct userformat_want *w)
 	strbuf_release(&dummy);
 }
 
-void format_commit_message(const struct commit *commit,
+void format_commit_message_the_repository(const struct commit *commit,
 			   const char *format, struct strbuf *sb,
 			   const struct pretty_print_context *pretty_ctx)
 {
@@ -1796,7 +1796,8 @@ void pretty_print_commit(struct pretty_print_context *pp,
 	int need_8bit_cte = pp->need_8bit_cte;
 
 	if (pp->fmt == CMIT_FMT_USERFORMAT) {
-		format_commit_message(commit, user_format, sb, pp);
+		format_commit_message(the_repository, commit, user_format, sb,
+				      pp);
 		return;
 	}
 
diff --git a/pretty.h b/pretty.h
index 5c85d94e33..14af7df4e8 100644
--- a/pretty.h
+++ b/pretty.h
@@ -99,7 +99,9 @@ void pp_remainder(struct pretty_print_context *pp, const char **msg_p,
  * Put the result to "sb".
  * Please use this function for custom formats.
  */
-void format_commit_message(const struct commit *commit,
+#define format_commit_message(r, c, f, s, p) \
+	format_commit_message_##r(c, f, s, p)
+void format_commit_message_the_repository(const struct commit *commit,
 			const char *format, struct strbuf *sb,
 			const struct pretty_print_context *context);
 
diff --git a/sha1_name.c b/sha1_name.c
index ee889daead..d6c2cf969f 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -378,7 +378,8 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
 		if (commit) {
 			struct pretty_print_context pp = {0};
 			pp.date_mode.type = DATE_SHORT;
-			format_commit_message(commit, " %ad - %s", &desc, &pp);
+			format_commit_message(the_repository, commit,
+					      " %ad - %s", &desc, &pp);
 		}
 	} else if (type == OBJ_TAG) {
 		struct tag *tag = lookup_tag(the_repository, oid);
diff --git a/submodule.c b/submodule.c
index af4a1d2cea..b399cf46e4 100644
--- a/submodule.c
+++ b/submodule.c
@@ -452,7 +452,8 @@ static void print_submodule_summary(struct rev_info *rev, struct diff_options *o
 		ctx.date_mode = rev->date_mode;
 		ctx.output_encoding = get_log_output_encoding();
 		strbuf_setlen(&sb, 0);
-		format_commit_message(commit, format, &sb, &ctx);
+		format_commit_message(the_repository, commit, format, &sb,
+				      &ctx);
 		strbuf_addch(&sb, '\n');
 		if (commit->object.flags & SYMMETRIC_LEFT)
 			diff_emit_submodule_del(o, sb.buf);
@@ -1786,7 +1787,7 @@ static void print_commit(struct commit *commit)
 	struct strbuf sb = STRBUF_INIT;
 	struct pretty_print_context ctx = {0};
 	ctx.date_mode.type = DATE_NORMAL;
-	format_commit_message(commit, " %h: %m %s", &sb, &ctx);
+	format_commit_message(the_repository, commit, " %h: %m %s", &sb, &ctx);
 	fprintf(stderr, "%s\n", sb.buf);
 	strbuf_release(&sb);
 }
diff --git a/t/helper/test-revision-walking.c b/t/helper/test-revision-walking.c
index b8e6fe1d00..59599410ce 100644
--- a/t/helper/test-revision-walking.c
+++ b/t/helper/test-revision-walking.c
@@ -18,7 +18,7 @@ static void print_commit(struct commit *commit)
 	struct strbuf sb = STRBUF_INIT;
 	struct pretty_print_context ctx = {0};
 	ctx.date_mode.type = DATE_NORMAL;
-	format_commit_message(commit, " %m %s", &sb, &ctx);
+	format_commit_message(the_repository, commit, " %m %s", &sb, &ctx);
 	printf("%s\n", sb.buf);
 	strbuf_release(&sb);
 }
-- 
2.15.1.433.g936d1b9894.dirty




[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]

  Powered by Linux