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>
Stefan Beller committed
Nov 13, 2018 at 16:13 UTC
f54fbf5eefb9740a318344fe400f54f047cc4bf1
3 files changed
+24
-8
contrib/coccinelle/the_repository.pending.cocci
+10
@@ -132,3 +132,13 @@ expression G;
132
- logmsg_reencode(
133
+ repo_logmsg_reencode(the_repository,
134
E, F, G);
135
+
136
+@@
137
+expression E;
138
+expression F;
139
+expression G;
140
+expression H;
141
+@@
142
+- format_commit_message(
143
++ repo_format_commit_message(the_repository,
144
+ E, F, G, H);
pretty.c
+8
-7
@@ -1508,9 +1508,10 @@ void userformat_find_requirements(const char *fmt, struct userformat_want *w)
1508
strbuf_release(&dummy);
1509
}
1510
1511
-void format_commit_message(const struct commit *commit,
1512
- const char *format, struct strbuf *sb,
1513
- const struct pretty_print_context *pretty_ctx)
1511
+void repo_format_commit_message(struct repository *r,
1512
+ const struct commit *commit,
1513
+ const char *format, struct strbuf *sb,
1514
+ const struct pretty_print_context *pretty_ctx)
1515
{
1516
struct format_commit_context context;
1517
const char *output_enc = pretty_ctx->output_encoding;
@@ -1524,9 +1525,9 @@ void format_commit_message(const struct commit *commit,
1525
* convert a commit message to UTF-8 first
1526
* as far as 'format_commit_item' assumes it in UTF-8
1527
*/
1527
- context.message = logmsg_reencode(commit,
1528
- &context.commit_encoding,
1529
- utf8);
1528
+ context.message = repo_logmsg_reencode(r, commit,
1529
+ &context.commit_encoding,
1530
+ utf8);
1531
1532
strbuf_expand(sb, format, format_commit_item, &context);
1533
rewrap_message_tail(sb, &context, 0, 0, 0);
@@ -1550,7 +1551,7 @@ void format_commit_message(const struct commit *commit,
1551
}
1552
1553
free(context.commit_encoding);
1553
- unuse_commit_buffer(commit, context.message);
1554
+ repo_unuse_commit_buffer(r, commit, context.message);
1555
}
1556
1557
static void pp_header(struct pretty_print_context *pp,
pretty.h
+6
-1
@@ -103,9 +103,14 @@ void pp_remainder(struct pretty_print_context *pp, const char **msg_p,
103
* Put the result to "sb".
104
* Please use this function for custom formats.
105
*/
106
-void format_commit_message(const struct commit *commit,
106
+void repo_format_commit_message(struct repository *r,
107
+ const struct commit *commit,
108
const char *format, struct strbuf *sb,
109
const struct pretty_print_context *context);
110
+#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
111
+#define format_commit_message(c, f, s, con) \
112
+ repo_format_commit_message(the_repository, c, f, s, con)
113
+#endif
114
115
/*
116
* Parse given arguments from "arg", check it for correctness and