pretty: move trailer formatting to trailer.c

The next commit will add many features to the %(trailer)
placeholder in pretty.c. We'll need to access some internal
functions of trailer.c for that, so our options are either:

  1. expose those functions publicly

or

  2. make an entry point into trailer.c to do the formatting

Doing (2) ends up exposing less surface area, though do note
that caveats in the docstring of the new function.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King
2017-08-15 06:23:56 -04:00
committed by Junio C Hamano
parent 99e09dafd7
commit a388b10fc1
3 changed files with 34 additions and 11 deletions

View File

@ -870,16 +870,6 @@ const char *format_subject(struct strbuf *sb, const char *msg,
return msg;
}
static void format_trailers(struct strbuf *sb, const char *msg)
{
struct trailer_info info;
trailer_info_get(&info, msg);
strbuf_add(sb, info.trailer_start,
info.trailer_end - info.trailer_start);
trailer_info_release(&info);
}
static void parse_commit_message(struct format_commit_context *c)
{
const char *msg = c->message + c->message_off;
@ -1273,7 +1263,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
}
if (starts_with(placeholder, "(trailers)")) {
format_trailers(sb, msg + c->subject_off);
struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT;
format_trailers_from_commit(sb, msg + c->subject_off, &opts);
return strlen("(trailers)");
}