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