{"thread":{"id":"42808","subject":"[PATCH] rm: reuse strbuf for all remove_dir_recursively() calls","startedAt":"2016-07-09T14:47:22Z","lastAt":"2016-07-09T14:47:22Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"291105","messageId":"57810E68.5040301@web.de","threadId":"42808","inReplyTo":null,"subject":"[PATCH] rm: reuse strbuf for all remove_dir_recursively() calls","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2016-07-09T14:47:04Z","receivedAt":"2016-07-09T14:47:22Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Don't throw the memory allocated for remove_dir_recursively() away after\na single call, use it for the other entries as well instead.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n builtin/rm.c | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex 8abb020..b2fee3e 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -387,6 +387,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \t */\n \tif (!index_only) {\n \t\tint removed = 0, gitmodules_modified = 0;\n+\t\tstruct strbuf buf = STRBUF_INIT;\n \t\tfor (i = 0; i < list.nr; i++) {\n \t\t\tconst char *path = list.entry[i].name;\n \t\t\tif (list.entry[i].is_submodule) {\n@@ -398,7 +399,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \t\t\t\t\t\tcontinue;\n \t\t\t\t\t}\n \t\t\t\t} else {\n-\t\t\t\t\tstruct strbuf buf = STRBUF_INIT;\n+\t\t\t\t\tstrbuf_reset(&buf);\n \t\t\t\t\tstrbuf_addstr(&buf, path);\n \t\t\t\t\tif (!remove_dir_recursively(&buf, 0)) {\n \t\t\t\t\t\tremoved = 1;\n@@ -410,7 +411,6 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \t\t\t\t\t\t/* Submodule was removed by user */\n \t\t\t\t\t\tif (!remove_path_from_gitmodules(path))\n \t\t\t\t\t\t\tgitmodules_modified = 1;\n-\t\t\t\t\tstrbuf_release(&buf);\n \t\t\t\t\t/* Fallthrough and let remove_path() fail. */\n \t\t\t\t}\n \t\t\t}\n@@ -421,6 +421,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \t\t\tif (!removed)\n \t\t\t\tdie_errno(\"git rm: '%s'\", path);\n \t\t}\n+\t\tstrbuf_release(&buf);\n \t\tif (gitmodules_modified)\n \t\t\tstage_updated_gitmodules();\n \t}\n-- \n2.9.0\n\n"}]}