Skip to content

Commit 590fc05

Browse files
rscharfegitster
authored andcommitted
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 deb8e15 (rm: reuse strbuf for all remove_dir_recursively() calls), but was reverted as a side-effect of 55856a3 (rm: absorb a submodules git dir before deletion). Reinstate the optimization. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3ccd681 commit 590fc05

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

builtin/rm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,15 +360,14 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
360360
*/
361361
if (!index_only) {
362362
int removed = 0, gitmodules_modified = 0;
363+
struct strbuf buf = STRBUF_INIT;
363364
for (i = 0; i < list.nr; i++) {
364365
const char *path = list.entry[i].name;
365366
if (list.entry[i].is_submodule) {
366-
struct strbuf buf = STRBUF_INIT;
367-
367+
strbuf_reset(&buf);
368368
strbuf_addstr(&buf, path);
369369
if (remove_dir_recursively(&buf, 0))
370370
die(_("could not remove '%s'"), path);
371-
strbuf_release(&buf);
372371

373372
removed = 1;
374373
if (!remove_path_from_gitmodules(path))
@@ -382,6 +381,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
382381
if (!removed)
383382
die_errno("git rm: '%s'", path);
384383
}
384+
strbuf_release(&buf);
385385
if (gitmodules_modified)
386386
stage_updated_gitmodules();
387387
}

0 commit comments

Comments
 (0)