clean: convert to use parse_pathspec
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Jul 14, 2013 at 15:35 UTC
893d839970c0f966bee17cdf63895a62e670e0ca
1 file changed
+10
-7
builtin/clean.c
+10
-7
@@ -13,6 +13,7 @@
13
#include "refs.h"
14
#include "string-list.h"
15
#include "quote.h"
16
+#include "pathspec.h"
17
18
static int force = -1; /* unset */
19
@@ -150,7 +151,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
151
int rm_flags = REMOVE_DIR_KEEP_NESTED_GIT;
152
struct strbuf directory = STRBUF_INIT;
153
struct dir_struct dir;
153
- static const char **pathspec;
154
+ struct pathspec pathspec;
155
struct strbuf buf = STRBUF_INIT;
156
struct string_list exclude_list = STRING_LIST_INIT_NODUP;
157
struct exclude_list *el;
@@ -209,9 +210,11 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
210
for (i = 0; i < exclude_list.nr; i++)
211
add_exclude(exclude_list.items[i].string, "", 0, el, -(i+1));
212
212
- pathspec = get_pathspec(prefix, argv);
213
+ parse_pathspec(&pathspec, 0,
214
+ PATHSPEC_PREFER_CWD,
215
+ prefix, argv);
216
214
- fill_directory(&dir, pathspec);
217
+ fill_directory(&dir, pathspec.raw);
218
219
for (i = 0; i < dir.nr; i++) {
220
struct dir_entry *ent = dir.entries[i];
@@ -246,9 +249,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
249
if (lstat(ent->name, &st))
250
continue;
251
249
- if (pathspec)
250
- matches = match_pathspec(pathspec, ent->name, len,
251
- 0, NULL);
252
+ if (pathspec.nr)
253
+ matches = match_pathspec_depth(&pathspec, ent->name,
254
+ len, 0, NULL);
255
256
if (S_ISDIR(st.st_mode)) {
257
strbuf_addstr(&directory, ent->name);
@@ -262,7 +265,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
265
}
266
strbuf_reset(&directory);
267
} else {
265
- if (pathspec && !matches)
268
+ if (pathspec.nr && !matches)
269
continue;
270
res = dry_run ? 0 : unlink(ent->name);
271
if (res) {