format_trailer_info(): move "fast path" to caller

This is another preparatory refactor to unify the trailer formatters. This allows us to drop the "msg" parameter from format_trailer_info(), so that it take 3 parameters, similar to format_trailers() which also takes 3 parameters: void format_trailers(const struct process_trailer_options *opts, struct list_head *trailers, struct strbuf *out) The short-term goal is to make format_trailer_info() be smart enough to deprecate format_trailers(). And then ultimately we will rename format_trailer_info() to format_trailers(). Signed-off-by: Linus Arver <linusa@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Arver committed Mar 1, 2024 at 00:14 UTC 2c948a78fd449a03c114802772acd4abfec25bba
1 file changed +9 -11
trailer.c
+9 -11
@@ -1087,21 +1087,11 @@ void trailer_info_release(struct trailer_info *info)
1087
1088 static void format_trailer_info(const struct process_trailer_options *opts,
1089 const struct trailer_info *info,
1090 - const char *msg,
1090 struct strbuf *out)
1091 {
1092 size_t origlen = out->len;
1093 size_t i;
1094
1096 - /* If we want the whole block untouched, we can take the fast path. */
1097 - if (!opts->only_trailers && !opts->unfold && !opts->filter &&
1098 - !opts->separator && !opts->key_only && !opts->value_only &&
1099 - !opts->key_value_separator) {
1100 - strbuf_add(out, msg + info->trailer_block_start,
1101 - info->trailer_block_end - info->trailer_block_start);
1102 - return;
1103 - }
1104 -
1095 for (i = 0; i < info->trailer_nr; i++) {
1096 char *trailer = info->trailers[i];
1097 ssize_t separator_pos = find_separator(trailer, separators);
@@ -1153,7 +1143,15 @@ void format_trailers_from_commit(const struct process_trailer_options *opts,
1143 struct trailer_info info;
1144
1145 trailer_info_get(opts, msg, &info);
1156 - format_trailer_info(opts, &info, msg, out);
1146 + /* If we want the whole block untouched, we can take the fast path. */
1147 + if (!opts->only_trailers && !opts->unfold && !opts->filter &&
1148 + !opts->separator && !opts->key_only && !opts->value_only &&
1149 + !opts->key_value_separator) {
1150 + strbuf_add(out, msg + info.trailer_block_start,
1151 + info.trailer_block_end - info.trailer_block_start);
1152 + } else
1153 + format_trailer_info(opts, &info, out);
1154 +
1155 trailer_info_release(&info);
1156 }
1157