git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] rm: reuse strbuf for all remove_dir_recursively() calls, again

From
Stefan Beller <sbeller@google.com>
Date
Feb 13, 2017, 21:03 UTC
Message-ID
<CAGZ79kapfeEpX5Y5Y5ebBMjePvrXhOM80KQWU4DuLs9=ApRHTw@mail.gmail.com>
In-Reply-To
<f2549b5b-b3c8-3935-cdb9-9908914195b6@web.de>
On Sat, Feb 11, 2017 at 11:51 AM, René Scharfe <l.s.r@web.de> wrote:
Show 11 quoted lines
> 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 deb8e15a (rm: reuse strbuf for all
> remove_dir_recursively() calls), but was reverted as a side-effect of
> 55856a35 (rm: absorb a submodules git dir before deletion). Reinstate
> the optimization.
>
> Signed-off-by: Rene Scharfe <l.s.r@web.de>
> ---
> Was deb8e15a a rebase victim?
(I do not recall it off the top of my head)

That commit was merged at 03f25e85, Merge branch 'rs/rm-strbuf-optim', but it looks like it was reverted as part of 55856a35b2 (rm: absorb a submodules git dir before deletion)

Looking through the discussion at https://public-inbox.org/git/xmqqmvfich2e.fsf@gitster.mtv.corp.google.com/ there was no apparent signs of confusion, but a reroll was promised, that I cannot find on the list.

Anyway, the patch below looks good to me.

Thanks, Stefan

Show 37 quoted lines
>
>  builtin/rm.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/rm.c b/builtin/rm.c
> index 452170a3ab..fb79dcab18 100644
> --- a/builtin/rm.c
> +++ b/builtin/rm.c
> @@ -360,15 +360,14 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
>          */
>         if (!index_only) {
>                 int removed = 0, gitmodules_modified = 0;
> +               struct strbuf buf = STRBUF_INIT;
>                 for (i = 0; i < list.nr; i++) {
>                         const char *path = list.entry[i].name;
>                         if (list.entry[i].is_submodule) {
> -                               struct strbuf buf = STRBUF_INIT;
> -
> +                               strbuf_reset(&buf);
>                                 strbuf_addstr(&buf, path);
>                                 if (remove_dir_recursively(&buf, 0))
>                                         die(_("could not remove '%s'"), path);
> -                               strbuf_release(&buf);
>
>                                 removed = 1;
>                                 if (!remove_path_from_gitmodules(path))
> @@ -382,6 +381,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
>                         if (!removed)
>                                 die_errno("git rm: '%s'", path);
>                 }
> +               strbuf_release(&buf);
>                 if (gitmodules_modified)
>                         stage_updated_gitmodules();
>         }
> --
> 2.11.1
>
Previous: René Scharfe
Message 2 of 2 in “rm: reuse strbuf for all remove_dir_recursively() calls, again”
  1. rm: reuse strbuf for all remove_dir_recursively() calls, againRené Scharfe, Feb 11, 2017
  2. Stefan BellerFeb 13, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.