@@ -144,38 +144,6 @@ static char last_non_space_char(const char *s)
144
144
return '\0' ;
145
145
}
146
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
-
179
147
static struct trailer_item * trailer_from_arg (struct arg_item * arg_tok )
180
148
{
181
149
struct trailer_item * new_item = xcalloc (1 , sizeof (* new_item ));
@@ -1084,35 +1052,44 @@ void trailer_info_release(struct trailer_info *info)
1084
1052
free (info -> trailers );
1085
1053
}
1086
1054
1087
- static void format_trailer_info (const struct process_trailer_options * opts ,
1088
- const struct trailer_info * info ,
1089
- struct strbuf * out )
1055
+ void format_trailers (const struct process_trailer_options * opts ,
1056
+ struct list_head * trailers ,
1057
+ struct strbuf * out )
1090
1058
{
1091
1059
size_t origlen = out -> len ;
1092
- size_t i ;
1093
-
1094
- for (i = 0 ; i < info -> trailer_nr ; i ++ ) {
1095
- char * trailer = info -> trailers [i ];
1096
- ssize_t separator_pos = find_separator (trailer , separators );
1060
+ struct list_head * pos ;
1061
+ struct trailer_item * item ;
1097
1062
1098
- if (separator_pos >= 1 ) {
1063
+ list_for_each (pos , trailers ) {
1064
+ item = list_entry (pos , struct trailer_item , list );
1065
+ if (item -> token ) {
1099
1066
struct strbuf tok = STRBUF_INIT ;
1100
1067
struct strbuf val = STRBUF_INIT ;
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 ;
1101
1079
1102
- parse_trailer (& tok , & val , NULL , trailer , separator_pos );
1103
1080
if (!opts -> filter || opts -> filter (& tok , opts -> filter_data )) {
1104
- if (opts -> unfold )
1105
- unfold_value (& val );
1106
-
1107
1081
if (opts -> separator && out -> len != origlen )
1108
1082
strbuf_addbuf (out , opts -> separator );
1109
1083
if (!opts -> value_only )
1110
1084
strbuf_addbuf (out , & tok );
1111
1085
if (!opts -> key_only && !opts -> value_only ) {
1112
1086
if (opts -> key_value_separator )
1113
1087
strbuf_addbuf (out , opts -> key_value_separator );
1114
- else
1115
- 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
+ }
1116
1093
}
1117
1094
if (!opts -> key_only )
1118
1095
strbuf_addbuf (out , & val );
@@ -1126,13 +1103,13 @@ static void format_trailer_info(const struct process_trailer_options *opts,
1126
1103
if (opts -> separator && out -> len != origlen ) {
1127
1104
strbuf_addbuf (out , opts -> separator );
1128
1105
}
1129
- strbuf_addstr (out , trailer );
1130
- if (opts -> separator ) {
1106
+ strbuf_addstr (out , item -> value );
1107
+ if (opts -> separator )
1131
1108
strbuf_rtrim (out );
1132
- }
1109
+ else
1110
+ strbuf_addch (out , '\n' );
1133
1111
}
1134
1112
}
1135
-
1136
1113
}
1137
1114
1138
1115
void format_trailers_from_commit (const struct process_trailer_options * opts ,
@@ -1151,7 +1128,7 @@ void format_trailers_from_commit(const struct process_trailer_options *opts,
1151
1128
strbuf_add (out , msg + info .trailer_block_start ,
1152
1129
info .trailer_block_end - info .trailer_block_start );
1153
1130
} else
1154
- format_trailer_info (opts , & info , out );
1131
+ format_trailers (opts , & trailer_objects , out );
1155
1132
1156
1133
free_trailers (& trailer_objects );
1157
1134
trailer_info_release (& info );
0 commit comments