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

[PATCH v3 03/13] pack-bitmap.c: open and store incremental bitmap layers

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

Prepare the pack-bitmap machinery to work with incremental MIDXs by adding a new "base" field to keep track of the bitmap index associated with the previous MIDX layer.

The changes in this commit are mostly boilerplate to open the correct bitmap(s), add them to the chain bitmap layers along the "base" pointer, ensures that the correct packs and their reverse indexes are loaded across MIDX layers, etc.

While we're at it, keep track of a base_nr field to indicate how many bitmap layers (including the current bitmap) exist. This will be used in a future commit to allocate an array of 'struct ewah_bitmap' pointers to collect all of the respective type bitmaps among all layers to initialize a multi-EWAH iterator.

Subsequent commits will teach the functions within the pack-bitmap machinery how to interact with these new fields.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 pack-bitmap.c | 64 ++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 51 insertions(+), 13 deletions(-)
diff --git a/pack-bitmap.c b/pack-bitmap.c
index bba9c6a905a..41675a69f68 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -54,6 +54,13 @@ struct bitmap_index {
 	struct packed_git *pack;
 	struct multi_pack_index *midx;
 
+	/*
+	 * If using a multi-pack index chain, 'base' points to the
+	 * bitmap index corresponding to this bitmap's midx->base_midx.
+	 */
+	struct bitmap_index *base;
+	uint32_t base_nr;
+
 	/* mmapped buffer of the whole bitmap index */
 	unsigned char *map;
 	size_t map_size; /* size of the mmaped buffer */
@@ -377,8 +384,13 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
 char *midx_bitmap_filename(struct multi_pack_index *midx)
 {
 	struct strbuf buf = STRBUF_INIT;
-	get_midx_filename_ext(&buf, midx->object_dir, get_midx_checksum(midx),
-			      MIDX_EXT_BITMAP);
+	if (midx->has_chain)
+		get_split_midx_filename_ext(&buf, midx->object_dir,
+					    get_midx_checksum(midx),
+					    MIDX_EXT_BITMAP);
+	else
+		get_midx_filename_ext(&buf, midx->object_dir,
+				      get_midx_checksum(midx), MIDX_EXT_BITMAP);
 
 	return strbuf_detach(&buf, NULL);
 }
@@ -397,10 +409,17 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
 {
 	struct stat st;
 	char *bitmap_name = midx_bitmap_filename(midx);
-	int fd = git_open(bitmap_name);
+	int fd;
 	uint32_t i, preferred_pack;
 	struct packed_git *preferred;
 
+	fd = git_open(bitmap_name);
+	if (fd < 0 && errno == ENOENT) {
+		FREE_AND_NULL(bitmap_name);
+		bitmap_name = midx_bitmap_filename(midx);
+		fd = git_open(bitmap_name);
+	}
+
 	if (fd < 0) {
 		if (errno != ENOENT)
 			warning_errno("cannot open '%s'", bitmap_name);
@@ -446,7 +465,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
 		goto cleanup;
 	}
 
-	for (i = 0; i < bitmap_git->midx->num_packs; i++) {
+	for (i = 0; i < bitmap_git->midx->num_packs + bitmap_git->midx->num_packs_in_base; i++) {
 		if (prepare_midx_pack(the_repository, bitmap_git->midx, i)) {
 			warning(_("could not open pack %s"),
 				bitmap_git->midx->pack_names[i]);
@@ -459,13 +478,20 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
 		goto cleanup;
 	}
 
-	preferred = bitmap_git->midx->packs[preferred_pack];
+	preferred = nth_midxed_pack(bitmap_git->midx, preferred_pack);
 	if (!is_pack_valid(preferred)) {
 		warning(_("preferred pack (%s) is invalid"),
 			preferred->pack_name);
 		goto cleanup;
 	}
 
+	if (midx->base_midx) {
+		bitmap_git->base = prepare_midx_bitmap_git(midx->base_midx);
+		bitmap_git->base_nr = bitmap_git->base->base_nr + 1;
+	} else {
+		bitmap_git->base_nr = 1;
+	}
+
 	return 0;
 
 cleanup:
@@ -516,6 +542,7 @@ static int open_pack_bitmap_1(struct bitmap_index *bitmap_git, struct packed_git
 	bitmap_git->map_size = xsize_t(st.st_size);
 	bitmap_git->map = xmmap(NULL, bitmap_git->map_size, PROT_READ, MAP_PRIVATE, fd, 0);
 	bitmap_git->map_pos = 0;
+	bitmap_git->base_nr = 1;
 	close(fd);
 
 	if (load_bitmap_header(bitmap_git) < 0) {
@@ -535,8 +562,7 @@ static int open_pack_bitmap_1(struct bitmap_index *bitmap_git, struct packed_git
 static int load_reverse_index(struct repository *r, struct bitmap_index *bitmap_git)
 {
 	if (bitmap_is_midx(bitmap_git)) {
-		uint32_t i;
-		int ret;
+		struct multi_pack_index *m;
 
 		/*
 		 * The multi-pack-index's .rev file is already loaded via
@@ -545,10 +571,15 @@ static int load_reverse_index(struct repository *r, struct bitmap_index *bitmap_
 		 * But we still need to open the individual pack .rev files,
 		 * since we will need to make use of them in pack-objects.
 		 */
-		for (i = 0; i < bitmap_git->midx->num_packs; i++) {
-			ret = load_pack_revindex(r, bitmap_git->midx->packs[i]);
-			if (ret)
-				return ret;
+		for (m = bitmap_git->midx; m; m = m->base_midx) {
+			uint32_t i;
+			int ret;
+
+			for (i = 0; i < m->num_packs; i++) {
+				ret = load_pack_revindex(r, m->packs[i]);
+				if (ret)
+					return ret;
+			}
 		}
 		return 0;
 	}
@@ -574,6 +605,13 @@ static int load_bitmap(struct repository *r, struct bitmap_index *bitmap_git)
 	if (!bitmap_git->table_lookup && load_bitmap_entries_v1(bitmap_git) < 0)
 		goto failed;
 
+	if (bitmap_git->base) {
+		if (!bitmap_is_midx(bitmap_git))
+			BUG("non-MIDX bitmap has non-NULL base bitmap index");
+		if (load_bitmap(r, bitmap_git->base) < 0)
+			goto failed;
+	}
+
 	return 0;
 
 failed:
@@ -658,10 +696,9 @@ struct bitmap_index *prepare_bitmap_git(struct repository *r)
 
 struct bitmap_index *prepare_midx_bitmap_git(struct multi_pack_index *midx)
 {
-	struct repository *r = the_repository;
 	struct bitmap_index *bitmap_git = xcalloc(1, sizeof(*bitmap_git));
 
-	if (!open_midx_bitmap_1(bitmap_git, midx) && !load_bitmap(r, bitmap_git))
+	if (!open_midx_bitmap_1(bitmap_git, midx))
 		return bitmap_git;
 
 	free_bitmap_index(bitmap_git);
@@ -2875,6 +2912,7 @@ void free_bitmap_index(struct bitmap_index *b)
 		close_midx_revindex(b->midx);
 	}
 	free_pseudo_merge_map(&b->pseudo_merges);
+	free_bitmap_index(b->base);
 	free(b);
 }
 
-- 
2.47.0.301.g77ddd1170f9
Previous: Taylor BlauNext: Patrick Steinhardt
Message 42 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.