pretty: prepare format_commit_message to handle arbitrary repositories

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Stefan Beller 2018-11-13 16:13:00 -08:00 committed by Junio C Hamano
parent 424510ed19
commit f54fbf5eef
3 changed files with 24 additions and 8 deletions

View file

@ -132,3 +132,13 @@ expression G;
- logmsg_reencode(
+ repo_logmsg_reencode(the_repository,
E, F, G);
@@
expression E;
expression F;
expression G;
expression H;
@@
- format_commit_message(
+ repo_format_commit_message(the_repository,
E, F, G, H);

View file

@ -1508,9 +1508,10 @@ void userformat_find_requirements(const char *fmt, struct userformat_want *w)
strbuf_release(&dummy);
}
void format_commit_message(const struct commit *commit,
const char *format, struct strbuf *sb,
const struct pretty_print_context *pretty_ctx)
void repo_format_commit_message(struct repository *r,
const struct commit *commit,
const char *format, struct strbuf *sb,
const struct pretty_print_context *pretty_ctx)
{
struct format_commit_context context;
const char *output_enc = pretty_ctx->output_encoding;
@ -1524,9 +1525,9 @@ void format_commit_message(const struct commit *commit,
* convert a commit message to UTF-8 first
* as far as 'format_commit_item' assumes it in UTF-8
*/
context.message = logmsg_reencode(commit,
&context.commit_encoding,
utf8);
context.message = repo_logmsg_reencode(r, commit,
&context.commit_encoding,
utf8);
strbuf_expand(sb, format, format_commit_item, &context);
rewrap_message_tail(sb, &context, 0, 0, 0);
@ -1550,7 +1551,7 @@ void format_commit_message(const struct commit *commit,
}
free(context.commit_encoding);
unuse_commit_buffer(commit, context.message);
repo_unuse_commit_buffer(r, commit, context.message);
}
static void pp_header(struct pretty_print_context *pp,

View file

@ -103,9 +103,14 @@ 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,
void repo_format_commit_message(struct repository *r,
const struct commit *commit,
const char *format, struct strbuf *sb,
const struct pretty_print_context *context);
#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
#define format_commit_message(c, f, s, con) \
repo_format_commit_message(the_repository, c, f, s, con)
#endif
/*
* Parse given arguments from "arg", check it for correctness and