12
12
#include "refs.h"
13
13
#include "submodule.h"
14
14
15
+ __attribute__((format (printf , 4 , 5 )))
16
+ extern void fprintf_commented (FILE * fp , int mid_line , const char * color , const char * fmt , ...);
17
+
15
18
static char default_wt_status_colors [][COLOR_MAXLEN ] = {
16
19
GIT_COLOR_NORMAL , /* WT_STATUS_HEADER */
17
20
GIT_COLOR_GREEN , /* WT_STATUS_UPDATED */
@@ -57,33 +60,33 @@ static void wt_status_print_unmerged_header(struct wt_status *s)
57
60
{
58
61
const char * c = color (WT_STATUS_HEADER , s );
59
62
60
- color_fprintf_ln (s -> fp , c , _ ("# Unmerged paths:" ));
63
+ fprintf_commented (s -> fp , 0 , c , _ ("Unmerged paths:\n " ));
61
64
if (!advice_status_hints )
62
65
return ;
63
66
if (s -> in_merge )
64
67
;
65
68
else if (!s -> is_initial )
66
- color_fprintf_ln (s -> fp , c , _ ("# (use \"git reset %s <file>...\" to unstage)" ), s -> reference );
69
+ fprintf_commented (s -> fp , 0 , c , _ (" (use \"git reset %s <file>...\" to unstage)\n " ), s -> reference );
67
70
else
68
- color_fprintf_ln (s -> fp , c , _ ("# (use \"git rm --cached <file>...\" to unstage)" ));
69
- color_fprintf_ln (s -> fp , c , _ ("# (use \"git add/rm <file>...\" as appropriate to mark resolution)" ));
70
- color_fprintf_ln (s -> fp , c , "# " );
71
+ fprintf_commented (s -> fp , 0 , c , _ (" (use \"git rm --cached <file>...\" to unstage)\n " ));
72
+ fprintf_commented (s -> fp , 0 , c , _ (" (use \"git add/rm <file>...\" as appropriate to mark resolution)\n " ));
73
+ fprintf_commented (s -> fp , 0 , c , "\n " );
71
74
}
72
75
73
76
static void wt_status_print_cached_header (struct wt_status * s )
74
77
{
75
78
const char * c = color (WT_STATUS_HEADER , s );
76
79
77
- color_fprintf_ln (s -> fp , c , _ ("# Changes to be committed:" ));
80
+ fprintf_commented (s -> fp , 0 , c , _ ("Changes to be committed:\n " ));
78
81
if (!advice_status_hints )
79
82
return ;
80
83
if (s -> in_merge )
81
84
; /* NEEDSWORK: use "git reset --unresolve"??? */
82
85
else if (!s -> is_initial )
83
- color_fprintf_ln (s -> fp , c , _ ("# (use \"git reset %s <file>...\" to unstage)" ), s -> reference );
86
+ fprintf_commented (s -> fp , 0 , c , _ (" (use \"git reset %s <file>...\" to unstage)\n " ), s -> reference );
84
87
else
85
- color_fprintf_ln (s -> fp , c , _ ("# (use \"git rm --cached <file>...\" to unstage)" ));
86
- color_fprintf_ln (s -> fp , c , "# " );
88
+ fprintf_commented (s -> fp , 0 , c , _ (" (use \"git rm --cached <file>...\" to unstage)\n " ));
89
+ fprintf_commented (s -> fp , 0 , c , "\n " );
87
90
}
88
91
89
92
static void wt_status_print_dirty_header (struct wt_status * s ,
@@ -92,34 +95,34 @@ static void wt_status_print_dirty_header(struct wt_status *s,
92
95
{
93
96
const char * c = color (WT_STATUS_HEADER , s );
94
97
95
- color_fprintf_ln (s -> fp , c , _ ("# Changes not staged for commit:" ));
98
+ fprintf_commented (s -> fp , 0 , c , _ ("Changes not staged for commit:\n " ));
96
99
if (!advice_status_hints )
97
100
return ;
98
101
if (!has_deleted )
99
- color_fprintf_ln (s -> fp , c , _ ("# (use \"git add <file>...\" to update what will be committed)" ));
102
+ fprintf_commented (s -> fp , 0 , c , _ (" (use \"git add <file>...\" to update what will be committed)\n " ));
100
103
else
101
- color_fprintf_ln (s -> fp , c , _ ("# (use \"git add/rm <file>...\" to update what will be committed)" ));
102
- color_fprintf_ln (s -> fp , c , _ ("# (use \"git checkout -- <file>...\" to discard changes in working directory)" ));
104
+ fprintf_commented (s -> fp , 0 , c , _ (" (use \"git add/rm <file>...\" to update what will be committed)\n " ));
105
+ fprintf_commented (s -> fp , 0 , c , _ (" (use \"git checkout -- <file>...\" to discard changes in working directory)\n " ));
103
106
if (has_dirty_submodules )
104
- color_fprintf_ln (s -> fp , c , _ ("# (commit or discard the untracked or modified content in submodules)" ));
105
- color_fprintf_ln (s -> fp , c , "# " );
107
+ fprintf_commented (s -> fp , 0 , c , _ (" (commit or discard the untracked or modified content in submodules)\n " ));
108
+ fprintf_commented (s -> fp , 0 , c , "\n " );
106
109
}
107
110
108
111
static void wt_status_print_other_header (struct wt_status * s ,
109
112
const char * what ,
110
113
const char * how )
111
114
{
112
115
const char * c = color (WT_STATUS_HEADER , s );
113
- color_fprintf_ln (s -> fp , c , _ ("# %s files:" ), what );
116
+ fprintf_commented (s -> fp , 0 , c , _ ("%s files:\n " ), what );
114
117
if (!advice_status_hints )
115
118
return ;
116
- color_fprintf_ln (s -> fp , c , _ ("# (use \"git %s <file>...\" to include in what will be committed)" ), how );
117
- color_fprintf_ln (s -> fp , c , "# " );
119
+ fprintf_commented (s -> fp , 0 , c , _ (" (use \"git %s <file>...\" to include in what will be committed)\n " ), how );
120
+ fprintf_commented (s -> fp , 0 , c , "\n " );
118
121
}
119
122
120
123
static void wt_status_print_trailer (struct wt_status * s )
121
124
{
122
- color_fprintf_ln (s -> fp , color (WT_STATUS_HEADER , s ), "# " );
125
+ fprintf_commented (s -> fp , 0 , color (WT_STATUS_HEADER , s ), "\n " );
123
126
}
124
127
125
128
#define quote_path quote_path_relative
@@ -133,7 +136,7 @@ static void wt_status_print_unmerged_data(struct wt_status *s,
133
136
const char * one , * how = _ ("bug" );
134
137
135
138
one = quote_path (it -> string , -1 , & onebuf , s -> prefix );
136
- color_fprintf (s -> fp , color (WT_STATUS_HEADER , s ), "# \t" );
139
+ fprintf_commented (s -> fp , 0 , color (WT_STATUS_HEADER , s ), "\t" );
137
140
switch (d -> stagemask ) {
138
141
case 1 : how = _ ("both deleted:" ); break ;
139
142
case 2 : how = _ ("added by us:" ); break ;
@@ -143,7 +146,7 @@ static void wt_status_print_unmerged_data(struct wt_status *s,
143
146
case 6 : how = _ ("both added:" ); break ;
144
147
case 7 : how = _ ("both modified:" ); break ;
145
148
}
146
- color_fprintf (s -> fp , c , "%-20s%s\n" , how , one );
149
+ fprintf_commented (s -> fp , 1 , c , "%-20s%s\n" , how , one );
147
150
strbuf_release (& onebuf );
148
151
}
149
152
@@ -186,40 +189,40 @@ static void wt_status_print_change_data(struct wt_status *s,
186
189
one = quote_path (one_name , -1 , & onebuf , s -> prefix );
187
190
two = quote_path (two_name , -1 , & twobuf , s -> prefix );
188
191
189
- color_fprintf (s -> fp , color (WT_STATUS_HEADER , s ), "# \t" );
192
+ fprintf_commented (s -> fp , 0 , color (WT_STATUS_HEADER , s ), "\t" );
190
193
switch (status ) {
191
194
case DIFF_STATUS_ADDED :
192
- color_fprintf (s -> fp , c , _ ("new file: %s" ), one );
195
+ fprintf_commented (s -> fp , 1 , c , _ ("new file: %s" ), one );
193
196
break ;
194
197
case DIFF_STATUS_COPIED :
195
- color_fprintf (s -> fp , c , _ ("copied: %s -> %s" ), one , two );
198
+ fprintf_commented (s -> fp , 1 , c , _ ("copied: %s -> %s" ), one , two );
196
199
break ;
197
200
case DIFF_STATUS_DELETED :
198
- color_fprintf (s -> fp , c , _ ("deleted: %s" ), one );
201
+ fprintf_commented (s -> fp , 1 , c , _ ("deleted: %s" ), one );
199
202
break ;
200
203
case DIFF_STATUS_MODIFIED :
201
- color_fprintf (s -> fp , c , _ ("modified: %s" ), one );
204
+ fprintf_commented (s -> fp , 1 , c , _ ("modified: %s" ), one );
202
205
break ;
203
206
case DIFF_STATUS_RENAMED :
204
- color_fprintf (s -> fp , c , _ ("renamed: %s -> %s" ), one , two );
207
+ fprintf_commented (s -> fp , 1 , c , _ ("renamed: %s -> %s" ), one , two );
205
208
break ;
206
209
case DIFF_STATUS_TYPE_CHANGED :
207
- color_fprintf (s -> fp , c , _ ("typechange: %s" ), one );
210
+ fprintf_commented (s -> fp , 1 , c , _ ("typechange: %s" ), one );
208
211
break ;
209
212
case DIFF_STATUS_UNKNOWN :
210
- color_fprintf (s -> fp , c , _ ("unknown: %s" ), one );
213
+ fprintf_commented (s -> fp , 1 , c , _ ("unknown: %s" ), one );
211
214
break ;
212
215
case DIFF_STATUS_UNMERGED :
213
- color_fprintf (s -> fp , c , _ ("unmerged: %s" ), one );
216
+ fprintf_commented (s -> fp , 1 , c , _ ("unmerged: %s" ), one );
214
217
break ;
215
218
default :
216
219
die (_ ("bug: unhandled diff status %c" ), status );
217
220
}
218
221
if (extra .len ) {
219
- color_fprintf (s -> fp , color (WT_STATUS_HEADER , s ), "%s" , extra .buf );
222
+ fprintf_commented (s -> fp , 1 , color (WT_STATUS_HEADER , s ), "%s" , extra .buf );
220
223
strbuf_release (& extra );
221
224
}
222
- fprintf (s -> fp , "\n" );
225
+ fprintf_commented (s -> fp , 1 , "" , "\n" );
223
226
strbuf_release (& onebuf );
224
227
strbuf_release (& twobuf );
225
228
}
@@ -573,8 +576,8 @@ static void wt_status_print_other(struct wt_status *s,
573
576
for (i = 0 ; i < l -> nr ; i ++ ) {
574
577
struct string_list_item * it ;
575
578
it = & (l -> items [i ]);
576
- color_fprintf (s -> fp , color (WT_STATUS_HEADER , s ), "# \t" );
577
- color_fprintf_ln (s -> fp , color (WT_STATUS_UNTRACKED , s ), "%s" ,
579
+ fprintf_commented (s -> fp , 0 , color (WT_STATUS_HEADER , s ), "\t" );
580
+ fprintf_commented (s -> fp , 1 , color (WT_STATUS_UNTRACKED , s ), "%s\n " ,
578
581
quote_path (it -> string , strlen (it -> string ),
579
582
& buf , s -> prefix ));
580
583
}
@@ -622,9 +625,9 @@ static void wt_status_print_tracking(struct wt_status *s)
622
625
return ;
623
626
624
627
for (cp = sb .buf ; (ep = strchr (cp , '\n' )) != NULL ; cp = ep + 1 )
625
- color_fprintf_ln (s -> fp , color (WT_STATUS_HEADER , s ),
626
- "# %.*s" , (int )(ep - cp ), cp );
627
- color_fprintf_ln (s -> fp , color (WT_STATUS_HEADER , s ), "# " );
628
+ fprintf_commented (s -> fp , 0 , color (WT_STATUS_HEADER , s ),
629
+ "%.*s\n " , (int )(ep - cp ), cp );
630
+ fprintf_commented (s -> fp , 0 , color (WT_STATUS_HEADER , s ), "\n " );
628
631
}
629
632
630
633
void wt_status_print (struct wt_status * s )
@@ -642,17 +645,17 @@ void wt_status_print(struct wt_status *s)
642
645
branch_status_color = color (WT_STATUS_NOBRANCH , s );
643
646
on_what = _ ("Not currently on any branch." );
644
647
}
645
- color_fprintf (s -> fp , color (WT_STATUS_HEADER , s ), "# " );
646
- color_fprintf (s -> fp , branch_status_color , "%s" , on_what );
647
- color_fprintf_ln (s -> fp , branch_color , "%s" , branch_name );
648
+ fprintf_commented (s -> fp , 0 , color (WT_STATUS_HEADER , s ), "" );
649
+ fprintf_commented (s -> fp , 1 , branch_status_color , "%s" , on_what );
650
+ fprintf_commented (s -> fp , 1 , branch_color , "%s\n " , branch_name );
648
651
if (!s -> is_initial )
649
652
wt_status_print_tracking (s );
650
653
}
651
654
652
655
if (s -> is_initial ) {
653
- color_fprintf_ln (s -> fp , color (WT_STATUS_HEADER , s ), "# " );
654
- color_fprintf_ln (s -> fp , color (WT_STATUS_HEADER , s ), _ ("# Initial commit" ));
655
- color_fprintf_ln (s -> fp , color (WT_STATUS_HEADER , s ), "# " );
656
+ fprintf_commented (s -> fp , 0 , color (WT_STATUS_HEADER , s ), "\n " );
657
+ fprintf_commented (s -> fp , 0 , color (WT_STATUS_HEADER , s ), _ ("Initial commit\n " ));
658
+ fprintf_commented (s -> fp , 0 , color (WT_STATUS_HEADER , s ), "\n " );
656
659
}
657
660
658
661
wt_status_print_updated (s );
@@ -669,15 +672,15 @@ void wt_status_print(struct wt_status *s)
669
672
if (s -> show_ignored_files )
670
673
wt_status_print_other (s , & s -> ignored , _ ("Ignored" ), "add -f" );
671
674
} else if (s -> commitable )
672
- fprintf (s -> fp , _ ("# Untracked files not listed%s\n" ),
675
+ fprintf_commented (s -> fp , 0 , _ ("Untracked files not listed%s\n" ),
673
676
advice_status_hints
674
677
? _ (" (use -u option to show untracked files)" ) : "" );
675
678
676
679
if (s -> verbose )
677
680
wt_status_print_verbose (s );
678
681
if (!s -> commitable ) {
679
682
if (s -> amend )
680
- fprintf (s -> fp , _ ("# No changes\n" ));
683
+ fprintf_commented (s -> fp , 0 , "" , _ ("No changes\n" ));
681
684
else if (s -> nowarn )
682
685
; /* nothing */
683
686
else if (s -> workdir_dirty )
0 commit comments