diff options
author | Linus Arver <linusa@google.com> | 2024-03-15 06:55:01 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-03-15 10:10:24 -0700 |
commit | 65b4ad82b81e1a1f4afbb7f4974384d7db479c0a (patch) | |
tree | b3ba05a4e5ba866e4458f31e5ca81f82abbe8530 /trailer.c | |
parent | 4f9b731bdeccffa1b13e5edf4bc0428b8d49704e (diff) | |
download | git-65b4ad82b81e1a1f4afbb7f4974384d7db479c0a.tar.gz |
format_trailer_info(): use trailer_item objects
This is another preparatory refactor to unify the trailer formatters.
Make format_trailer_info() operate on trailer_item objects, not the raw
string array.
We will continue to make improvements, culminating in the renaming of
format_trailer_info() to format_trailers(), at which point the
unification of these formatters will be complete.
In order to avoid breaking t4205 and t6300, flip *_success to *_failure
in the affected test cases. Add a temporary
"test_trailer_option_expect_failure" wrapper which we will use along
with "test_expect_failure" in the next commit to avoid breaking tests.
When the dust settles with the refactors a few more commits later, we
will drop the use of *_failure to make the tests truly pass again.
When the preparatory refactors are complete,
we'll be able to drop the use of *_failure that we introduce here.
Signed-off-by: Linus Arver <linusa@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'trailer.c')
-rw-r--r-- | trailer.c | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -1085,21 +1085,21 @@ void trailer_info_release(struct trailer_info *info) } static void format_trailer_info(const struct process_trailer_options *opts, - const struct trailer_info *info, + struct list_head *trailers, struct strbuf *out) { size_t origlen = out->len; - size_t i; - - for (i = 0; i < info->trailer_nr; i++) { - char *trailer = info->trailers[i]; - ssize_t separator_pos = find_separator(trailer, separators); + struct list_head *pos; + struct trailer_item *item; - if (separator_pos >= 1) { + list_for_each(pos, trailers) { + item = list_entry(pos, struct trailer_item, list); + if (item->token) { struct strbuf tok = STRBUF_INIT; struct strbuf val = STRBUF_INIT; + strbuf_addstr(&tok, item->token); + strbuf_addstr(&val, item->value); - parse_trailer(&tok, &val, NULL, trailer, separator_pos); if (!opts->filter || opts->filter(&tok, opts->filter_data)) { if (opts->unfold) unfold_value(&val); @@ -1126,13 +1126,12 @@ static void format_trailer_info(const struct process_trailer_options *opts, if (opts->separator && out->len != origlen) { strbuf_addbuf(out, opts->separator); } - strbuf_addstr(out, trailer); + strbuf_addstr(out, item->value); if (opts->separator) { strbuf_rtrim(out); } } } - } void format_trailers_from_commit(const struct process_trailer_options *opts, @@ -1151,7 +1150,7 @@ void format_trailers_from_commit(const struct process_trailer_options *opts, strbuf_add(out, msg + info.trailer_block_start, info.trailer_block_end - info.trailer_block_start); } else - format_trailer_info(opts, &info, out); + format_trailer_info(opts, &trailer_objects, out); free_trailers(&trailer_objects); trailer_info_release(&info); |