| 1015 | } |
| 1016 | |
| 1017 | static struct trailer_block *trailer_block_get(const struct process_trailer_options *opts, |
| 1018 | const char *str) |
| 1019 | { |
| 1020 | struct trailer_block *trailer_block = trailer_block_new(); |
| 1021 | size_t end_of_log_message = 0, trailer_block_start = 0; |
| 1022 | struct strbuf **trailer_lines, **ptr; |
| 1023 | char **trailer_strings = NULL; |
| 1024 | size_t nr = 0, alloc = 0; |
| 1025 | char **last = NULL; |
| 1026 | |
| 1027 | trailer_config_init(); |
| 1028 | |
| 1029 | end_of_log_message = find_end_of_log_message(str, opts->no_divider); |
| 1030 | trailer_block_start = find_trailer_block_start(str, end_of_log_message); |
| 1031 | |
| 1032 | trailer_lines = strbuf_split_buf(str + trailer_block_start, |
| 1033 | end_of_log_message - trailer_block_start, |
| 1034 | '\n', |
| 1035 | 0); |
| 1036 | for (ptr = trailer_lines; *ptr; ptr++) { |
| 1037 | if (last && isspace((*ptr)->buf[0])) { |
| 1038 | struct strbuf sb = STRBUF_INIT; |
| 1039 | strbuf_attach(&sb, *last, strlen(*last), strlen(*last) + 1); |
| 1040 | strbuf_addbuf(&sb, *ptr); |
| 1041 | *last = strbuf_detach(&sb, NULL); |
| 1042 | continue; |
| 1043 | } |
| 1044 | ALLOC_GROW(trailer_strings, nr + 1, alloc); |
| 1045 | trailer_strings[nr] = strbuf_detach(*ptr, NULL); |
| 1046 | last = find_separator(trailer_strings[nr], separators) >= 1 |
| 1047 | ? &trailer_strings[nr] |
| 1048 | : NULL; |
| 1049 | nr++; |
| 1050 | } |
| 1051 | strbuf_list_free(trailer_lines); |
| 1052 | |
| 1053 | trailer_block->blank_line_before_trailer = ends_with_blank_line(str, |
| 1054 | trailer_block_start); |
| 1055 | trailer_block->start = trailer_block_start; |
| 1056 | trailer_block->end = end_of_log_message; |
| 1057 | trailer_block->trailers = trailer_strings; |
| 1058 | trailer_block->trailer_nr = nr; |
| 1059 | |
| 1060 | return trailer_block; |
| 1061 | } |
| 1062 | |
| 1063 | /* |
| 1064 | * Parse trailers in "str", populating the trailer_block and "trailer_objects" |
no test coverage detected