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

[PATCH v3 03/19] midx: teach `nth_midxed_pack_int_id()` about incremental MIDXs

From
Taylor Blau <me@ttaylorr.com>
Date
Aug 6, 2024, 15:37 UTC
Message-ID
<5cd742b67761913bd9693102a8b823f353b60f7b.1722958596.git.me@ttaylorr.com>
In-Reply-To
<cover.1722958595.git.me@ttaylorr.com>

The function `nth_midxed_pack_int_id()` takes in a object position in MIDX lexicographic order and returns an identifier of the pack from which that object was selected in the MIDX.

Currently, the given object position is an index into the lexicographic order of objects in a single MIDX. Change this position to instead refer into the concatenated lexicographic order of all MIDXs in a MIDX chain.

This has two visible effects within the implementation of `prepare_midx_pack()`:

  - First, the given position is now an index into the concatenated
    lexicographic order of all MIDXs in the order in which they appear
    in the MIDX chain.
  - Second the pack ID returned from this function is now also in the
    concatenated order of packs among all layers of the MIDX chain in
    the same order that they appear in the MIDX chain.

To do this, introduce the first of two general purpose helpers, this one being `midx_for_object()`. `midx_for_object()` takes a double pointer to a `struct multi_pack_index` as well as an object `pos` in terms of the entire MIDX chain[^1].

The function chases down the '->base_midx' field until it finds the MIDX layer within the chain that contains the given object. It then:

  - modifies the double pointer to point to the containing MIDX, instead
    of the tip of the chain, and
  - returns the MIDX-local position[^2] at which the given object can be
    found.

Use this function within `nth_midxed_pack_int_id()` so that the `pos` it expects is now relative to the entire MIDX chain, and that it returns the appropriate pack position for that object.

[^1]: As a reminder, this means that the object is identified among the
  objects contained in all layers of the incremental MIDX chain, not any
  particular layer. For example, consider MIDX chain with two individual
  MIDXs, one with 4 objects and another with 3 objects. If the MIDX with
  4 objects appears earlier in the chain, then asking for object 6 would
  return the second object in the MIDX with 3 objects.
[^2]: Building on the previous example, asking for object 6 in a MIDX
  chain with (4, 3) objects, respectively, this would set the double
  pointer to point at the MIDX containing three objects, and would
  return an index to the second object within that MIDX.
Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 midx.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/midx.c b/midx.c
index 3992b05465..39d358da20 100644
--- a/midx.c
+++ b/midx.c
@@ -242,6 +242,23 @@ void close_midx(struct multi_pack_index *m)
 	free(m);
 }
 
+static uint32_t midx_for_object(struct multi_pack_index **_m, uint32_t pos)
+{
+	struct multi_pack_index *m = *_m;
+	while (m && pos < m->num_objects_in_base)
+		m = m->base_midx;
+
+	if (!m)
+		BUG("NULL multi-pack-index for object position: %"PRIu32, pos);
+
+	if (pos >= m->num_objects + m->num_objects_in_base)
+		die(_("invalid MIDX object position, MIDX is likely corrupt"));
+
+	*_m = m;
+
+	return pos - m->num_objects_in_base;
+}
+
 int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id)
 {
 	struct strbuf pack_name = STRBUF_INIT;
@@ -334,8 +351,10 @@ off_t nth_midxed_offset(struct multi_pack_index *m, uint32_t pos)
 
 uint32_t nth_midxed_pack_int_id(struct multi_pack_index *m, uint32_t pos)
 {
-	return get_be32(m->chunk_object_offsets +
-			(off_t)pos * MIDX_CHUNK_OFFSET_WIDTH);
+	pos = midx_for_object(&m, pos);
+
+	return m->num_packs_in_base + get_be32(m->chunk_object_offsets +
+					       (off_t)pos * MIDX_CHUNK_OFFSET_WIDTH);
 }
 
 int fill_midx_entry(struct repository *r,
-- 
2.46.0.46.g406f326d27.dirty
Previous: Taylor BlauNext: Taylor Blau
Message 85 of 102 in “midx: incremental multi-pack indexes, part one”
  1. 00/19 midx: incremental multi-pack indexes, part oneTaylor Blau, Jun 6, 2024
  2. 01/19 Documentation: describe incremental MIDX formatTaylor Blau, Jun 6, 2024
  3. 02/19 midx: add new fields for incremental MIDX chainsTaylor Blau, Jun 6, 2024
  4. 03/19 midx: teach `nth_midxed_pack_int_id()` about incremental MIDXsTaylor Blau, Jun 6, 2024
  5. 04/19 midx: teach `prepare_midx_pack()` about incremental MIDXsTaylor Blau, Jun 6, 2024
  6. 05/19 midx: teach `nth_midxed_object_oid()` about incremental MIDXsTaylor Blau, Jun 6, 2024
  7. 06/19 midx: teach `nth_bitmapped_pack()` about incremental MIDXsTaylor Blau, Jun 6, 2024
  8. 07/19 midx: introduce `bsearch_one_midx()`Taylor Blau, Jun 6, 2024
  9. 08/19 midx: teach `bsearch_midx()` about incremental MIDXsTaylor Blau, Jun 6, 2024
  10. 09/19 midx: teach `nth_midxed_offset()` about incremental MIDXsTaylor Blau, Jun 6, 2024
  11. 10/19 midx: teach `fill_midx_entry()` about incremental MIDXsTaylor Blau, Jun 6, 2024
  12. 11/19 midx: remove unused `midx_locate_pack()`Taylor Blau, Jun 6, 2024
  13. 12/19 midx: teach `midx_contains_pack()` about incremental MIDXsTaylor Blau, Jun 6, 2024
  14. 13/19 midx: teach `midx_preferred_pack()` about incremental MIDXsTaylor Blau, Jun 6, 2024
  15. 14/19 midx: teach `midx_fanout_add_midx_fanout()` about incremental MIDXsTaylor Blau, Jun 6, 2024
  16. 15/19 midx: support reading incremental MIDX chainsTaylor Blau, Jun 6, 2024
  17. 16/19 midx: implement verification support for incremental MIDXsTaylor Blau, Jun 6, 2024
  18. 17/19 t: retire 'GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP'Taylor Blau, Jun 6, 2024
  19. 18/19 t/t5313-pack-bounds-checks.sh: prepare for sub-directoriesTaylor Blau, Jun 6, 2024
  20. 19/19 midx: implement support for writing incremental MIDX chainsTaylor Blau, Jun 6, 2024
  21. Taylor BlauJun 6, 2024
  22. Junio C HamanoJun 7, 2024
  23. Taylor BlauJun 7, 2024
  24. Junio C HamanoJun 7, 2024
  25. Taylor BlauJun 7, 2024
  26. Junio C HamanoJun 25, 2024
  27. Elijah NewrenJun 26, 2024
  28. 00/19 midx: incremental multi-pack indexes, part oneTaylor Blau, Jul 17, 2024
  29. 01/19 Documentation: describe incremental MIDX formatTaylor Blau, Jul 17, 2024
  30. Jeff KingAug 1, 2024
  31. Taylor BlauAug 1, 2024
  32. 02/19 midx: add new fields for incremental MIDX chainsTaylor Blau, Jul 17, 2024
  33. Jeff KingAug 1, 2024
  34. Taylor BlauAug 1, 2024
  35. 03/19 midx: teach `nth_midxed_pack_int_id()` about incremental MIDXsTaylor Blau, Jul 17, 2024
  36. Jeff KingAug 1, 2024
  37. Taylor BlauAug 1, 2024
  38. 04/19 midx: teach `prepare_midx_pack()` about incremental MIDXsTaylor Blau, Jul 17, 2024
  39. Jeff KingAug 1, 2024
  40. Taylor BlauAug 1, 2024
  41. 05/19 midx: teach `nth_midxed_object_oid()` about incremental MIDXsTaylor Blau, Jul 17, 2024
  42. Jeff KingAug 1, 2024
  43. Taylor BlauAug 1, 2024
  44. 06/19 midx: teach `nth_bitmapped_pack()` about incremental MIDXsTaylor Blau, Jul 17, 2024
  45. Jeff KingAug 1, 2024
  46. Taylor BlauAug 1, 2024
  47. 07/19 midx: introduce `bsearch_one_midx()`Taylor Blau, Jul 17, 2024
  48. Jeff KingAug 1, 2024
  49. Taylor BlauAug 1, 2024
  50. 08/19 midx: teach `bsearch_midx()` about incremental MIDXsTaylor Blau, Jul 17, 2024
  51. Jeff KingAug 1, 2024
  52. 09/19 midx: teach `nth_midxed_offset()` about incremental MIDXsTaylor Blau, Jul 17, 2024
  53. Jeff KingAug 1, 2024
  54. 10/19 midx: teach `fill_midx_entry()` about incremental MIDXsTaylor Blau, Jul 17, 2024
  55. Jeff KingAug 1, 2024
  56. Taylor BlauAug 1, 2024
  57. 11/19 midx: remove unused `midx_locate_pack()`Taylor Blau, Jul 17, 2024
  58. Jeff KingAug 1, 2024
  59. Taylor BlauAug 1, 2024
  60. 12/19 midx: teach `midx_contains_pack()` about incremental MIDXsTaylor Blau, Jul 17, 2024
  61. Jeff KingAug 1, 2024
  62. 13/19 midx: teach `midx_preferred_pack()` about incremental MIDXsTaylor Blau, Jul 17, 2024
  63. Jeff KingAug 1, 2024
  64. Taylor BlauAug 1, 2024
  65. 14/19 midx: teach `midx_fanout_add_midx_fanout()` about incremental MIDXsTaylor Blau, Jul 17, 2024
  66. Jeff KingAug 1, 2024
  67. Taylor BlauAug 1, 2024
  68. 15/19 midx: support reading incremental MIDX chainsTaylor Blau, Jul 17, 2024
  69. Jeff KingAug 1, 2024
  70. Taylor BlauAug 1, 2024
  71. 16/19 midx: implement verification support for incremental MIDXsTaylor Blau, Jul 17, 2024
  72. Jeff KingAug 1, 2024
  73. 17/19 t: retire 'GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP'Taylor Blau, Jul 17, 2024
  74. Jeff KingAug 1, 2024
  75. Taylor BlauAug 1, 2024
  76. 18/19 t/t5313-pack-bounds-checks.sh: prepare for sub-directoriesTaylor Blau, Jul 17, 2024
  77. 19/19 midx: implement support for writing incremental MIDX chainsTaylor Blau, Jul 17, 2024
  78. Jeff KingAug 1, 2024
  79. Taylor BlauAug 1, 2024
  80. Jeff KingAug 1, 2024
  81. Taylor BlauAug 1, 2024
  82. 00/19 midx: incremental multi-pack indexes, part oneTaylor Blau, Aug 6, 2024
  83. 01/19 Documentation: describe incremental MIDX formatTaylor Blau, Aug 6, 2024
  84. 02/19 midx: add new fields for incremental MIDX chainsTaylor Blau, Aug 6, 2024
  85. 03/19 midx: teach `nth_midxed_pack_int_id()` about incremental MIDXsTaylor Blau, Aug 6, 2024
  86. 04/19 midx: teach `prepare_midx_pack()` about incremental MIDXsTaylor Blau, Aug 6, 2024
  87. 05/19 midx: teach `nth_midxed_object_oid()` about incremental MIDXsTaylor Blau, Aug 6, 2024
  88. 06/19 midx: teach `nth_bitmapped_pack()` about incremental MIDXsTaylor Blau, Aug 6, 2024
  89. 07/19 midx: introduce `bsearch_one_midx()`Taylor Blau, Aug 6, 2024
  90. 08/19 midx: teach `bsearch_midx()` about incremental MIDXsTaylor Blau, Aug 6, 2024
  91. 09/19 midx: teach `nth_midxed_offset()` about incremental MIDXsTaylor Blau, Aug 6, 2024
  92. 10/19 midx: teach `fill_midx_entry()` about incremental MIDXsTaylor Blau, Aug 6, 2024
  93. 11/19 midx: remove unused `midx_locate_pack()`Taylor Blau, Aug 6, 2024
  94. 12/19 midx: teach `midx_contains_pack()` about incremental MIDXsTaylor Blau, Aug 6, 2024
  95. 13/19 midx: teach `midx_preferred_pack()` about incremental MIDXsTaylor Blau, Aug 6, 2024
  96. 14/19 midx: teach `midx_fanout_add_midx_fanout()` about incremental MIDXsTaylor Blau, Aug 6, 2024
  97. 15/19 midx: support reading incremental MIDX chainsTaylor Blau, Aug 6, 2024
  98. 16/19 midx: implement verification support for incremental MIDXsTaylor Blau, Aug 6, 2024
  99. 17/19 t: retire 'GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP'Taylor Blau, Aug 6, 2024
  100. 18/19 t/t5313-pack-bounds-checks.sh: prepare for sub-directoriesTaylor Blau, Aug 6, 2024
  101. 19/19 midx: implement support for writing incremental MIDX chainsTaylor Blau, Aug 6, 2024
  102. Jeff KingAug 12, 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.