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>

René Scharfe committed Feb 11, 2017 at 20:51 UTC 590fc05293964160e4360431950325658d75fe23
1 file changed +3 -3
builtin/rm.c
+3 -3
@@ -360,15 +360,14 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
360 */
361 if (!index_only) {
362 int removed = 0, gitmodules_modified = 0;
363 + struct strbuf buf = STRBUF_INIT;
364 for (i = 0; i < list.nr; i++) {
365 const char *path = list.entry[i].name;
366 if (list.entry[i].is_submodule) {
366 - struct strbuf buf = STRBUF_INIT;
367 -
367 + strbuf_reset(&buf);
368 strbuf_addstr(&buf, path);
369 if (remove_dir_recursively(&buf, 0))
370 die(_("could not remove '%s'"), path);
371 - strbuf_release(&buf);
371
372 removed = 1;
373 if (!remove_path_from_gitmodules(path))
@@ -382,6 +381,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
381 if (!removed)
382 die_errno("git rm: '%s'", path);
383 }
384 + strbuf_release(&buf);
385 if (gitmodules_modified)
386 stage_updated_gitmodules();
387 }