Skip to content

Commit 29211a9

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent 817b345 commit 29211a9

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

builtin/rm.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "parse-options.h"
1212
#include "string-list.h"
1313
#include "submodule.h"
14+
#include "pathspec.h"
1415

1516
static const char * const builtin_rm_usage[] = {
1617
N_("git rm [options] [--] <file>..."),
@@ -279,7 +280,7 @@ static struct option builtin_rm_options[] = {
279280
int cmd_rm(int argc, const char **argv, const char *prefix)
280281
{
281282
int i, newfd;
282-
const char **pathspec;
283+
struct pathspec pathspec;
283284
char *seen;
284285

285286
git_config(git_default_config, NULL);
@@ -312,39 +313,38 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
312313
}
313314
}
314315

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);
317318

318319
seen = NULL;
319-
for (i = 0; pathspec[i] ; i++)
320-
/* nothing */;
321-
seen = xcalloc(i, 1);
320+
seen = xcalloc(pathspec.nr, 1);
322321

323322
for (i = 0; i < active_nr; i++) {
324323
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))
326325
continue;
327326
ALLOC_GROW(list.entry, list.nr + 1, list.alloc);
328327
list.entry[list.nr].name = ce->name;
329328
list.entry[list.nr++].is_submodule = S_ISGITLINK(ce->ce_mode);
330329
}
331330

332-
if (pathspec) {
333-
const char *match;
331+
if (pathspec.nr) {
332+
const char *original;
334333
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;
336336
if (!seen[i]) {
337337
if (!ignore_unmatch) {
338338
die(_("pathspec '%s' did not match any files"),
339-
match);
339+
original);
340340
}
341341
}
342342
else {
343343
seen_any = 1;
344344
}
345345
if (!recursive && seen[i] == MATCHED_RECURSIVELY)
346346
die(_("not removing '%s' recursively without -r"),
347-
*match ? match : ".");
347+
*original ? original : ".");
348348
}
349349

350350
if (! seen_any)

0 commit comments

Comments
 (0)