Subject: Re: [PATCH 08/11] midx-write.c: avoid directly managed temporary strbuf

From: Junio C Hamano <[email-masked]>
Date: Mon, 25 Mar 2024 13:33:11 -0700

Taylor Blau <[email-masked]> writes:

> In midx-write.c::midx_repack(), we construct the command-line arguments
> for a pack-objects invocation which will combine objects from the packs
> below our `--batch-size` option.
>
> To construct the base name of the output pack, we use a temporary
> strbuf, and then push the result of that onto the strvec which holds the
> command-line arguments, after which point we release the strbuf.
>
> We could replace this by doing something like:
>
>     struct strbuf buf = STRBUF_INIT;
>     strbuf_addf(&buf, "%s/pack/pack", object_dir);
>     strvec_push_nodup(&cmd.args, strbuf_detach(&buf));

Hmph, I thought I saw another patch recently that uses
strvec_pushf() to simplify such a sequence.  Does the technique
apply here as well?

Ah, yes, exactly.  See <[email-masked]>

> @@ -1473,10 +1472,6 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
>  
>  	strvec_push(&cmd.args, "pack-objects");
>  
> -	strbuf_addstr(&base_name, object_dir);
> -	strbuf_addstr(&base_name, "/pack/pack");
> -	strvec_push(&cmd.args, base_name.buf);
> -
>  	if (delta_base_offset)
>  		strvec_push(&cmd.args, "--delta-base-offset");
>  	if (use_delta_islands)
> @@ -1487,7 +1482,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
>  	else
>  		strvec_push(&cmd.args, "-q");
>  
> -	strbuf_release(&base_name);
> +	strvec_pushf(&cmd.args, "%s/pack/pack", object_dir);
>  
>  	cmd.git_cmd = 1;
>  	cmd.in = cmd.out = -1;