summaryrefslogtreecommitdiff
path: root/builtin/rm.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-02-11 19:51:08 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-02-13 22:33:32 (GMT)
commit590fc05293964160e4360431950325658d75fe23 (patch)
tree1ab99d1530f074adba624c27fe711145bf9012b5 /builtin/rm.c
parent3ccd681c2ab11522591be8a7a3eddb1a85a43ab0 (diff)
downloadgit-590fc05293964160e4360431950325658d75fe23.zip
git-590fc05293964160e4360431950325658d75fe23.tar.gz
git-590fc05293964160e4360431950325658d75fe23.tar.bz2
rm: reuse strbuf for all remove_dir_recursively() calls, again
Don't throw the memory allocated for remove_dir_recursively() away after a single call, use it for the other entries as well instead. This change was done before in deb8e15a (rm: reuse strbuf for all remove_dir_recursively() calls), but was reverted as a side-effect of 55856a35 (rm: absorb a submodules git dir before deletion). Reinstate the optimization. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/rm.c')
-rw-r--r--builtin/rm.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/builtin/rm.c b/builtin/rm.c
index 452170a..fb79dca 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -360,15 +360,14 @@ 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) {
- struct strbuf buf = STRBUF_INIT;
-
+ strbuf_reset(&buf);
strbuf_addstr(&buf, path);
if (remove_dir_recursively(&buf, 0))
die(_("could not remove '%s'"), path);
- strbuf_release(&buf);
removed = 1;
if (!remove_path_from_gitmodules(path))
@@ -382,6 +381,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();
}