13
13
#include "refs.h"
14
14
#include "string-list.h"
15
15
#include "quote.h"
16
+ #include "column.h"
16
17
17
18
static int force = -1 ; /* unset */
18
19
static int interactive ;
19
20
static struct string_list del_list = STRING_LIST_INIT_DUP ;
21
+ static unsigned int colopts ;
20
22
21
23
static const char * const builtin_clean_usage [] = {
22
24
N_ ("git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <paths>..." ),
@@ -31,8 +33,13 @@ static const char *msg_warn_remove_failed = N_("failed to remove %s");
31
33
32
34
static int git_clean_config (const char * var , const char * value , void * cb )
33
35
{
34
- if (!strcmp (var , "clean.requireforce" ))
36
+ if (!prefixcmp (var , "column." ))
37
+ return git_column_config (var , value , "clean" , & colopts );
38
+
39
+ if (!strcmp (var , "clean.requireforce" )) {
35
40
force = !git_config_bool (var , value );
41
+ return 0 ;
42
+ }
36
43
return git_default_config (var , value , cb );
37
44
}
38
45
@@ -144,21 +151,46 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
144
151
return ret ;
145
152
}
146
153
147
- static void interactive_main_loop (void )
154
+ static void pretty_print_dels (void )
148
155
{
149
- struct strbuf confirm = STRBUF_INIT ;
150
- struct strbuf buf = STRBUF_INIT ;
156
+ struct string_list list = STRING_LIST_INIT_DUP ;
151
157
struct string_list_item * item ;
158
+ struct strbuf buf = STRBUF_INIT ;
152
159
const char * qname ;
160
+ struct column_options copts ;
161
+
162
+ for_each_string_list_item (item , & del_list ) {
163
+ qname = quote_path_relative (item -> string , NULL , & buf );
164
+ string_list_append (& list , qname );
165
+ }
166
+
167
+ /*
168
+ * always enable column display, we only consult column.*
169
+ * about layout strategy and stuff
170
+ */
171
+ colopts = (colopts & ~COL_ENABLE_MASK ) | COL_ENABLED ;
172
+ memset (& copts , 0 , sizeof (copts ));
173
+ copts .indent = " " ;
174
+ copts .padding = 2 ;
175
+ print_columns (& list , colopts , & copts );
176
+ putchar ('\n' );
177
+ strbuf_release (& buf );
178
+ string_list_clear (& list , 0 );
179
+ }
180
+
181
+ static void interactive_main_loop (void )
182
+ {
183
+ struct strbuf confirm = STRBUF_INIT ;
153
184
154
185
while (del_list .nr ) {
155
186
putchar ('\n' );
156
- for_each_string_list_item (item , & del_list ) {
157
- qname = quote_path_relative (item -> string , NULL , & buf );
158
- printf (_ (msg_would_remove ), qname );
159
- }
187
+ printf_ln (Q_ ("Would remove the following item:" ,
188
+ "Would remove the following items:" ,
189
+ del_list .nr ));
160
190
putchar ('\n' );
161
191
192
+ pretty_print_dels ();
193
+
162
194
printf (_ ("Remove [y/n]? " ));
163
195
if (strbuf_getline (& confirm , stdin , '\n' ) != EOF ) {
164
196
strbuf_trim (& confirm );
@@ -184,7 +216,6 @@ static void interactive_main_loop(void)
184
216
}
185
217
}
186
218
187
- strbuf_release (& buf );
188
219
strbuf_release (& confirm );
189
220
}
190
221
0 commit comments