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

[PATCH] submodule: use strvec_pushf() for --super-prefix

From
René Scharfe <l.s.r@web.de>
Date
Oct 23, 2022, 06:47 UTC
Message-ID
<7a4e2fc6-3e01-5683-2be5-13b7e67c7fe5@web.de>

absorb_git_dir_into_superproject() uses a strbuf and strvec_pushl() to build and add the --super-prefix option and its argument. Use a single strvec_pushf() call to add the stuck form instead, which reduces the code size and avoids a strbuf allocation and release. The same is already done in submodule_reset_index() and submodule_move_head().

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 submodule.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/submodule.c b/submodule.c
index bf7a2c7918..0a82aa9bdd 100644
--- a/submodule.c
+++ b/submodule.c
@@ -2361,26 +2361,20 @@ void absorb_git_dir_into_superproject(const char *path,

 	if (flags & ABSORB_GITDIR_RECURSE_SUBMODULES) {
 		struct child_process cp = CHILD_PROCESS_INIT;
-		struct strbuf sb = STRBUF_INIT;

 		if (flags & ~ABSORB_GITDIR_RECURSE_SUBMODULES)
 			BUG("we don't know how to pass the flags down?");

-		strbuf_addstr(&sb, get_super_prefix_or_empty());
-		strbuf_addstr(&sb, path);
-		strbuf_addch(&sb, '/');
-
 		cp.dir = path;
 		cp.git_cmd = 1;
 		cp.no_stdin = 1;
-		strvec_pushl(&cp.args, "--super-prefix", sb.buf,
-			     "submodule--helper",
+		strvec_pushf(&cp.args, "--super-prefix=%s%s/",
+			     get_super_prefix_or_empty(), path);
+		strvec_pushl(&cp.args, "submodule--helper",
 			     "absorbgitdirs", NULL);
 		prepare_submodule_repo_env(&cp.env);
 		if (run_command(&cp))
 			die(_("could not recurse into submodule '%s'"), path);
-
-		strbuf_release(&sb);
 	}
 }

--
2.38.1
Next: Jeff King
Message 1 of 2 in “submodule: use strvec_pushf() for --super-prefix”
  1. submodule: use strvec_pushf() for --super-prefixRené Scharfe, Oct 23, 2022
  2. Jeff KingOct 24, 2022

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.