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

[RFC PATCH 02/14] strvec: introduce `strvec_init_alloc()`

From
Taylor Blau <me@ttaylorr.com>
Date
Feb 25, 2026, 00:21 UTC
Message-ID
<50efbbb0fe8d897d7c4cd51489af4cb4c4c49d02.1771978829.git.me@ttaylorr.com>
In-Reply-To
<cover.1771978829.git.me@ttaylorr.com>

When the caller knows upfront how many elements will be pushed onto a `strvec`, it is useful to pre-allocate enough space in the array to fit that many elements (and one additional slot to store NULL, indicating the end of the list.)

Introduce `strvec_init_alloc()`, which allocates the backing array large enough to hold `alloc` elements and the termination marker without further reallocation.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 strvec.c | 7 +++++++
 strvec.h | 5 +++++
 2 files changed, 12 insertions(+)
diff --git a/strvec.c b/strvec.c
index f8de79f5579..f7f32a53b56 100644
--- a/strvec.c
+++ b/strvec.c
@@ -10,6 +10,13 @@ void strvec_init(struct strvec *array)
 	memcpy(array, &blank, sizeof(*array));
 }
 
+void strvec_init_alloc(struct strvec *array, size_t alloc)
+{
+	CALLOC_ARRAY(array->v, st_add(alloc, 1));
+	array->nr = 0;
+	array->alloc = alloc + 1;
+}
+
 void strvec_push_nodup(struct strvec *array, char *value)
 {
 	if (array->v == empty_strvec)
diff --git a/strvec.h b/strvec.h
index f74e061e141..34cb1f939f0 100644
--- a/strvec.h
+++ b/strvec.h
@@ -43,6 +43,11 @@ struct strvec {
  */
 void strvec_init(struct strvec *);
 
+/*
+ * Initializes an array large enough to store `alloc` elements.
+ */
+void strvec_init_alloc(struct strvec *, size_t alloc);
+
 /* Push a copy of a string onto the end of the array. */
 const char *strvec_push(struct strvec *, const char *);
 
-- 
2.53.0.185.g29bc4dff628
Previous: Taylor BlauNext: Junio C Hamano
Message 7 of 21 in “repack: incremental MIDX/bitmap-based repacking”
  1. 00/14 repack: incremental MIDX/bitmap-based repackingTaylor Blau, Feb 25, 2026
  2. 06/14 repack: track the ODB source via existing_packsTaylor Blau, Feb 25, 2026
  3. Taylor BlauFeb 25, 2026
  4. 01/14 midx: use `string_list` for retained MIDX filesTaylor Blau, Feb 25, 2026
  5. Junio C HamanoFeb 26, 2026
  6. Taylor BlauFeb 27, 2026
  7. 02/14 strvec: introduce `strvec_init_alloc()`Taylor Blau, Feb 25, 2026
  8. Junio C HamanoFeb 26, 2026
  9. Junio C HamanoFeb 26, 2026
  10. Taylor BlauFeb 27, 2026
  11. 03/14 midx: use `strvec` for `keep_hashes`Taylor Blau, Feb 25, 2026
  12. 04/14 midx: introduce `--checksum-only` for incremental MIDX writesTaylor Blau, Feb 25, 2026
  13. 05/14 midx: support custom `--base` for incremental MIDX writesTaylor Blau, Feb 25, 2026
  14. 07/14 midx: expose `midx_layer_contains_pack()`Taylor Blau, Feb 25, 2026
  15. 08/14 repack-midx: factor out `repack_prepare_midx_command()`Taylor Blau, Feb 25, 2026
  16. 09/14 repack-midx: extract `repack_fill_midx_stdin_packs()`Taylor Blau, Feb 25, 2026
  17. 10/14 repack-geometry: prepare for incremental MIDX repackingTaylor Blau, Feb 25, 2026
  18. 11/14 builtin/repack.c: convert `--write-midx` to an `OPT_CALLBACK`Taylor Blau, Feb 25, 2026
  19. 12/14 repack: implement incremental MIDX repackingTaylor Blau, Feb 25, 2026
  20. 13/14 repack: introduce `--write-midx=incremental`Taylor Blau, Feb 25, 2026
  21. 14/14 repack: allow `--write-midx=incremental` without `--geometric`Taylor Blau, Feb 25, 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.