144
return '\0';
145
}
146
147
-static void print_tok_val(struct strbuf *out, const char *tok, const char *val)
148
-{
149
- char c;
150
-
151
- if (!tok) {
152
- strbuf_addf(out, "%s\n", val);
153
- return;
154
- }
155
-
156
- c = last_non_space_char(tok);
157
- if (!c)
158
- return;
159
- if (strchr(separators, c))
160
- strbuf_addf(out, "%s%s\n", tok, val);
161
- else
162
- strbuf_addf(out, "%s%c %s\n", tok, separators[0], val);
163
-}
164
-
165
-void format_trailers(const struct process_trailer_options *opts,
166
- struct list_head *trailers,
167
- struct strbuf *out)
168
-{
169
- struct list_head *pos;
170
- struct trailer_item *item;
171
- list_for_each(pos, trailers) {
172
- item = list_entry(pos, struct trailer_item, list);
173
- if ((!opts->trim_empty || strlen(item->value) > 0) &&
174
- (!opts->only_trailers || item->token))
175
- print_tok_val(out, item->token, item->value);
176
- }
177
-}
178
-
147
static struct trailer_item *trailer_from_arg(struct arg_item *arg_tok)
148
{
149
struct trailer_item *new_item = xcalloc(1, sizeof(*new_item));
1052
free(info->trailers);
1053
}
1054
1087
-static void format_trailer_info(const struct process_trailer_options *opts,
1088
- struct list_head *trailers,
1089
- struct strbuf *out)
1055
+void format_trailer_info(const struct process_trailer_options *opts,
1056
+ struct list_head *trailers,
1057
+ struct strbuf *out)
1058
{
1059
size_t origlen = out->len;
1060
struct list_head *pos;
1068
strbuf_addstr(&tok, item->token);
1069
strbuf_addstr(&val, item->value);
1070
1071
+ /*
1072
+ * Skip key/value pairs where the value was empty. This
1073
+ * can happen from trailers specified without a
1074
+ * separator, like `--trailer "Reviewed-by"` (no
1075
+ * corresponding value).
1076
+ */
1077
+ if (opts->trim_empty && !strlen(item->value))
1078
+ continue;
1079
+
1080
if (!opts->filter || opts->filter(&tok, opts->filter_data)) {
1081
if (opts->separator && out->len != origlen)
1082
strbuf_addbuf(out, opts->separator);
1085
if (!opts->key_only && !opts->value_only) {
1086
if (opts->key_value_separator)
1087
strbuf_addbuf(out, opts->key_value_separator);
1111
- else
1112
- strbuf_addstr(out, ": ");
1088
+ else {
1089
+ char c = last_non_space_char(tok.buf);
1090
+ if (c && !strchr(separators, c))
1091
+ strbuf_addf(out, "%c ", separators[0]);
1092
+ }
1093
}
1094
if (!opts->key_only)
1095
strbuf_addbuf(out, &val);