{"thread":{"id":"58677","subject":"[PATCH] submodule: use strvec_pushf() for --super-prefix","startedAt":"2022-10-23T06:47:46Z","lastAt":"2022-10-25T00:59:36Z","messageCount":2,"participants":["René Scharfe","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"465596","messageId":"7a4e2fc6-3e01-5683-2be5-13b7e67c7fe5@web.de","threadId":"58677","inReplyTo":null,"subject":"[PATCH] submodule: use strvec_pushf() for --super-prefix","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2022-10-23T06:47:35Z","receivedAt":"2022-10-23T06:47:46Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"absorb_git_dir_into_superproject() uses a strbuf and strvec_pushl() to\nbuild and add the --super-prefix option and its argument.  Use a single\nstrvec_pushf() call to add the stuck form instead, which reduces the\ncode size and avoids a strbuf allocation and release.  The same is\nalready done in submodule_reset_index() and submodule_move_head().\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n submodule.c | 12 +++---------\n 1 file changed, 3 insertions(+), 9 deletions(-)\n\ndiff --git a/submodule.c b/submodule.c\nindex bf7a2c7918..0a82aa9bdd 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -2361,26 +2361,20 @@ void absorb_git_dir_into_superproject(const char *path,\n\n \tif (flags & ABSORB_GITDIR_RECURSE_SUBMODULES) {\n \t\tstruct child_process cp = CHILD_PROCESS_INIT;\n-\t\tstruct strbuf sb = STRBUF_INIT;\n\n \t\tif (flags & ~ABSORB_GITDIR_RECURSE_SUBMODULES)\n \t\t\tBUG(\"we don't know how to pass the flags down?\");\n\n-\t\tstrbuf_addstr(&sb, get_super_prefix_or_empty());\n-\t\tstrbuf_addstr(&sb, path);\n-\t\tstrbuf_addch(&sb, '/');\n-\n \t\tcp.dir = path;\n \t\tcp.git_cmd = 1;\n \t\tcp.no_stdin = 1;\n-\t\tstrvec_pushl(&cp.args, \"--super-prefix\", sb.buf,\n-\t\t\t     \"submodule--helper\",\n+\t\tstrvec_pushf(&cp.args, \"--super-prefix=%s%s/\",\n+\t\t\t     get_super_prefix_or_empty(), path);\n+\t\tstrvec_pushl(&cp.args, \"submodule--helper\",\n \t\t\t     \"absorbgitdirs\", NULL);\n \t\tprepare_submodule_repo_env(&cp.env);\n \t\tif (run_command(&cp))\n \t\t\tdie(_(\"could not recurse into submodule '%s'\"), path);\n-\n-\t\tstrbuf_release(&sb);\n \t}\n }\n\n--\n2.38.1\n"},{"id":"465674","messageId":"Y1ck2p6ykHRo5cCg@coredump.intra.peff.net","threadId":"58677","inReplyTo":"7a4e2fc6-3e01-5683-2be5-13b7e67c7fe5@web.de","subject":"Re: [PATCH] submodule: use strvec_pushf() for --super-prefix","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2022-10-24T23:50:50Z","receivedAt":"2022-10-25T00:59:36Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Oct 23, 2022 at 08:47:35AM +0200, René Scharfe wrote:\n\n> absorb_git_dir_into_superproject() uses a strbuf and strvec_pushl() to\n> build and add the --super-prefix option and its argument.  Use a single\n> strvec_pushf() call to add the stuck form instead, which reduces the\n> code size and avoids a strbuf allocation and release.  The same is\n> already done in submodule_reset_index() and submodule_move_head().\n\nNice. Unlike some of the earlier discussion around child_process args,\nthis one seems like a very clear win.\n\n-Peff\n"}]}