git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] submodule: use strvec_pushf() for --super-prefix
@ 2022-10-23  6:47 René Scharfe
  2022-10-24 23:50 ` Jeff King
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2022-10-23  6:47 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] submodule: use strvec_pushf() for --super-prefix
  2022-10-23  6:47 [PATCH] submodule: use strvec_pushf() for --super-prefix René Scharfe
@ 2022-10-24 23:50 ` Jeff King
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2022-10-24 23:50 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git List, Junio C Hamano

On Sun, Oct 23, 2022 at 08:47:35AM +0200, René Scharfe wrote:

> 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().

Nice. Unlike some of the earlier discussion around child_process args,
this one seems like a very clear win.

-Peff

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-25  0:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-23  6:47 [PATCH] submodule: use strvec_pushf() for --super-prefix René Scharfe
2022-10-24 23:50 ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).