Skip to content

Commit a388b10

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 99e09da commit a388b10

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

pretty.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -870,16 +870,6 @@ const char *format_subject(struct strbuf *sb, const char *msg,
870870
return msg;
871871
}
872872

873-
static void format_trailers(struct strbuf *sb, const char *msg)
874-
{
875-
struct trailer_info info;
876-
877-
trailer_info_get(&info, msg);
878-
strbuf_add(sb, info.trailer_start,
879-
info.trailer_end - info.trailer_start);
880-
trailer_info_release(&info);
881-
}
882-
883873
static void parse_commit_message(struct format_commit_context *c)
884874
{
885875
const char *msg = c->message + c->message_off;
@@ -1273,7 +1263,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
12731263
}
12741264

12751265
if (starts_with(placeholder, "(trailers)")) {
1276-
format_trailers(sb, msg + c->subject_off);
1266+
struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT;
1267+
format_trailers_from_commit(sb, msg + c->subject_off, &opts);
12771268
return strlen("(trailers)");
12781269
}
12791270

trailer.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,3 +1090,21 @@ void trailer_info_release(struct trailer_info *info)
10901090
free(info->trailers[i]);
10911091
free(info->trailers);
10921092
}
1093+
1094+
static void format_trailer_info(struct strbuf *out,
1095+
const struct trailer_info *info,
1096+
const struct process_trailer_options *opts)
1097+
{
1098+
strbuf_add(out, info->trailer_start,
1099+
info->trailer_end - info->trailer_start);
1100+
}
1101+
1102+
void format_trailers_from_commit(struct strbuf *out, const char *msg,
1103+
const struct process_trailer_options *opts)
1104+
{
1105+
struct trailer_info info;
1106+
1107+
trailer_info_get(&info, msg);
1108+
format_trailer_info(out, &info, opts);
1109+
trailer_info_release(&info);
1110+
}

trailer.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,18 @@ void trailer_info_get(struct trailer_info *info, const char *str);
4040

4141
void trailer_info_release(struct trailer_info *info);
4242

43+
/*
44+
* Format the trailers from the commit msg "msg" into the strbuf "out".
45+
* Note two caveats about "opts":
46+
*
47+
* - this is primarily a helper for pretty.c, and not
48+
* all of the flags are supported.
49+
*
50+
* - this differs from process_trailers slightly in that we always format
51+
* only the trailer block itself, even if the "only_trailers" option is not
52+
* set.
53+
*/
54+
void format_trailers_from_commit(struct strbuf *out, const char *msg,
55+
const struct process_trailer_options *opts);
56+
4357
#endif /* TRAILER_H */

0 commit comments

Comments
 (0)