MCPcopy Create free account
hub / github.com/git/git / format_trailers

Function format_trailers

trailer.c:1137–1197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1135}
1136
1137void format_trailers(const struct process_trailer_options *opts,
1138 struct list_head *trailers,
1139 struct strbuf *out)
1140{
1141 struct strbuf tok = STRBUF_INIT;
1142 struct strbuf val = STRBUF_INIT;
1143 size_t origlen = out->len;
1144 struct list_head *pos;
1145 struct trailer_item *item;
1146
1147 list_for_each(pos, trailers) {
1148 item = list_entry(pos, struct trailer_item, list);
1149 if (item->token) {
1150 strbuf_reset(&tok);
1151 strbuf_addstr(&tok, item->token);
1152 strbuf_reset(&val);
1153 strbuf_addstr(&val, item->value);
1154
1155 /*
1156 * Skip key/value pairs where the value was empty. This
1157 * can happen from trailers specified without a
1158 * separator, like `--trailer "Reviewed-by"` (no
1159 * corresponding value).
1160 */
1161 if (opts->trim_empty && !strlen(item->value))
1162 continue;
1163
1164 if (!opts->filter || opts->filter(&tok, opts->filter_data)) {
1165 if (opts->separator && out->len != origlen)
1166 strbuf_addbuf(out, opts->separator);
1167 if (!opts->value_only)
1168 strbuf_addbuf(out, &tok);
1169 if (!opts->key_only && !opts->value_only) {
1170 if (opts->key_value_separator)
1171 strbuf_addbuf(out, opts->key_value_separator);
1172 else {
1173 char c = last_non_space_char(tok.buf);
1174 if (c && !strchr(separators, c))
1175 strbuf_addf(out, "%c ", separators[0]);
1176 }
1177 }
1178 if (!opts->key_only)
1179 strbuf_addbuf(out, &val);
1180 if (!opts->separator)
1181 strbuf_addch(out, '\n');
1182 }
1183 } else if (!opts->only_trailers) {
1184 if (opts->separator && out->len != origlen) {
1185 strbuf_addbuf(out, opts->separator);
1186 }
1187 strbuf_addstr(out, item->value);
1188 if (opts->separator)
1189 strbuf_rtrim(out);
1190 else
1191 strbuf_addch(out, '\n');
1192 }
1193 }
1194

Callers 2

process_trailersFunction · 0.85

Calls 7

strbuf_addstrFunction · 0.85
strbuf_addbufFunction · 0.85
last_non_space_charFunction · 0.85
strbuf_addfFunction · 0.85
strbuf_addchFunction · 0.85
strbuf_rtrimFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected