@@ -108,23 +108,23 @@ static char last_non_space_char(const char *s)
108
108
return '\0' ;
109
109
}
110
110
111
- static void print_tok_val (const char * tok , const char * val )
111
+ static void print_tok_val (FILE * outfile , const char * tok , const char * val )
112
112
{
113
113
char c = last_non_space_char (tok );
114
114
if (!c )
115
115
return ;
116
116
if (strchr (separators , c ))
117
- printf ( "%s%s\n" , tok , val );
117
+ fprintf ( outfile , "%s%s\n" , tok , val );
118
118
else
119
- printf ( "%s%c %s\n" , tok , separators [0 ], val );
119
+ fprintf ( outfile , "%s%c %s\n" , tok , separators [0 ], val );
120
120
}
121
121
122
- static void print_all (struct trailer_item * first , int trim_empty )
122
+ static void print_all (FILE * outfile , struct trailer_item * first , int trim_empty )
123
123
{
124
124
struct trailer_item * item ;
125
125
for (item = first ; item ; item = item -> next ) {
126
126
if (!trim_empty || strlen (item -> value ) > 0 )
127
- print_tok_val (item -> token , item -> value );
127
+ print_tok_val (outfile , item -> token , item -> value );
128
128
}
129
129
}
130
130
@@ -795,14 +795,15 @@ static int has_blank_line_before(struct strbuf **lines, int start)
795
795
return 0 ;
796
796
}
797
797
798
- static void print_lines (struct strbuf * * lines , int start , int end )
798
+ static void print_lines (FILE * outfile , struct strbuf * * lines , int start , int end )
799
799
{
800
800
int i ;
801
801
for (i = start ; lines [i ] && i < end ; i ++ )
802
- printf ( "%s" , lines [i ]-> buf );
802
+ fprintf ( outfile , "%s" , lines [i ]-> buf );
803
803
}
804
804
805
- static int process_input_file (struct strbuf * * lines ,
805
+ static int process_input_file (FILE * outfile ,
806
+ struct strbuf * * lines ,
806
807
struct trailer_item * * in_tok_first ,
807
808
struct trailer_item * * in_tok_last )
808
809
{
@@ -818,10 +819,10 @@ static int process_input_file(struct strbuf **lines,
818
819
trailer_start = find_trailer_start (lines , trailer_end );
819
820
820
821
/* Print lines before the trailers as is */
821
- print_lines (lines , 0 , trailer_start );
822
+ print_lines (outfile , lines , 0 , trailer_start );
822
823
823
824
if (!has_blank_line_before (lines , trailer_start - 1 ))
824
- printf ( "\n" );
825
+ fprintf ( outfile , "\n" );
825
826
826
827
/* Parse trailer lines */
827
828
for (i = trailer_start ; i < trailer_end ; i ++ ) {
@@ -849,6 +850,7 @@ void process_trailers(const char *file, int trim_empty, struct string_list *trai
849
850
struct trailer_item * arg_tok_first ;
850
851
struct strbuf * * lines ;
851
852
int trailer_end ;
853
+ FILE * outfile = stdout ;
852
854
853
855
/* Default config must be setup first */
854
856
git_config (git_trailer_default_config , NULL );
@@ -857,18 +859,18 @@ void process_trailers(const char *file, int trim_empty, struct string_list *trai
857
859
lines = read_input_file (file );
858
860
859
861
/* Print the lines before the trailers */
860
- trailer_end = process_input_file (lines , & in_tok_first , & in_tok_last );
862
+ trailer_end = process_input_file (outfile , lines , & in_tok_first , & in_tok_last );
861
863
862
864
arg_tok_first = process_command_line_args (trailers );
863
865
864
866
process_trailers_lists (& in_tok_first , & in_tok_last , & arg_tok_first );
865
867
866
- print_all (in_tok_first , trim_empty );
868
+ print_all (outfile , in_tok_first , trim_empty );
867
869
868
870
free_all (& in_tok_first );
869
871
870
872
/* Print the lines after the trailers as is */
871
- print_lines (lines , trailer_end , INT_MAX );
873
+ print_lines (outfile , lines , trailer_end , INT_MAX );
872
874
873
875
strbuf_list_free (lines );
874
876
}
0 commit comments