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

Re: [PATCH] use strvec_pushv() to add another strvec

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 19, 2026, 21:14 UTC
Message-ID
<xmqqwlz7iks3.fsf@gitster.g>
In-Reply-To
<ad46f86f-2ac0-4802-8e63-d854d594932d@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 9 quoted lines
> Simplify the code by letting strvec_pushv() add the items of a second
> strvec instead of pushing them one by one.
>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
>  fetch-pack.c | 8 ++------
>  git.c        | 3 +--
>  submodule.c  | 4 +---
>  3 files changed, 4 insertions(+), 11 deletions(-)
Nice.  Is this something we can make a coccinelle rule for?
Something like

@@ struct strvec SRC; struct strvec DST; size_t I; @@ - for (size_t I = 0; I < SRC.nr; I++) - strvec_push(&DST, SRC.v[I]); + strvec_pushv(&DST, SRC.v);

perhaps?
Will queue.
Show 54 quoted lines
> diff --git a/fetch-pack.c b/fetch-pack.c
> index 6ecd468ef7..a32224ed02 100644
> --- a/fetch-pack.c
> +++ b/fetch-pack.c
> @@ -1024,12 +1024,8 @@ static int get_pack(struct fetch_pack_args *args,
>  				     fsck_msg_types.buf);
>  	}
>  
> -	if (index_pack_args) {
> -		int i;
> -
> -		for (i = 0; i < cmd.args.nr; i++)
> -			strvec_push(index_pack_args, cmd.args.v[i]);
> -	}
> +	if (index_pack_args)
> +		strvec_pushv(index_pack_args, cmd.args.v);
>  
>  	sigchain_push(SIGPIPE, SIG_IGN);
>  
> diff --git a/git.c b/git.c
> index 2b212e6675..5a40eab8a2 100644
> --- a/git.c
> +++ b/git.c
> @@ -877,8 +877,7 @@ static int run_argv(struct strvec *args)
>  			commit_pager_choice();
>  
>  			strvec_push(&cmd.args, "git");
> -			for (size_t i = 0; i < args->nr; i++)
> -				strvec_push(&cmd.args, args->v[i]);
> +			strvec_pushv(&cmd.args, args->v);
>  
>  			trace_argv_printf(cmd.args.v, "trace: exec:");
>  
> diff --git a/submodule.c b/submodule.c
> index cd879a5cfe..4c8c674aa4 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -1815,7 +1815,6 @@ int fetch_submodules(struct repository *r,
>  		     int default_option,
>  		     int quiet, int max_parallel_jobs)
>  {
> -	int i;
>  	struct submodule_parallel_fetch spf = SPF_INIT;
>  	const struct run_process_parallel_opts opts = {
>  		.tr2_category = "submodule",
> @@ -1842,8 +1841,7 @@ int fetch_submodules(struct repository *r,
>  		die(_("index file corrupt"));
>  
>  	strvec_push(&spf.args, "fetch");
> -	for (i = 0; i < options->nr; i++)
> -		strvec_push(&spf.args, options->v[i]);
> +	strvec_pushv(&spf.args, options->v);
>  	strvec_push(&spf.args, "--recurse-submodules-default");
>  	/* default value, "--submodule-prefix" and its value are added later */
Previous: René ScharfeNext: René Scharfe
Message 2 of 6 in “use strvec_pushv() to add another strvec”
  1. use strvec_pushv() to add another strvecRené Scharfe, Mar 19, 2026
  2. Junio C HamanoMar 19, 2026
  3. René ScharfeMar 20, 2026
  4. use strvec_pushv() to add another strvecRené Scharfe, Mar 20, 2026
  5. Junio C HamanoMar 22, 2026
  6. René ScharfeMar 27, 2026

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.