@@ -711,30 +711,35 @@ static void add_arg_item(struct list_head *arg_head, char *tok, char *val,
711
711
list_add_tail (& new_item -> list , arg_head );
712
712
}
713
713
714
- static void process_command_line_args (struct list_head * arg_head ,
715
- struct list_head * new_trailer_head )
714
+ static void parse_trailers_from_config (struct list_head * config_head )
716
715
{
717
716
struct arg_item * item ;
718
- struct strbuf tok = STRBUF_INIT ;
719
- struct strbuf val = STRBUF_INIT ;
720
- const struct conf_info * conf ;
721
717
struct list_head * pos ;
722
718
723
- /*
724
- * In command-line arguments, '=' is accepted (in addition to the
725
- * separators that are defined).
726
- */
727
- char * cl_separators = xstrfmt ("=%s" , separators );
728
-
729
719
/* Add an arg item for each configured trailer with a command */
730
720
list_for_each (pos , & conf_head ) {
731
721
item = list_entry (pos , struct arg_item , list );
732
722
if (item -> conf .command )
733
- add_arg_item (arg_head ,
723
+ add_arg_item (config_head ,
734
724
xstrdup (token_from_item (item , NULL )),
735
725
xstrdup ("" ),
736
726
& item -> conf , NULL );
737
727
}
728
+ }
729
+
730
+ static void parse_trailers_from_command_line_args (struct list_head * arg_head ,
731
+ struct list_head * new_trailer_head )
732
+ {
733
+ struct strbuf tok = STRBUF_INIT ;
734
+ struct strbuf val = STRBUF_INIT ;
735
+ const struct conf_info * conf ;
736
+ struct list_head * pos ;
737
+
738
+ /*
739
+ * In command-line arguments, '=' is accepted (in addition to the
740
+ * separators that are defined).
741
+ */
742
+ char * cl_separators = xstrfmt ("=%s" , separators );
738
743
739
744
/* Add an arg item for each trailer on the command line */
740
745
list_for_each (pos , new_trailer_head ) {
@@ -961,28 +966,24 @@ static void unfold_value(struct strbuf *val)
961
966
strbuf_release (& out );
962
967
}
963
968
964
- static size_t process_input_file (FILE * outfile ,
965
- const char * str ,
966
- struct list_head * head ,
967
- const struct process_trailer_options * opts )
969
+ /*
970
+ * Parse trailers in "str", populating the trailer info and "head"
971
+ * linked list structure.
972
+ */
973
+ static void parse_trailers (struct trailer_info * info ,
974
+ const char * str ,
975
+ struct list_head * head ,
976
+ const struct process_trailer_options * opts )
968
977
{
969
- struct trailer_info info ;
970
978
struct strbuf tok = STRBUF_INIT ;
971
979
struct strbuf val = STRBUF_INIT ;
972
980
size_t i ;
973
981
974
- trailer_info_get (& info , str , opts );
975
-
976
- /* Print lines before the trailers as is */
977
- if (!opts -> only_trailers )
978
- fwrite (str , 1 , info .trailer_start - str , outfile );
982
+ trailer_info_get (info , str , opts );
979
983
980
- if (!opts -> only_trailers && !info .blank_line_before_trailer )
981
- fprintf (outfile , "\n" );
982
-
983
- for (i = 0 ; i < info .trailer_nr ; i ++ ) {
984
+ for (i = 0 ; i < info -> trailer_nr ; i ++ ) {
984
985
int separator_pos ;
985
- char * trailer = info . trailers [i ];
986
+ char * trailer = info -> trailers [i ];
986
987
if (trailer [0 ] == comment_line_char )
987
988
continue ;
988
989
separator_pos = find_separator (trailer , separators );
@@ -1002,10 +1003,6 @@ static size_t process_input_file(FILE *outfile,
1002
1003
strbuf_detach (& val , NULL ));
1003
1004
}
1004
1005
}
1005
-
1006
- trailer_info_release (& info );
1007
-
1008
- return info .trailer_end - str ;
1009
1006
}
1010
1007
1011
1008
static void free_all (struct list_head * head )
@@ -1054,6 +1051,7 @@ void process_trailers(const char *file,
1054
1051
{
1055
1052
LIST_HEAD (head );
1056
1053
struct strbuf sb = STRBUF_INIT ;
1054
+ struct trailer_info info ;
1057
1055
size_t trailer_end ;
1058
1056
FILE * outfile = stdout ;
1059
1057
@@ -1064,18 +1062,30 @@ void process_trailers(const char *file,
1064
1062
if (opts -> in_place )
1065
1063
outfile = create_in_place_tempfile (file );
1066
1064
1065
+ parse_trailers (& info , sb .buf , & head , opts );
1066
+ trailer_end = info .trailer_end - sb .buf ;
1067
+
1067
1068
/* Print the lines before the trailers */
1068
- trailer_end = process_input_file (outfile , sb .buf , & head , opts );
1069
+ if (!opts -> only_trailers )
1070
+ fwrite (sb .buf , 1 , info .trailer_start - sb .buf , outfile );
1071
+
1072
+ if (!opts -> only_trailers && !info .blank_line_before_trailer )
1073
+ fprintf (outfile , "\n" );
1074
+
1069
1075
1070
1076
if (!opts -> only_input ) {
1077
+ LIST_HEAD (config_head );
1071
1078
LIST_HEAD (arg_head );
1072
- process_command_line_args (& arg_head , new_trailer_head );
1079
+ parse_trailers_from_config (& config_head );
1080
+ parse_trailers_from_command_line_args (& arg_head , new_trailer_head );
1081
+ list_splice (& config_head , & arg_head );
1073
1082
process_trailers_lists (& head , & arg_head );
1074
1083
}
1075
1084
1076
1085
print_all (outfile , & head , opts );
1077
1086
1078
1087
free_all (& head );
1088
+ trailer_info_release (& info );
1079
1089
1080
1090
/* Print the lines after the trailers as is */
1081
1091
if (!opts -> only_trailers )
@@ -1220,14 +1230,14 @@ void trailer_iterator_init(struct trailer_iterator *iter, const char *msg)
1220
1230
strbuf_init (& iter -> key , 0 );
1221
1231
strbuf_init (& iter -> val , 0 );
1222
1232
opts .no_divider = 1 ;
1223
- trailer_info_get (& iter -> info , msg , & opts );
1224
- iter -> cur = 0 ;
1233
+ trailer_info_get (& iter -> internal . info , msg , & opts );
1234
+ iter -> internal . cur = 0 ;
1225
1235
}
1226
1236
1227
1237
int trailer_iterator_advance (struct trailer_iterator * iter )
1228
1238
{
1229
- while (iter -> cur < iter -> info .trailer_nr ) {
1230
- char * trailer = iter -> info .trailers [iter -> cur ++ ];
1239
+ while (iter -> internal . cur < iter -> internal . info .trailer_nr ) {
1240
+ char * trailer = iter -> internal . info .trailers [iter -> internal . cur ++ ];
1231
1241
int separator_pos = find_separator (trailer , separators );
1232
1242
1233
1243
if (separator_pos < 1 )
@@ -1245,7 +1255,7 @@ int trailer_iterator_advance(struct trailer_iterator *iter)
1245
1255
1246
1256
void trailer_iterator_release (struct trailer_iterator * iter )
1247
1257
{
1248
- trailer_info_release (& iter -> info );
1258
+ trailer_info_release (& iter -> internal . info );
1249
1259
strbuf_release (& iter -> val );
1250
1260
strbuf_release (& iter -> key );
1251
1261
}
0 commit comments