1313#include "refs.h"
1414#include "string-list.h"
1515#include "quote.h"
16+ #include "column.h"
1617
1718static int force = -1 ; /* unset */
1819static int interactive ;
1920static struct string_list del_list = STRING_LIST_INIT_DUP ;
21+ static unsigned int colopts ;
2022
2123static const char * const builtin_clean_usage [] = {
2224 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");
3133
3234static int git_clean_config (const char * var , const char * value , void * cb )
3335{
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" )) {
3540 force = !git_config_bool (var , value );
41+ return 0 ;
42+ }
3643 return git_default_config (var , value , cb );
3744}
3845
@@ -144,21 +151,46 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
144151 return ret ;
145152}
146153
147- static void interactive_main_loop (void )
154+ static void pretty_print_dels (void )
148155{
149- struct strbuf confirm = STRBUF_INIT ;
150- struct strbuf buf = STRBUF_INIT ;
156+ struct string_list list = STRING_LIST_INIT_DUP ;
151157 struct string_list_item * item ;
158+ struct strbuf buf = STRBUF_INIT ;
152159 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 ;
153184
154185 while (del_list .nr ) {
155186 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 ));
160190 putchar ('\n' );
161191
192+ pretty_print_dels ();
193+
162194 printf (_ ("Remove [y/n]? " ));
163195 if (strbuf_getline (& confirm , stdin , '\n' ) != EOF ) {
164196 strbuf_trim (& confirm );
@@ -184,7 +216,6 @@ static void interactive_main_loop(void)
184216 }
185217 }
186218
187- strbuf_release (& buf );
188219 strbuf_release (& confirm );
189220}
190221
0 commit comments