trailer: finish formatting unification

Rename format_trailer_info() to format_trailers(). Finally, both interpret-trailers and format_trailers_from_commit() can call "format_trailers()"! Update the comment in <trailer.h> to remove the (now obsolete) caveats about format_trailers_from_commit(). Those caveats come from a388b10fc1 (pretty: move trailer formatting to trailer.c, 2017-08-15) where it says: 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. which suggests format_trailers_from_commit() started out from pretty.c and did not have access to all of the trailer implementation internals, and was never intended to replace (unify) the formatting machinery in trailer.c. The refactors leading up to this commit (as well as additional refactors that will follow) expose additional functions publicly, and is therefore choosing option (1) as described in a388b10fc1. Signed-off-by: Linus Arver <linusa@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Arver committed Mar 15, 2024 at 06:55 UTC 3452d173241c8b87ecdd67f91f594cb14327e394
3 files changed +9 -16
builtin/interpret-trailers.c
+1 -1
@@ -171,7 +171,7 @@ static void interpret_trailers(const struct process_trailer_options *opts,
171 }
172
173 /* Print trailer block. */
174 - format_trailer_info(opts, &head, &trailer_block);
174 + format_trailers(opts, &head, &trailer_block);
175 free_trailers(&head);
176 fwrite(trailer_block.buf, 1, trailer_block.len, outfile);
177 strbuf_release(&trailer_block);
trailer.c
+4 -4
@@ -1052,9 +1052,9 @@ void trailer_info_release(struct trailer_info *info)
1052 free(info->trailers);
1053 }
1054
1055 -void format_trailer_info(const struct process_trailer_options *opts,
1056 - struct list_head *trailers,
1057 - struct strbuf *out)
1055 +void format_trailers(const struct process_trailer_options *opts,
1056 + struct list_head *trailers,
1057 + struct strbuf *out)
1058 {
1059 size_t origlen = out->len;
1060 struct list_head *pos;
@@ -1128,7 +1128,7 @@ void format_trailers_from_commit(const struct process_trailer_options *opts,
1128 strbuf_add(out, msg + info.trailer_block_start,
1129 info.trailer_block_end - info.trailer_block_start);
1130 } else
1131 - format_trailer_info(opts, &trailer_objects, out);
1131 + format_trailers(opts, &trailer_objects, out);
1132
1133 free_trailers(&trailer_objects);
1134 trailer_info_release(&info);
trailer.h
+4 -11
@@ -101,23 +101,16 @@ void trailer_info_get(const struct process_trailer_options *,
101 void trailer_info_release(struct trailer_info *info);
102
103 void trailer_config_init(void);
104 -void format_trailer_info(const struct process_trailer_options *,
104 +void format_trailers(const struct process_trailer_options *,
105 struct list_head *trailers,
106 struct strbuf *out);
107 void free_trailers(struct list_head *);
108
109 /*
110 - * Format the trailers from the commit msg "msg" into the strbuf "out".
111 - * Note two caveats about "opts":
112 - *
113 - * - this is primarily a helper for pretty.c, and not
114 - * all of the flags are supported.
115 - *
116 - * - this differs from process_trailers slightly in that we always format
117 - * only the trailer block itself, even if the "only_trailers" option is not
118 - * set.
110 + * Convenience function to format the trailers from the commit msg "msg" into
111 + * the strbuf "out". Reuses format_trailers() internally.
112 */
120 -void format_trailers_from_commit(const struct process_trailer_options *opts,
113 +void format_trailers_from_commit(const struct process_trailer_options *,
114 const char *msg,
115 struct strbuf *out);
116