test-hashmap.c: drop unnecessary #includes
[gitweb.git] / builtin / rm.c
index 9b59ab3a64e00cfe3a6a73d6493001085c31d683..171f37c1cc5371c307ef16ce67fefc1c40fbc2c2 100644 (file)
@@ -298,22 +298,10 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
        if (read_cache() < 0)
                die(_("index file corrupt"));
 
-       /*
-        * Drop trailing directory separators from directories so we'll find
-        * submodules in the index.
-        */
-       for (i = 0; i < argc; i++) {
-               size_t pathlen = strlen(argv[i]);
-               if (pathlen && is_dir_sep(argv[i][pathlen - 1]) &&
-                   is_directory(argv[i])) {
-                       do {
-                               pathlen--;
-                       } while (pathlen && is_dir_sep(argv[i][pathlen - 1]));
-                       argv[i] = xmemdupz(argv[i], pathlen);
-               }
-       }
-
-       parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);
+       parse_pathspec(&pathspec, 0,
+                      PATHSPEC_PREFER_CWD |
+                      PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,
+                      prefix, argv);
        refresh_index(&the_index, REFRESH_QUIET, &pathspec, NULL, NULL);
 
        seen = xcalloc(pathspec.nr, 1);
@@ -323,7 +311,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
                if (!match_pathspec_depth(&pathspec, ce->name, ce_namelen(ce), 0, seen))
                        continue;
                ALLOC_GROW(list.entry, list.nr + 1, list.alloc);
-               list.entry[list.nr].name = ce->name;
+               list.entry[list.nr].name = xstrdup(ce->name);
                list.entry[list.nr].is_submodule = S_ISGITLINK(ce->ce_mode);
                if (list.entry[list.nr++].is_submodule &&
                    !is_staging_gitmodules_ok())