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>
René Scharfe committed
Jul 9, 2016 at 16:47 UTC
deb8e15a19790b2c526b599620407d2f5c1cefcb
1 file changed
+3
-2
builtin/rm.c
+3
-2
@@ -387,6 +387,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
387
*/
388
if (!index_only) {
389
int removed = 0, gitmodules_modified = 0;
390
+ struct strbuf buf = STRBUF_INIT;
391
for (i = 0; i < list.nr; i++) {
392
const char *path = list.entry[i].name;
393
if (list.entry[i].is_submodule) {
@@ -398,7 +399,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
399
continue;
400
}
401
} else {
401
- struct strbuf buf = STRBUF_INIT;
402
+ strbuf_reset(&buf);
403
strbuf_addstr(&buf, path);
404
if (!remove_dir_recursively(&buf, 0)) {
405
removed = 1;
@@ -410,7 +411,6 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
411
/* Submodule was removed by user */
412
if (!remove_path_from_gitmodules(path))
413
gitmodules_modified = 1;
413
- strbuf_release(&buf);
414
/* Fallthrough and let remove_path() fail. */
415
}
416
}
@@ -421,6 +421,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
421
if (!removed)
422
die_errno("git rm: '%s'", path);
423
}
424
+ strbuf_release(&buf);
425
if (gitmodules_modified)
426
stage_updated_gitmodules();
427
}