summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2016-07-09 14:47:04 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-07-12 22:09:21 (GMT)
commitdeb8e15a19790b2c526b599620407d2f5c1cefcb (patch)
tree4e331b5944ef17d8f125d18eceb02496b1a2afff /builtin
parent50b4a7807f5f1db79a0a4f4400c29bc00efbd307 (diff)
downloadgit-deb8e15a19790b2c526b599620407d2f5c1cefcb.zip
git-deb8e15a19790b2c526b599620407d2f5c1cefcb.tar.gz
git-deb8e15a19790b2c526b599620407d2f5c1cefcb.tar.bz2
rm: reuse strbuf for all remove_dir_recursively() calls
Don't throw the memory allocated for remove_dir_recursively() away after a single call, use it for the other entries as well instead. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/rm.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/builtin/rm.c b/builtin/rm.c
index 8829b09..7d6787d 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -387,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) {
@@ -398,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;
@@ -410,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. */
}
}
@@ -421,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();
}