commit: prepare logmsg_reencode to handle arbitrary repositories

Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Nov 13, 2018 at 16:12 UTC 424510ed193fdc49cacc832d8795677d0cc54461
3 files changed +24 -6
commit.h
+8
@@ -180,6 +180,14 @@ extern int has_non_ascii(const char *text);
180 extern const char *logmsg_reencode(const struct commit *commit,
181 char **commit_encoding,
182 const char *output_encoding);
183 +const char *repo_logmsg_reencode(struct repository *r,
184 + const struct commit *commit,
185 + char **commit_encoding,
186 + const char *output_encoding);
187 +#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
188 +#define logmsg_reencode(c, enc, out) repo_logmsg_reencode(the_repository, c, enc, out)
189 +#endif
190 +
191 extern const char *skip_blank_lines(const char *msg);
192
193 /** Removes the first commit from a list sorted by date, and adds all
contrib/coccinelle/the_repository.pending.cocci
+9
@@ -123,3 +123,12 @@ expression F;
123 - unuse_commit_buffer(
124 + repo_unuse_commit_buffer(the_repository,
125 E, F);
126 +
127 +@@
128 +expression E;
129 +expression F;
130 +expression G;
131 +@@
132 +- logmsg_reencode(
133 ++ repo_logmsg_reencode(the_repository,
134 + E, F, G);
pretty.c
+7 -6
@@ -595,14 +595,15 @@ static char *replace_encoding_header(char *buf, const char *encoding)
595 return strbuf_detach(&tmp, NULL);
596 }
597
598 -const char *logmsg_reencode(const struct commit *commit,
599 - char **commit_encoding,
600 - const char *output_encoding)
598 +const char *repo_logmsg_reencode(struct repository *r,
599 + const struct commit *commit,
600 + char **commit_encoding,
601 + const char *output_encoding)
602 {
603 static const char *utf8 = "UTF-8";
604 const char *use_encoding;
605 char *encoding;
605 - const char *msg = get_commit_buffer(commit, NULL);
606 + const char *msg = repo_get_commit_buffer(r, commit, NULL);
607 char *out;
608
609 if (!output_encoding || !*output_encoding) {
@@ -630,7 +631,7 @@ const char *logmsg_reencode(const struct commit *commit,
631 * the cached copy from get_commit_buffer, we need to duplicate it
632 * to avoid munging the cached copy.
633 */
633 - if (msg == get_cached_commit_buffer(the_repository, commit, NULL))
634 + if (msg == get_cached_commit_buffer(r, commit, NULL))
635 out = xstrdup(msg);
636 else
637 out = (char *)msg;
@@ -644,7 +645,7 @@ const char *logmsg_reencode(const struct commit *commit,
645 */
646 out = reencode_string(msg, output_encoding, use_encoding);
647 if (out)
647 - unuse_commit_buffer(commit, msg);
648 + repo_unuse_commit_buffer(r, commit, msg);
649 }
650
651 /*