rm: 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
29211a93c14011f3eff2cf2706a809f1b8160fb5
1 file changed
+12
-12
builtin/rm.c
+12
-12
@@ -11,6 +11,7 @@
11
#include "parse-options.h"
12
#include "string-list.h"
13
#include "submodule.h"
14
+#include "pathspec.h"
15
16
static const char * const builtin_rm_usage[] = {
17
N_("git rm [options] [--] <file>..."),
@@ -279,7 +280,7 @@ static struct option builtin_rm_options[] = {
280
int cmd_rm(int argc, const char **argv, const char *prefix)
281
{
282
int i, newfd;
282
- const char **pathspec;
283
+ struct pathspec pathspec;
284
char *seen;
285
286
git_config(git_default_config, NULL);
@@ -312,31 +313,30 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
313
}
314
}
315
315
- pathspec = get_pathspec(prefix, argv);
316
- refresh_index(&the_index, REFRESH_QUIET, pathspec, NULL, NULL);
316
+ parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);
317
+ refresh_index(&the_index, REFRESH_QUIET, pathspec.raw, NULL, NULL);
318
319
seen = NULL;
319
- for (i = 0; pathspec[i] ; i++)
320
- /* nothing */;
321
- seen = xcalloc(i, 1);
320
+ seen = xcalloc(pathspec.nr, 1);
321
322
for (i = 0; i < active_nr; i++) {
323
struct cache_entry *ce = active_cache[i];
325
- if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen))
324
+ if (!match_pathspec_depth(&pathspec, ce->name, ce_namelen(ce), 0, seen))
325
continue;
326
ALLOC_GROW(list.entry, list.nr + 1, list.alloc);
327
list.entry[list.nr].name = ce->name;
328
list.entry[list.nr++].is_submodule = S_ISGITLINK(ce->ce_mode);
329
}
330
332
- if (pathspec) {
333
- const char *match;
331
+ if (pathspec.nr) {
332
+ const char *original;
333
int seen_any = 0;
335
- for (i = 0; (match = pathspec[i]) != NULL ; i++) {
334
+ for (i = 0; i < pathspec.nr; i++) {
335
+ original = pathspec.items[i].original;
336
if (!seen[i]) {
337
if (!ignore_unmatch) {
338
die(_("pathspec '%s' did not match any files"),
339
- match);
339
+ original);
340
}
341
}
342
else {
@@ -344,7 +344,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
344
}
345
if (!recursive && seen[i] == MATCHED_RECURSIVELY)
346
die(_("not removing '%s' recursively without -r"),
347
- *match ? match : ".");
347
+ *original ? original : ".");
348
}
349
350
if (! seen_any)