]> git.ipfire.org Git - thirdparty/git.git/commitdiff
format_trailer_info(): move "fast path" to caller
authorLinus Arver <linusa@google.com>
Fri, 1 Mar 2024 00:14:45 +0000 (00:14 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 1 Mar 2024 18:35:42 +0000 (10:35 -0800)
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>
trailer.c

index cbd643cd1fe8b013a5f0d0b9b054a468345790e7..e92d0154d902f15d3054a862bacb82dbe6e186d8 100644 (file)
--- a/trailer.c
+++ b/trailer.c
@@ -1087,21 +1087,11 @@ void trailer_info_release(struct trailer_info *info)
 
 static void format_trailer_info(const struct process_trailer_options *opts,
                                const struct trailer_info *info,
-                               const char *msg,
                                struct strbuf *out)
 {
        size_t origlen = out->len;
        size_t i;
 
-       /* If we want the whole block untouched, we can take the fast path. */
-       if (!opts->only_trailers && !opts->unfold && !opts->filter &&
-           !opts->separator && !opts->key_only && !opts->value_only &&
-           !opts->key_value_separator) {
-               strbuf_add(out, msg + info->trailer_block_start,
-                          info->trailer_block_end - info->trailer_block_start);
-               return;
-       }
-
        for (i = 0; i < info->trailer_nr; i++) {
                char *trailer = info->trailers[i];
                ssize_t separator_pos = find_separator(trailer, separators);
@@ -1153,7 +1143,15 @@ void format_trailers_from_commit(const struct process_trailer_options *opts,
        struct trailer_info info;
 
        trailer_info_get(opts, msg, &info);
-       format_trailer_info(opts, &info, msg, out);
+       /* If we want the whole block untouched, we can take the fast path. */
+       if (!opts->only_trailers && !opts->unfold && !opts->filter &&
+           !opts->separator && !opts->key_only && !opts->value_only &&
+           !opts->key_value_separator) {
+               strbuf_add(out, msg + info.trailer_block_start,
+                          info.trailer_block_end - info.trailer_block_start);
+       } else
+               format_trailer_info(opts, &info, out);
+
        trailer_info_release(&info);
 }