rm: reuse strbuf for all remove_dir_recursively() calls
[gitweb.git] / builtin / rm.c
index 74a7a43efb9a119b342dde25db12902fdaf0e461..7d6787d8dd00963b81bf9e630452c871b70f4e49 100644 (file)
@@ -84,7 +84,6 @@ static int check_submodules_use_gitfiles(void)
                const char *name = list.entry[i].name;
                int pos;
                const struct cache_entry *ce;
-               struct stat st;
 
                pos = cache_name_pos(name, strlen(name));
                if (pos < 0) {
@@ -95,7 +94,7 @@ static int check_submodules_use_gitfiles(void)
                ce = active_cache[pos];
 
                if (!S_ISGITLINK(ce->ce_mode) ||
-                   (lstat(ce->name, &st) < 0) ||
+                   !file_exists(ce->name) ||
                    is_empty_dir(name))
                        continue;
 
@@ -388,6 +387,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
         */
        if (!index_only) {
                int removed = 0, gitmodules_modified = 0;
+               struct strbuf buf = STRBUF_INIT;
                for (i = 0; i < list.nr; i++) {
                        const char *path = list.entry[i].name;
                        if (list.entry[i].is_submodule) {
@@ -399,7 +399,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
                                                continue;
                                        }
                                } else {
-                                       struct strbuf buf = STRBUF_INIT;
+                                       strbuf_reset(&buf);
                                        strbuf_addstr(&buf, path);
                                        if (!remove_dir_recursively(&buf, 0)) {
                                                removed = 1;
@@ -411,7 +411,6 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
                                                /* Submodule was removed by user */
                                                if (!remove_path_from_gitmodules(path))
                                                        gitmodules_modified = 1;
-                                       strbuf_release(&buf);
                                        /* Fallthrough and let remove_path() fail. */
                                }
                        }
@@ -422,6 +421,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
                        if (!removed)
                                die_errno("git rm: '%s'", path);
                }
+               strbuf_release(&buf);
                if (gitmodules_modified)
                        stage_updated_gitmodules();
        }