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

[PATCH v3 07/13] pack-bitmap.c: teach `rev-list --test-bitmap` about incremental MIDXs

From
Taylor Blau <me@ttaylorr.com>
Date
Nov 19, 2024, 22:07 UTC
Message-ID
<17ab23dd76dce076275873e96991acd2f2b2a994.1732054032.git.me@ttaylorr.com>
In-Reply-To
<cover.1732054032.git.me@ttaylorr.com>

Implement support for the special `--test-bitmap` mode of `git rev-list` when using incremental MIDXs.

The bitmap_test_data structure is extended to contain a "base" pointer that mirrors the structure of the bitmap chain that it is being used to test.

When we find a commit to test, we first chase down the ->base pointer to find the appropriate bitmap_test_data for the bitmap layer that the given commit is contained within, and then perform the test on that bitmap.

In order to implement this, light modifications are made to bitmap_for_commit() to reimplement it in terms of a new function, find_bitmap_for_commit(), which fills out a pointer which indicates the bitmap layer which contains the given commit.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 pack-bitmap.c | 105 ++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 84 insertions(+), 21 deletions(-)
diff --git a/pack-bitmap.c b/pack-bitmap.c
index 1dddb242434..02864a0e1f7 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -943,8 +943,9 @@ static struct stored_bitmap *lazy_bitmap_for_commit(struct bitmap_index *bitmap_
 	return NULL;
 }
 
-struct ewah_bitmap *bitmap_for_commit(struct bitmap_index *bitmap_git,
-				      struct commit *commit)
+static struct ewah_bitmap *find_bitmap_for_commit(struct bitmap_index *bitmap_git,
+						  struct commit *commit,
+						  struct bitmap_index **found)
 {
 	khiter_t hash_pos;
 	if (!bitmap_git)
@@ -954,18 +955,30 @@ struct ewah_bitmap *bitmap_for_commit(struct bitmap_index *bitmap_git,
 	if (hash_pos >= kh_end(bitmap_git->bitmaps)) {
 		struct stored_bitmap *bitmap = NULL;
 		if (!bitmap_git->table_lookup)
-			return bitmap_for_commit(bitmap_git->base, commit);
+			return find_bitmap_for_commit(bitmap_git->base, commit,
+						      found);
 
 		/* this is a fairly hot codepath - no trace2_region please */
 		/* NEEDSWORK: cache misses aren't recorded */
 		bitmap = lazy_bitmap_for_commit(bitmap_git, commit);
 		if (!bitmap)
-			return bitmap_for_commit(bitmap_git->base, commit);
+			return find_bitmap_for_commit(bitmap_git->base, commit,
+						      found);
+		if (found)
+			*found = bitmap_git;
 		return lookup_stored_bitmap(bitmap);
 	}
+	if (found)
+		*found = bitmap_git;
 	return lookup_stored_bitmap(kh_value(bitmap_git->bitmaps, hash_pos));
 }
 
+struct ewah_bitmap *bitmap_for_commit(struct bitmap_index *bitmap_git,
+				      struct commit *commit)
+{
+	return find_bitmap_for_commit(bitmap_git, commit, NULL);
+}
+
 static inline int bitmap_position_extended(struct bitmap_index *bitmap_git,
 					   const struct object_id *oid)
 {
@@ -2493,6 +2506,8 @@ struct bitmap_test_data {
 	struct bitmap *tags;
 	struct progress *prg;
 	size_t seen;
+
+	struct bitmap_test_data *base_tdata;
 };
 
 static void test_bitmap_type(struct bitmap_test_data *tdata,
@@ -2501,6 +2516,11 @@ static void test_bitmap_type(struct bitmap_test_data *tdata,
 	enum object_type bitmap_type = OBJ_NONE;
 	int bitmaps_nr = 0;
 
+	if (bitmap_is_midx(tdata->bitmap_git)) {
+		while (pos < tdata->bitmap_git->midx->num_objects_in_base)
+			tdata = tdata->base_tdata;
+	}
+
 	if (bitmap_get(tdata->commits, pos)) {
 		bitmap_type = OBJ_COMMIT;
 		bitmaps_nr++;
@@ -2564,13 +2584,57 @@ static void test_show_commit(struct commit *commit, void *data)
 	display_progress(tdata->prg, ++tdata->seen);
 }
 
+static uint32_t bitmap_total_entry_count(struct bitmap_index *bitmap_git)
+{
+	uint32_t total = 0;
+	do {
+		total = st_add(total, bitmap_git->entry_count);
+		bitmap_git = bitmap_git->base;
+	} while (bitmap_git);
+
+	return total;
+}
+
+static void prepare_bitmap_test_data(struct bitmap_test_data *tdata,
+				     struct bitmap_index *bitmap_git)
+{
+	memset(tdata, 0, sizeof(struct bitmap_test_data));
+
+	tdata->bitmap_git = bitmap_git;
+	tdata->base = bitmap_new();
+	tdata->commits = ewah_to_bitmap(bitmap_git->commits);
+	tdata->trees = ewah_to_bitmap(bitmap_git->trees);
+	tdata->blobs = ewah_to_bitmap(bitmap_git->blobs);
+	tdata->tags = ewah_to_bitmap(bitmap_git->tags);
+
+	if (bitmap_git->base) {
+		CALLOC_ARRAY(tdata->base_tdata, 1);
+		prepare_bitmap_test_data(tdata->base_tdata, bitmap_git->base);
+	}
+}
+
+static void free_bitmap_test_data(struct bitmap_test_data *tdata)
+{
+	if (!tdata)
+		return;
+
+	free_bitmap_test_data(tdata->base_tdata);
+	free(tdata->base_tdata);
+
+	bitmap_free(tdata->base);
+	bitmap_free(tdata->commits);
+	bitmap_free(tdata->trees);
+	bitmap_free(tdata->blobs);
+	bitmap_free(tdata->tags);
+}
+
 void test_bitmap_walk(struct rev_info *revs)
 {
 	struct object *root;
 	struct bitmap *result = NULL;
 	size_t result_popcnt;
 	struct bitmap_test_data tdata;
-	struct bitmap_index *bitmap_git;
+	struct bitmap_index *bitmap_git, *found;
 	struct ewah_bitmap *bm;
 
 	if (!(bitmap_git = prepare_bitmap_git(revs->repo)))
@@ -2579,17 +2643,26 @@ void test_bitmap_walk(struct rev_info *revs)
 	if (revs->pending.nr != 1)
 		die(_("you must specify exactly one commit to test"));
 
-	fprintf_ln(stderr, "Bitmap v%d test (%d entries%s)",
+	fprintf_ln(stderr, "Bitmap v%d test (%d entries%s, %d total)",
 		bitmap_git->version,
 		bitmap_git->entry_count,
-		bitmap_git->table_lookup ? "" : " loaded");
+		bitmap_git->table_lookup ? "" : " loaded",
+		bitmap_total_entry_count(bitmap_git));
 
 	root = revs->pending.objects[0].item;
-	bm = bitmap_for_commit(bitmap_git, (struct commit *)root);
+	bm = find_bitmap_for_commit(bitmap_git, (struct commit *)root, &found);
 
 	if (bm) {
 		fprintf_ln(stderr, "Found bitmap for '%s'. %d bits / %08x checksum",
-			oid_to_hex(&root->oid), (int)bm->bit_size, ewah_checksum(bm));
+			oid_to_hex(&root->oid),
+			(int)bm->bit_size, ewah_checksum(bm));
+
+		if (bitmap_is_midx(found))
+			fprintf_ln(stderr, "Located via MIDX '%s'.",
+				   hash_to_hex(get_midx_checksum(found->midx)));
+		else
+			fprintf_ln(stderr, "Located via pack '%s'.",
+				   hash_to_hex(found->pack->hash));
 
 		result = ewah_to_bitmap(bm);
 	}
@@ -2606,14 +2679,8 @@ void test_bitmap_walk(struct rev_info *revs)
 	if (prepare_revision_walk(revs))
 		die(_("revision walk setup failed"));
 
-	tdata.bitmap_git = bitmap_git;
-	tdata.base = bitmap_new();
-	tdata.commits = ewah_to_bitmap(bitmap_git->commits);
-	tdata.trees = ewah_to_bitmap(bitmap_git->trees);
-	tdata.blobs = ewah_to_bitmap(bitmap_git->blobs);
-	tdata.tags = ewah_to_bitmap(bitmap_git->tags);
+	prepare_bitmap_test_data(&tdata, bitmap_git);
 	tdata.prg = start_progress("Verifying bitmap entries", result_popcnt);
-	tdata.seen = 0;
 
 	traverse_commit_list(revs, &test_show_commit, &test_show_object, &tdata);
 
@@ -2625,11 +2692,7 @@ void test_bitmap_walk(struct rev_info *revs)
 		die(_("mismatch in bitmap results"));
 
 	bitmap_free(result);
-	bitmap_free(tdata.base);
-	bitmap_free(tdata.commits);
-	bitmap_free(tdata.trees);
-	bitmap_free(tdata.blobs);
-	bitmap_free(tdata.tags);
+	free_bitmap_test_data(&tdata);
 	free_bitmap_index(bitmap_git);
 }
 
-- 
2.47.0.301.g77ddd1170f9
Previous: Taylor BlauNext: Patrick Steinhardt
Message 53 of 135 in “midx: incremental multi-pack indexes, part two”
  1. 00/13 midx: incremental multi-pack indexes, part twoTaylor Blau, Aug 15, 2024
  2. 01/13 Documentation: describe incremental MIDX bitmapsTaylor Blau, Aug 15, 2024
  3. 02/13 pack-revindex: prepare for incremental MIDX bitmapsTaylor Blau, Aug 15, 2024
  4. 03/13 pack-bitmap.c: open and store incremental bitmap layersTaylor Blau, Aug 15, 2024
  5. 04/13 pack-bitmap.c: teach `bitmap_for_commit()` about incremental MIDXsTaylor Blau, Aug 15, 2024
  6. 05/13 pack-bitmap.c: teach `show_objects_for_type()` about incremental MIDXsTaylor Blau, Aug 15, 2024
  7. 06/13 pack-bitmap.c: support bitmap pack-reuse with incremental MIDXsTaylor Blau, Aug 15, 2024
  8. 07/13 pack-bitmap.c: teach `rev-list --test-bitmap` about incremental MIDXsTaylor Blau, Aug 15, 2024
  9. 08/13 pack-bitmap.c: compute disk-usage with incremental MIDXsTaylor Blau, Aug 15, 2024
  10. 09/13 pack-bitmap.c: apply pseudo-merge commits with incremental MIDXsTaylor Blau, Aug 15, 2024
  11. 10/13 ewah: implement `struct ewah_or_iterator`Taylor Blau, Aug 15, 2024
  12. 11/13 pack-bitmap.c: keep track of each layer's type bitmapsTaylor Blau, Aug 15, 2024
  13. 12/13 pack-bitmap.c: use `ewah_or_iterator` for type bitmap iteratorsTaylor Blau, Aug 15, 2024
  14. 13/13 midx: implement writing incremental MIDX bitmapsTaylor Blau, Aug 15, 2024
  15. 00/13 midx: incremental multi-pack indexes, part twoTaylor Blau, Aug 15, 2024
  16. 01/13 Documentation: describe incremental MIDX bitmapsTaylor Blau, Aug 15, 2024
  17. 02/13 pack-revindex: prepare for incremental MIDX bitmapsTaylor Blau, Aug 15, 2024
  18. 03/13 pack-bitmap.c: open and store incremental bitmap layersTaylor Blau, Aug 15, 2024
  19. 04/13 pack-bitmap.c: teach `bitmap_for_commit()` about incremental MIDXsTaylor Blau, Aug 15, 2024
  20. 05/13 pack-bitmap.c: teach `show_objects_for_type()` about incremental MIDXsTaylor Blau, Aug 15, 2024
  21. 06/13 pack-bitmap.c: support bitmap pack-reuse with incremental MIDXsTaylor Blau, Aug 15, 2024
  22. 07/13 pack-bitmap.c: teach `rev-list --test-bitmap` about incremental MIDXsTaylor Blau, Aug 15, 2024
  23. 08/13 pack-bitmap.c: compute disk-usage with incremental MIDXsTaylor Blau, Aug 15, 2024
  24. 09/13 pack-bitmap.c: apply pseudo-merge commits with incremental MIDXsTaylor Blau, Aug 15, 2024
  25. 10/13 ewah: implement `struct ewah_or_iterator`Taylor Blau, Aug 15, 2024
  26. 11/13 pack-bitmap.c: keep track of each layer's type bitmapsTaylor Blau, Aug 15, 2024
  27. 12/13 pack-bitmap.c: use `ewah_or_iterator` for type bitmap iteratorsTaylor Blau, Aug 15, 2024
  28. 13/13 midx: implement writing incremental MIDX bitmapsTaylor Blau, Aug 15, 2024
  29. fixup! midx: implement writing incremental MIDX bitmapsJunio C Hamano, Aug 28, 2024
  30. Jeff KingAug 28, 2024
  31. Taylor BlauAug 29, 2024
  32. Jeff KingAug 29, 2024
  33. Taylor BlauNov 19, 2024
  34. 00/13 midx: incremental multi-pack indexes, part twoTaylor Blau, Nov 19, 2024
  35. 01/13 Documentation: describe incremental MIDX bitmapsTaylor Blau, Nov 19, 2024
  36. Patrick SteinhardtFeb 28, 2025
  37. Taylor BlauFeb 28, 2025
  38. Patrick SteinhardtMar 3, 2025
  39. 02/13 pack-revindex: prepare for incremental MIDX bitmapsTaylor Blau, Nov 19, 2024
  40. Patrick SteinhardtFeb 28, 2025
  41. Taylor BlauFeb 28, 2025
  42. 03/13 pack-bitmap.c: open and store incremental bitmap layersTaylor Blau, Nov 19, 2024
  43. Patrick SteinhardtFeb 28, 2025
  44. Taylor BlauFeb 28, 2025
  45. Patrick SteinhardtMar 3, 2025
  46. 04/13 pack-bitmap.c: teach `bitmap_for_commit()` about incremental MIDXsTaylor Blau, Nov 19, 2024
  47. Patrick SteinhardtFeb 28, 2025
  48. Taylor BlauMar 1, 2025
  49. 05/13 pack-bitmap.c: teach `show_objects_for_type()` about incremental MIDXsTaylor Blau, Nov 19, 2024
  50. 06/13 pack-bitmap.c: support bitmap pack-reuse with incremental MIDXsTaylor Blau, Nov 19, 2024
  51. Patrick SteinhardtFeb 28, 2025
  52. Taylor BlauMar 1, 2025
  53. 07/13 pack-bitmap.c: teach `rev-list --test-bitmap` about incremental MIDXsTaylor Blau, Nov 19, 2024
  54. Patrick SteinhardtFeb 28, 2025
  55. Taylor BlauMar 1, 2025
  56. 08/13 pack-bitmap.c: compute disk-usage with incremental MIDXsTaylor Blau, Nov 19, 2024
  57. 09/13 pack-bitmap.c: apply pseudo-merge commits with incremental MIDXsTaylor Blau, Nov 19, 2024
  58. 10/13 ewah: implement `struct ewah_or_iterator`Taylor Blau, Nov 19, 2024
  59. Patrick SteinhardtFeb 28, 2025
  60. Taylor BlauMar 1, 2025
  61. 11/13 pack-bitmap.c: keep track of each layer's type bitmapsTaylor Blau, Nov 19, 2024
  62. Patrick SteinhardtFeb 28, 2025
  63. Taylor BlauMar 1, 2025
  64. 12/13 pack-bitmap.c: use `ewah_or_iterator` for type bitmap iteratorsTaylor Blau, Nov 19, 2024
  65. Patrick SteinhardtFeb 28, 2025
  66. Taylor BlauMar 1, 2025
  67. 13/13 midx: implement writing incremental MIDX bitmapsTaylor Blau, Nov 19, 2024
  68. Patrick SteinhardtFeb 28, 2025
  69. Taylor BlauMar 1, 2025
  70. Junio C HamanoNov 20, 2024
  71. 00/13 midx: incremental multi-pack indexes, part twoTaylor Blau, Mar 14, 2025
  72. 01/13 Documentation: describe incremental MIDX bitmapsTaylor Blau, Mar 14, 2025
  73. Jeff KingMar 18, 2025
  74. Taylor BlauMar 18, 2025
  75. Elijah NewrenMar 18, 2025
  76. Taylor BlauMar 18, 2025
  77. 02/13 pack-revindex: prepare for incremental MIDX bitmapsTaylor Blau, Mar 14, 2025
  78. Jeff KingMar 18, 2025
  79. Taylor BlauMar 19, 2025
  80. Taylor BlauMar 19, 2025
  81. Jeff KingMar 26, 2025
  82. Elijah NewrenMar 18, 2025
  83. Taylor BlauMar 19, 2025
  84. 03/13 pack-bitmap.c: open and store incremental bitmap layersTaylor Blau, Mar 14, 2025
  85. Elijah NewrenMar 18, 2025
  86. Taylor BlauMar 19, 2025
  87. 04/13 pack-bitmap.c: teach `bitmap_for_commit()` about incremental MIDXsTaylor Blau, Mar 14, 2025
  88. Jeff KingMar 18, 2025
  89. Taylor BlauMar 19, 2025
  90. 05/13 pack-bitmap.c: teach `show_objects_for_type()` about incremental MIDXsTaylor Blau, Mar 14, 2025
  91. 06/13 pack-bitmap.c: support bitmap pack-reuse with incremental MIDXsTaylor Blau, Mar 14, 2025
  92. Elijah NewrenMar 18, 2025
  93. Taylor BlauMar 19, 2025
  94. 07/13 pack-bitmap.c: teach `rev-list --test-bitmap` about incremental MIDXsTaylor Blau, Mar 14, 2025
  95. Elijah NewrenMar 18, 2025
  96. Taylor BlauMar 19, 2025
  97. 08/13 pack-bitmap.c: compute disk-usage with incremental MIDXsTaylor Blau, Mar 14, 2025
  98. Jeff KingMar 18, 2025
  99. Taylor BlauMar 19, 2025
  100. 09/13 pack-bitmap.c: apply pseudo-merge commits with incremental MIDXsTaylor Blau, Mar 14, 2025
  101. 10/13 ewah: implement `struct ewah_or_iterator`Taylor Blau, Mar 14, 2025
  102. Jeff KingMar 18, 2025
  103. Taylor BlauMar 19, 2025
  104. 11/13 pack-bitmap.c: keep track of each layer's type bitmapsTaylor Blau, Mar 14, 2025
  105. Jeff KingMar 18, 2025
  106. Taylor BlauMar 19, 2025
  107. Elijah NewrenMar 18, 2025
  108. Taylor BlauMar 19, 2025
  109. 12/13 pack-bitmap.c: use `ewah_or_iterator` for type bitmap iteratorsTaylor Blau, Mar 14, 2025
  110. Jeff KingMar 18, 2025
  111. Taylor BlauMar 19, 2025
  112. 13/13 midx: implement writing incremental MIDX bitmapsTaylor Blau, Mar 14, 2025
  113. Jeff KingMar 18, 2025
  114. Taylor BlauMar 20, 2025
  115. Elijah NewrenMar 18, 2025
  116. Taylor BlauMar 20, 2025
  117. Jeff KingMar 18, 2025
  118. Taylor BlauMar 20, 2025
  119. 00/14 midx: incremental multi-pack indexes, part twoTaylor Blau, Mar 20, 2025
  120. 01/14 Documentation: remove a "future work" item from the MIDX docsTaylor Blau, Mar 20, 2025
  121. 02/14 Documentation: describe incremental MIDX bitmapsTaylor Blau, Mar 20, 2025
  122. 03/14 pack-revindex: prepare for incremental MIDX bitmapsTaylor Blau, Mar 20, 2025
  123. 04/14 pack-bitmap.c: open and store incremental bitmap layersTaylor Blau, Mar 20, 2025
  124. 05/14 pack-bitmap.c: teach `bitmap_for_commit()` about incremental MIDXsTaylor Blau, Mar 20, 2025
  125. 06/14 pack-bitmap.c: teach `show_objects_for_type()` about incremental MIDXsTaylor Blau, Mar 20, 2025
  126. 07/14 pack-bitmap.c: support bitmap pack-reuse with incremental MIDXsTaylor Blau, Mar 20, 2025
  127. 08/14 pack-bitmap.c: teach `rev-list --test-bitmap` about incremental MIDXsTaylor Blau, Mar 20, 2025
  128. 09/14 pack-bitmap.c: compute disk-usage with incremental MIDXsTaylor Blau, Mar 20, 2025
  129. 10/14 pack-bitmap.c: apply pseudo-merge commits with incremental MIDXsTaylor Blau, Mar 20, 2025
  130. 11/14 ewah: implement `struct ewah_or_iterator`Taylor Blau, Mar 20, 2025
  131. 12/14 pack-bitmap.c: keep track of each layer's type bitmapsTaylor Blau, Mar 20, 2025
  132. 13/14 pack-bitmap.c: use `ewah_or_iterator` for type bitmap iteratorsTaylor Blau, Mar 20, 2025
  133. 14/14 midx: implement writing incremental MIDX bitmapsTaylor Blau, Mar 20, 2025
  134. Elijah NewrenMar 20, 2025
  135. Taylor BlauMar 20, 2025

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.