Skip to content

Commit deb8e15

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 50b4a78 commit deb8e15

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

builtin/rm.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
387387
*/
388388
if (!index_only) {
389389
int removed = 0, gitmodules_modified = 0;
390+
struct strbuf buf = STRBUF_INIT;
390391
for (i = 0; i < list.nr; i++) {
391392
const char *path = list.entry[i].name;
392393
if (list.entry[i].is_submodule) {
@@ -398,7 +399,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
398399
continue;
399400
}
400401
} else {
401-
struct strbuf buf = STRBUF_INIT;
402+
strbuf_reset(&buf);
402403
strbuf_addstr(&buf, path);
403404
if (!remove_dir_recursively(&buf, 0)) {
404405
removed = 1;
@@ -410,7 +411,6 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
410411
/* Submodule was removed by user */
411412
if (!remove_path_from_gitmodules(path))
412413
gitmodules_modified = 1;
413-
strbuf_release(&buf);
414414
/* Fallthrough and let remove_path() fail. */
415415
}
416416
}
@@ -421,6 +421,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
421421
if (!removed)
422422
die_errno("git rm: '%s'", path);
423423
}
424+
strbuf_release(&buf);
424425
if (gitmodules_modified)
425426
stage_updated_gitmodules();
426427
}

0 commit comments

Comments
 (0)