@@ -52,31 +52,33 @@ void wt_status_prepare(struct wt_status *s)
5252 head = resolve_ref ("HEAD" , sha1 , 0 , NULL );
5353 s -> branch = head ? xstrdup (head ) : NULL ;
5454 s -> reference = "HEAD" ;
55+ s -> fp = stdout ;
5556}
5657
57- static void wt_status_print_cached_header (const char * reference )
58+ static void wt_status_print_cached_header (struct wt_status * s )
5859{
5960 const char * c = color (WT_STATUS_HEADER );
60- color_printf_ln ( c , "# Changes to be committed:" );
61- if (reference ) {
62- color_printf_ln ( c , "# (use \"git reset %s <file>...\" to unstage)" , reference );
61+ color_fprintf_ln ( s -> fp , c , "# Changes to be committed:" );
62+ if (s -> reference ) {
63+ color_fprintf_ln ( s -> fp , c , "# (use \"git reset %s <file>...\" to unstage)" , s -> reference );
6364 } else {
64- color_printf_ln ( c , "# (use \"git rm --cached <file>...\" to unstage)" );
65+ color_fprintf_ln ( s -> fp , c , "# (use \"git rm --cached <file>...\" to unstage)" );
6566 }
66- color_printf_ln ( c , "#" );
67+ color_fprintf_ln ( s -> fp , c , "#" );
6768}
6869
69- static void wt_status_print_header (const char * main , const char * sub )
70+ static void wt_status_print_header (struct wt_status * s ,
71+ const char * main , const char * sub )
7072{
7173 const char * c = color (WT_STATUS_HEADER );
72- color_printf_ln ( c , "# %s:" , main );
73- color_printf_ln ( c , "# (%s)" , sub );
74- color_printf_ln ( c , "#" );
74+ color_fprintf_ln ( s -> fp , c , "# %s:" , main );
75+ color_fprintf_ln ( s -> fp , c , "# (%s)" , sub );
76+ color_fprintf_ln ( s -> fp , c , "#" );
7577}
7678
77- static void wt_status_print_trailer (void )
79+ static void wt_status_print_trailer (struct wt_status * s )
7880{
79- color_printf_ln ( color (WT_STATUS_HEADER ), "#" );
81+ color_fprintf_ln ( s -> fp , color (WT_STATUS_HEADER ), "#" );
8082}
8183
8284static const char * quote_crlf (const char * in , char * buf , size_t sz )
@@ -108,7 +110,8 @@ static const char *quote_crlf(const char *in, char *buf, size_t sz)
108110 return ret ;
109111}
110112
111- static void wt_status_print_filepair (int t , struct diff_filepair * p )
113+ static void wt_status_print_filepair (struct wt_status * s ,
114+ int t , struct diff_filepair * p )
112115{
113116 const char * c = color (t );
114117 const char * one , * two ;
@@ -117,36 +120,36 @@ static void wt_status_print_filepair(int t, struct diff_filepair *p)
117120 one = quote_crlf (p -> one -> path , onebuf , sizeof (onebuf ));
118121 two = quote_crlf (p -> two -> path , twobuf , sizeof (twobuf ));
119122
120- color_printf ( color (WT_STATUS_HEADER ), "#\t" );
123+ color_fprintf ( s -> fp , color (WT_STATUS_HEADER ), "#\t" );
121124 switch (p -> status ) {
122125 case DIFF_STATUS_ADDED :
123- color_printf ( c , "new file: %s" , one );
126+ color_fprintf ( s -> fp , c , "new file: %s" , one );
124127 break ;
125128 case DIFF_STATUS_COPIED :
126- color_printf ( c , "copied: %s -> %s" , one , two );
129+ color_fprintf ( s -> fp , c , "copied: %s -> %s" , one , two );
127130 break ;
128131 case DIFF_STATUS_DELETED :
129- color_printf ( c , "deleted: %s" , one );
132+ color_fprintf ( s -> fp , c , "deleted: %s" , one );
130133 break ;
131134 case DIFF_STATUS_MODIFIED :
132- color_printf ( c , "modified: %s" , one );
135+ color_fprintf ( s -> fp , c , "modified: %s" , one );
133136 break ;
134137 case DIFF_STATUS_RENAMED :
135- color_printf ( c , "renamed: %s -> %s" , one , two );
138+ color_fprintf ( s -> fp , c , "renamed: %s -> %s" , one , two );
136139 break ;
137140 case DIFF_STATUS_TYPE_CHANGED :
138- color_printf ( c , "typechange: %s" , one );
141+ color_fprintf ( s -> fp , c , "typechange: %s" , one );
139142 break ;
140143 case DIFF_STATUS_UNKNOWN :
141- color_printf ( c , "unknown: %s" , one );
144+ color_fprintf ( s -> fp , c , "unknown: %s" , one );
142145 break ;
143146 case DIFF_STATUS_UNMERGED :
144- color_printf ( c , "unmerged: %s" , one );
147+ color_fprintf ( s -> fp , c , "unmerged: %s" , one );
145148 break ;
146149 default :
147150 die ("bug: unhandled diff status %c" , p -> status );
148151 }
149- printf ( "\n" );
152+ fprintf ( s -> fp , "\n" );
150153}
151154
152155static void wt_status_print_updated_cb (struct diff_queue_struct * q ,
@@ -160,14 +163,14 @@ static void wt_status_print_updated_cb(struct diff_queue_struct *q,
160163 if (q -> queue [i ]-> status == 'U' )
161164 continue ;
162165 if (!shown_header ) {
163- wt_status_print_cached_header (s -> reference );
166+ wt_status_print_cached_header (s );
164167 s -> commitable = 1 ;
165168 shown_header = 1 ;
166169 }
167- wt_status_print_filepair (WT_STATUS_UPDATED , q -> queue [i ]);
170+ wt_status_print_filepair (s , WT_STATUS_UPDATED , q -> queue [i ]);
168171 }
169172 if (shown_header )
170- wt_status_print_trailer ();
173+ wt_status_print_trailer (s );
171174}
172175
173176static void wt_status_print_changed_cb (struct diff_queue_struct * q ,
@@ -184,12 +187,12 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q,
184187 msg = use_add_rm_msg ;
185188 break ;
186189 }
187- wt_status_print_header ("Changed but not updated" , msg );
190+ wt_status_print_header (s , "Changed but not updated" , msg );
188191 }
189192 for (i = 0 ; i < q -> nr ; i ++ )
190- wt_status_print_filepair (WT_STATUS_CHANGED , q -> queue [i ]);
193+ wt_status_print_filepair (s , WT_STATUS_CHANGED , q -> queue [i ]);
191194 if (q -> nr )
192- wt_status_print_trailer ();
195+ wt_status_print_trailer (s );
193196}
194197
195198static void wt_read_cache (struct wt_status * s )
@@ -206,16 +209,16 @@ static void wt_status_print_initial(struct wt_status *s)
206209 wt_read_cache (s );
207210 if (active_nr ) {
208211 s -> commitable = 1 ;
209- wt_status_print_cached_header (NULL );
212+ wt_status_print_cached_header (s );
210213 }
211214 for (i = 0 ; i < active_nr ; i ++ ) {
212- color_printf ( color (WT_STATUS_HEADER ), "#\t" );
213- color_printf_ln ( color (WT_STATUS_UPDATED ), "new file: %s" ,
215+ color_fprintf ( s -> fp , color (WT_STATUS_HEADER ), "#\t" );
216+ color_fprintf_ln ( s -> fp , color (WT_STATUS_UPDATED ), "new file: %s" ,
214217 quote_crlf (active_cache [i ]-> name ,
215218 buf , sizeof (buf )));
216219 }
217220 if (active_nr )
218- wt_status_print_trailer ();
221+ wt_status_print_trailer (s );
219222}
220223
221224static void wt_status_print_updated (struct wt_status * s )
@@ -282,12 +285,12 @@ static void wt_status_print_untracked(struct wt_status *s)
282285 }
283286 if (!shown_header ) {
284287 s -> workdir_untracked = 1 ;
285- wt_status_print_header ("Untracked files" ,
288+ wt_status_print_header (s , "Untracked files" ,
286289 use_add_to_include_msg );
287290 shown_header = 1 ;
288291 }
289- color_printf ( color (WT_STATUS_HEADER ), "#\t" );
290- color_printf_ln ( color (WT_STATUS_UNTRACKED ), "%.*s" ,
292+ color_fprintf ( s -> fp , color (WT_STATUS_HEADER ), "#\t" );
293+ color_fprintf_ln ( s -> fp , color (WT_STATUS_UNTRACKED ), "%.*s" ,
291294 ent -> len , ent -> name );
292295 }
293296}
@@ -317,14 +320,14 @@ void wt_status_print(struct wt_status *s)
317320 branch_name = "" ;
318321 on_what = "Not currently on any branch." ;
319322 }
320- color_printf_ln ( color (WT_STATUS_HEADER ),
323+ color_fprintf_ln ( s -> fp , color (WT_STATUS_HEADER ),
321324 "# %s%s" , on_what , branch_name );
322325 }
323326
324327 if (s -> is_initial ) {
325- color_printf_ln ( color (WT_STATUS_HEADER ), "#" );
326- color_printf_ln ( color (WT_STATUS_HEADER ), "# Initial commit" );
327- color_printf_ln ( color (WT_STATUS_HEADER ), "#" );
328+ color_fprintf_ln ( s -> fp , color (WT_STATUS_HEADER ), "#" );
329+ color_fprintf_ln ( s -> fp , color (WT_STATUS_HEADER ), "# Initial commit" );
330+ color_fprintf_ln ( s -> fp , color (WT_STATUS_HEADER ), "#" );
328331 wt_status_print_initial (s );
329332 }
330333 else {
@@ -338,7 +341,7 @@ void wt_status_print(struct wt_status *s)
338341 wt_status_print_verbose (s );
339342 if (!s -> commitable ) {
340343 if (s -> amend )
341- printf ( "# No changes\n" );
344+ fprintf ( s -> fp , "# No changes\n" );
342345 else if (s -> workdir_dirty )
343346 printf ("no changes added to commit (use \"git add\" and/or \"git commit -a\")\n" );
344347 else if (s -> workdir_untracked )
0 commit comments