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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 25, 2024, 20:33 UTC
Message-ID
<xmqqv85ahx14.fsf@gitster.g>
In-Reply-To
<8e32755c492d20eec02c81351d249ce34cc6d7b9.1711387439.git.me@ttaylorr.com>
Taylor Blau <me@ttaylorr.com> writes:
Show 13 quoted lines
> 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 <9483038c-9529-4243-9b9a-97254fac29c1@web.de>
Show 20 quoted lines
> @@ -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;
Previous: Taylor BlauNext: Taylor Blau
Message 12 of 30 in “midx: split MIDX writing routines into midx-write.c, cleanup”
  1. 00/11 midx: split MIDX writing routines into midx-write.c, cleanupTaylor Blau, Mar 25, 2024
  2. 01/11 midx-write: initial commitTaylor Blau, Mar 25, 2024
  3. Junio C HamanoMar 25, 2024
  4. Taylor BlauMar 25, 2024
  5. 02/11 midx: extern a pair of shared functionsTaylor Blau, Mar 25, 2024
  6. 03/11 midx: move `midx_repack` (and related functions) to midx-write.cTaylor Blau, Mar 25, 2024
  7. 04/11 midx: move `expire_midx_packs` to midx-write.cTaylor Blau, Mar 25, 2024
  8. 05/11 midx: move `write_midx_file_only` to midx-write.cTaylor Blau, Mar 25, 2024
  9. 06/11 midx: move `write_midx_file` to midx-write.cTaylor Blau, Mar 25, 2024
  10. 07/11 midx: move `write_midx_internal` (and related functions) to midx-write.cTaylor Blau, Mar 25, 2024
  11. 08/11 midx-write.c: avoid directly managed temporary strbufTaylor Blau, Mar 25, 2024
  12. Junio C HamanoMar 25, 2024
  13. Taylor BlauMar 25, 2024
  14. 09/11 midx-write.c: factor out common want_included_pack() routineTaylor Blau, Mar 25, 2024
  15. Junio C HamanoMar 25, 2024
  16. Jeff KingMar 27, 2024
  17. 10/11 midx-write.c: check count of packs to repack after groupingTaylor Blau, Mar 25, 2024
  18. Junio C HamanoMar 25, 2024
  19. Taylor BlauMar 25, 2024
  20. 11/11 midx-write.c: use `--stdin-packs` when repackingTaylor Blau, Mar 25, 2024
  21. Jeff KingMar 27, 2024
  22. Jeff KingMar 27, 2024
  23. 0/4 midx: split MIDX writing routines into midx-write.c, cleanupTaylor Blau, Apr 1, 2024
  24. 1/4 midx-write: move writing-related functions from midx.cTaylor Blau, Apr 1, 2024
  25. 2/4 midx-write.c: factor out common want_included_pack() routineTaylor Blau, Apr 1, 2024
  26. Patrick SteinhardtApr 2, 2024
  27. 3/4 midx-write.c: check count of packs to repack after groupingTaylor Blau, Apr 1, 2024
  28. 4/4 midx-write.c: use `--stdin-packs` when repackingTaylor Blau, Apr 1, 2024
  29. Junio C HamanoApr 1, 2024
  30. Patrick SteinhardtApr 2, 2024

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.