Skip to content

Commit b7fb136

Browse files
committed
Merge branch 'rs/rm-strbuf-optim' into maint
The use of strbuf in "git rm" to build filename to remove was a bit suboptimal, which has been fixed. * rs/rm-strbuf-optim: rm: reuse strbuf for all remove_dir_recursively() calls
2 parents 60b84ba + deb8e15 commit b7fb136

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)