git-clean: show items of del_list in columns
When there are lots of items to be cleaned, it is hard to see them all in one screen. Show them in columns will solve this problem. Signed-off-by: Jiang Xin <worldhello.net@gmail.com> Comments-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jiang Xin committed
Jun 25, 2013 at 23:53 UTC
1b8fd46732fc2e4e8300c11057a7fa9a8c2bc1b4
2 files changed
+44
-9
Documentation/config.txt
+4
@@ -955,6 +955,10 @@ column.branch::
955
Specify whether to output branch listing in `git branch` in columns.
956
See `column.ui` for details.
957
958
+column.clean::
959
+ Specify the layout when list items in `git clean -i`, which always
960
+ shows files and directories in columns. See `column.ui` for details.
961
+
962
column.status::
963
Specify whether to output untracked files in `git status` in columns.
964
See `column.ui` for details.
builtin/clean.c
+40
-9
@@ -13,10 +13,12 @@
13
#include "refs.h"
14
#include "string-list.h"
15
#include "quote.h"
16
+#include "column.h"
17
18
static int force = -1; /* unset */
19
static int interactive;
20
static struct string_list del_list = STRING_LIST_INIT_DUP;
21
+static unsigned int colopts;
22
23
static const char *const builtin_clean_usage[] = {
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");
33
34
static int git_clean_config(const char *var, const char *value, void *cb)
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")) {
40
force = !git_config_bool(var, value);
41
+ return 0;
42
+ }
43
return git_default_config(var, value, cb);
44
}
45
@@ -144,21 +151,46 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
151
return ret;
152
}
153
147
-static void interactive_main_loop(void)
154
+static void pretty_print_dels(void)
155
{
149
- struct strbuf confirm = STRBUF_INIT;
150
- struct strbuf buf = STRBUF_INIT;
156
+ struct string_list list = STRING_LIST_INIT_DUP;
157
struct string_list_item *item;
158
+ struct strbuf buf = STRBUF_INIT;
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;
184
185
while (del_list.nr) {
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));
190
putchar('\n');
191
192
+ pretty_print_dels();
193
+
194
printf(_("Remove [y/n]? "));
195
if (strbuf_getline(&confirm, stdin, '\n') != EOF) {
196
strbuf_trim(&confirm);
@@ -184,7 +216,6 @@ static void interactive_main_loop(void)
216
}
217
}
218
187
- strbuf_release(&buf);
219
strbuf_release(&confirm);
220
}
221