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

[PATCH v4 01/16] midx-write: handle noop writes when converting incremental chains

From
Taylor Blau <me@ttaylorr.com>
Date
May 19, 2026, 15:57 UTC
Message-ID
<ead11e610c8c619de08cfd2736c12daeb2f45e20.1779206240.git.me@ttaylorr.com>
In-Reply-To
<cover.1779206239.git.me@ttaylorr.com>

When updating a MIDX, we optimize out writes that will result in an identical MIDX as the one we already have on disk. See b3bab9d2729 (midx-write: extract function to test whether MIDX needs updating, 2025-12-10) for more details on exactly which writes are optimized out.

If `midx_needs_update()` can't rule out any of the obvious cases (e.g., the checksum is invalid, we're requesting a different version, or performing compaction which always requires an update), then we compare the packs we're writing to the packs we already know about. If there are an equal number of packs being written as there are in any existing MIDX layer(s), then we compare the packs by their name.

This comparison fails when we have an incremental MIDX chain with at least two layers, since we do not recursively peel through earlier layers, instead treating the `->pack_names` array of the tip MIDX layer as containing all `m->num_packs + m->num_packs_in_base` packs.

Adjust this to instead look through the MIDX layers one by one when comparing pack names. While we're at it, fix a typo above in the same function.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 midx-write.c                            | 18 ++++++++++--------
 t/t5334-incremental-multi-pack-index.sh | 16 ++++++++++++++++
 2 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/midx-write.c b/midx-write.c
index a25cab75aba..9328f65a201 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -1152,7 +1152,7 @@ static bool midx_needs_update(struct multi_pack_index *midx, struct write_midx_c
 
 	/*
 	 * Ensure that we have a valid checksum before consulting the
-	 * exisiting MIDX in order to determine if we can avoid an
+	 * existing MIDX in order to determine if we can avoid an
 	 * update.
 	 *
 	 * This is necessary because the given MIDX is loaded directly
@@ -1208,14 +1208,16 @@ static bool midx_needs_update(struct multi_pack_index *midx, struct write_midx_c
 			BUG("same pack added twice?");
 	}
 
-	for (uint32_t i = 0; i < ctx->nr; i++) {
-		strbuf_reset(&buf);
-		strbuf_addstr(&buf, midx->pack_names[i]);
-		strbuf_strip_suffix(&buf, ".idx");
+	for (struct multi_pack_index *m = midx; m; m = m->base_midx) {
+		for (uint32_t i = 0; i < m->num_packs; i++) {
+			strbuf_reset(&buf);
+			strbuf_addstr(&buf, m->pack_names[i]);
+			strbuf_strip_suffix(&buf, ".idx");
 
-		if (!strset_contains(&packs, buf.buf))
-			goto out;
-		strset_remove(&packs, buf.buf);
+			if (!strset_contains(&packs, buf.buf))
+				goto out;
+			strset_remove(&packs, buf.buf);
+		}
 	}
 
 	needed = false;
diff --git a/t/t5334-incremental-multi-pack-index.sh b/t/t5334-incremental-multi-pack-index.sh
index 99c7d44d8e9..c9f5b4e87aa 100755
--- a/t/t5334-incremental-multi-pack-index.sh
+++ b/t/t5334-incremental-multi-pack-index.sh
@@ -132,4 +132,20 @@ test_expect_success 'relink existing MIDX layer' '
 
 '
 
+test_expect_success 'non-incremental write with existing incremental chain' '
+	git init non-incremental-write-with-existing &&
+	test_when_finished "rm -fr non-incremental-write-with-existing" &&
+
+	(
+		cd non-incremental-write-with-existing &&
+
+		git config set maintenance.auto false &&
+
+		write_midx_layer &&
+		write_midx_layer &&
+
+		git multi-pack-index write
+	)
+'
+
 test_done
-- 
2.54.0.175.g8bd0ec98dc3
Previous: Taylor BlauNext: Taylor Blau
Message 94 of 113 in “repack: incremental MIDX/bitmap-based repacking”
  1. 00/16 repack: incremental MIDX/bitmap-based repackingTaylor Blau, Mar 29, 2026
  2. 01/16 midx-write: handle noop writes when converting incremental chainsTaylor Blau, Mar 29, 2026
  3. Jeff KingMar 30, 2026
  4. Taylor BlauMar 31, 2026
  5. 02/16 midx: use `string_list` for retained MIDX filesTaylor Blau, Mar 29, 2026
  6. Jeff KingMar 30, 2026
  7. Taylor BlauMar 31, 2026
  8. 03/16 strvec: introduce `strvec_init_alloc()`Taylor Blau, Mar 29, 2026
  9. Jeff KingMar 30, 2026
  10. 04/16 midx: use `strvec` for `keep_hashes`Taylor Blau, Mar 29, 2026
  11. Jeff KingMar 30, 2026
  12. Taylor BlauMar 31, 2026
  13. Taylor BlauMar 31, 2026
  14. Jeff KingMar 31, 2026
  15. Taylor BlauApr 1, 2026
  16. Jeff KingApr 1, 2026
  17. 05/16 midx: introduce `--checksum-only` for incremental MIDX writesTaylor Blau, Mar 29, 2026
  18. Jeff KingMar 30, 2026
  19. Taylor BlauApr 2, 2026
  20. 06/16 midx: support custom `--base` for incremental MIDX writesTaylor Blau, Mar 29, 2026
  21. Jeff KingApr 7, 2026
  22. Taylor BlauApr 14, 2026
  23. 07/16 repack: track the ODB source via existing_packsTaylor Blau, Mar 29, 2026
  24. Jeff KingApr 7, 2026
  25. Taylor BlauApr 14, 2026
  26. 08/16 midx: expose `midx_layer_contains_pack()`Taylor Blau, Mar 29, 2026
  27. Jeff KingApr 7, 2026
  28. 09/16 repack-midx: factor out `repack_prepare_midx_command()`Taylor Blau, Mar 29, 2026
  29. 10/16 repack-midx: extract `repack_fill_midx_stdin_packs()`Taylor Blau, Mar 29, 2026
  30. Jeff KingApr 7, 2026
  31. 11/16 repack-geometry: prepare for incremental MIDX repackingTaylor Blau, Mar 29, 2026
  32. Jeff KingApr 7, 2026
  33. Elijah NewrenApr 16, 2026
  34. Taylor BlauApr 21, 2026
  35. 12/16 builtin/repack.c: convert `--write-midx` to an `OPT_CALLBACK`Taylor Blau, Mar 29, 2026
  36. Jeff KingApr 7, 2026
  37. 13/16 packfile: ensure `close_pack_revindex()` frees in-memory revindexTaylor Blau, Mar 29, 2026
  38. Jeff KingApr 7, 2026
  39. 14/16 repack: implement incremental MIDX repackingTaylor Blau, Mar 29, 2026
  40. Elijah NewrenApr 16, 2026
  41. Taylor BlauApr 21, 2026
  42. 15/16 repack: introduce `--write-midx=incremental`Taylor Blau, Mar 29, 2026
  43. Elijah NewrenApr 16, 2026
  44. Taylor BlauApr 21, 2026
  45. 16/16 repack: allow `--write-midx=incremental` without `--geometric`Taylor Blau, Mar 29, 2026
  46. Taylor BlauApr 14, 2026
  47. 00/16 repack: incremental MIDX/bitmap-based repackingTaylor Blau, Apr 21, 2026
  48. 01/16 midx-write: handle noop writes when converting incremental chainsTaylor Blau, Apr 21, 2026
  49. 02/16 midx: use `strset` for retained MIDX filesTaylor Blau, Apr 21, 2026
  50. 03/16 midx: build `keep_hashes` array in orderTaylor Blau, Apr 21, 2026
  51. 04/16 midx: use `strvec` for `keep_hashes`Taylor Blau, Apr 21, 2026
  52. 05/16 midx: introduce `--no-write-chain-file` for incremental MIDX writesTaylor Blau, Apr 21, 2026
  53. 06/16 midx: support custom `--base` for incremental MIDX writesTaylor Blau, Apr 21, 2026
  54. 07/16 repack: track the ODB source via existing_packsTaylor Blau, Apr 21, 2026
  55. 08/16 midx: expose `midx_layer_contains_pack()`Taylor Blau, Apr 21, 2026
  56. 09/16 repack-midx: factor out `repack_prepare_midx_command()`Taylor Blau, Apr 21, 2026
  57. 10/16 repack-midx: extract `repack_fill_midx_stdin_packs()`Taylor Blau, Apr 21, 2026
  58. Jeff KingApr 29, 2026
  59. Taylor BlauApr 29, 2026
  60. 11/16 repack-geometry: prepare for incremental MIDX repackingTaylor Blau, Apr 21, 2026
  61. 12/16 builtin/repack.c: convert `--write-midx` to an `OPT_CALLBACK`Taylor Blau, Apr 21, 2026
  62. 13/16 packfile: ensure `close_pack_revindex()` frees in-memory revindexTaylor Blau, Apr 21, 2026
  63. 14/16 repack: implement incremental MIDX repackingTaylor Blau, Apr 21, 2026
  64. Jeff KingApr 29, 2026
  65. Taylor BlauApr 29, 2026
  66. Jeff KingApr 29, 2026
  67. Taylor BlauApr 29, 2026
  68. 15/16 repack: introduce `--write-midx=incremental`Taylor Blau, Apr 21, 2026
  69. Taylor BlauApr 21, 2026
  70. 16/16 repack: allow `--write-midx=incremental` without `--geometric`Taylor Blau, Apr 21, 2026
  71. Elijah NewrenApr 22, 2026
  72. Jeff KingApr 29, 2026
  73. 00/16 repack: incremental MIDX/bitmap-based repackingTaylor Blau, Apr 30, 2026
  74. 01/16 midx-write: handle noop writes when converting incremental chainsTaylor Blau, Apr 30, 2026
  75. 02/16 midx: use `strset` for retained MIDX filesTaylor Blau, Apr 30, 2026
  76. 03/16 midx: build `keep_hashes` array in orderTaylor Blau, Apr 30, 2026
  77. 04/16 midx: use `strvec` for `keep_hashes`Taylor Blau, Apr 30, 2026
  78. 05/16 midx: introduce `--no-write-chain-file` for incremental MIDX writesTaylor Blau, Apr 30, 2026
  79. 06/16 midx: support custom `--base` for incremental MIDX writesTaylor Blau, Apr 30, 2026
  80. 07/16 repack: track the ODB source via existing_packsTaylor Blau, Apr 30, 2026
  81. 08/16 midx: expose `midx_layer_contains_pack()`Taylor Blau, Apr 30, 2026
  82. 09/16 repack-midx: factor out `repack_prepare_midx_command()`Taylor Blau, Apr 30, 2026
  83. SZEDER GáborMay 13, 2026
  84. 10/16 repack-midx: extract `repack_fill_midx_stdin_packs()`Taylor Blau, Apr 30, 2026
  85. 11/16 repack-geometry: prepare for incremental MIDX repackingTaylor Blau, Apr 30, 2026
  86. 12/16 builtin/repack.c: convert `--write-midx` to an `OPT_CALLBACK`Taylor Blau, Apr 30, 2026
  87. 13/16 packfile: ensure `close_pack_revindex()` frees in-memory revindexTaylor Blau, Apr 30, 2026
  88. 14/16 repack: implement incremental MIDX repackingTaylor Blau, Apr 30, 2026
  89. 15/16 repack: introduce `--write-midx=incremental`Taylor Blau, Apr 30, 2026
  90. Jeff KingMay 13, 2026
  91. 16/16 repack: allow `--write-midx=incremental` without `--geometric`Taylor Blau, Apr 30, 2026
  92. Jeff KingMay 1, 2026
  93. 00/16 repack: incremental MIDX/bitmap-based repackingTaylor Blau, May 19, 2026
  94. 01/16 midx-write: handle noop writes when converting incremental chainsTaylor Blau, May 19, 2026
  95. 02/16 midx: use `strset` for retained MIDX filesTaylor Blau, May 19, 2026
  96. 03/16 midx: build `keep_hashes` array in orderTaylor Blau, May 19, 2026
  97. 04/16 midx: use `strvec` for `keep_hashes`Taylor Blau, May 19, 2026
  98. 05/16 midx: introduce `--no-write-chain-file` for incremental MIDX writesTaylor Blau, May 19, 2026
  99. 06/16 midx: support custom `--base` for incremental MIDX writesTaylor Blau, May 19, 2026
  100. SZEDER GáborJun 12, 2026
  101. Junio C HamanoJun 12, 2026
  102. Taylor BlauJun 12, 2026
  103. Taylor BlauJun 12, 2026
  104. 07/16 repack: track the ODB source via existing_packsTaylor Blau, May 19, 2026
  105. 08/16 midx: expose `midx_layer_contains_pack()`Taylor Blau, May 19, 2026
  106. 09/16 repack-midx: factor out `repack_prepare_midx_command()`Taylor Blau, May 19, 2026
  107. 10/16 repack-midx: extract `repack_fill_midx_stdin_packs()`Taylor Blau, May 19, 2026
  108. 11/16 repack-geometry: prepare for incremental MIDX repackingTaylor Blau, May 19, 2026
  109. 12/16 builtin/repack.c: convert `--write-midx` to an `OPT_CALLBACK`Taylor Blau, May 19, 2026
  110. 13/16 packfile: ensure `close_pack_revindex()` frees in-memory revindexTaylor Blau, May 19, 2026
  111. 14/16 repack: implement incremental MIDX repackingTaylor Blau, May 19, 2026
  112. 15/16 repack: introduce `--write-midx=incremental`Taylor Blau, May 19, 2026
  113. 16/16 repack: allow `--write-midx=incremental` without `--geometric`Taylor Blau, May 19, 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.