@@ -78,6 +78,24 @@ struct bitmap_index {
7878 struct ewah_bitmap * blobs ;
7979 struct ewah_bitmap * tags ;
8080
81+ /*
82+ * Type index arrays when this bitmap is associated with an
83+ * incremental multi-pack index chain.
84+ *
85+ * If n is the number of unique layers in the MIDX chain, then
86+ * commits_all[n-1] is this structs 'commits' field,
87+ * commits_all[n-2] is the commits field of this bitmap's
88+ * 'base', and so on.
89+ *
90+ * When either associated either with a non-incremental MIDX, or
91+ * a single packfile, these arrays each contain a single
92+ * element.
93+ */
94+ struct ewah_bitmap * * commits_all ;
95+ struct ewah_bitmap * * trees_all ;
96+ struct ewah_bitmap * * blobs_all ;
97+ struct ewah_bitmap * * tags_all ;
98+
8199 /* Map from object ID -> `stored_bitmap` for all the bitmapped commits */
82100 kh_oid_map_t * bitmaps ;
83101
@@ -586,7 +604,29 @@ static int load_reverse_index(struct repository *r, struct bitmap_index *bitmap_
586604 return load_pack_revindex (r , bitmap_git -> pack );
587605}
588606
589- static int load_bitmap (struct repository * r , struct bitmap_index * bitmap_git )
607+ static void load_all_type_bitmaps (struct bitmap_index * bitmap_git )
608+ {
609+ struct bitmap_index * curr = bitmap_git ;
610+ size_t i = bitmap_git -> base_nr - 1 ;
611+
612+ ALLOC_ARRAY (bitmap_git -> commits_all , bitmap_git -> base_nr );
613+ ALLOC_ARRAY (bitmap_git -> trees_all , bitmap_git -> base_nr );
614+ ALLOC_ARRAY (bitmap_git -> blobs_all , bitmap_git -> base_nr );
615+ ALLOC_ARRAY (bitmap_git -> tags_all , bitmap_git -> base_nr );
616+
617+ while (curr ) {
618+ bitmap_git -> commits_all [i ] = curr -> commits ;
619+ bitmap_git -> trees_all [i ] = curr -> trees ;
620+ bitmap_git -> blobs_all [i ] = curr -> blobs ;
621+ bitmap_git -> tags_all [i ] = curr -> tags ;
622+
623+ curr = curr -> base ;
624+ i -= 1 ;
625+ }
626+ }
627+
628+ static int load_bitmap (struct repository * r , struct bitmap_index * bitmap_git ,
629+ int recursing )
590630{
591631 assert (bitmap_git -> map );
592632
@@ -608,10 +648,13 @@ static int load_bitmap(struct repository *r, struct bitmap_index *bitmap_git)
608648 if (bitmap_git -> base ) {
609649 if (!bitmap_is_midx (bitmap_git ))
610650 BUG ("non-MIDX bitmap has non-NULL base bitmap index" );
611- if (load_bitmap (r , bitmap_git -> base ) < 0 )
651+ if (load_bitmap (r , bitmap_git -> base , 1 ) < 0 )
612652 goto failed ;
613653 }
614654
655+ if (!recursing )
656+ load_all_type_bitmaps (bitmap_git );
657+
615658 return 0 ;
616659
617660failed :
@@ -687,7 +730,7 @@ struct bitmap_index *prepare_bitmap_git(struct repository *r)
687730{
688731 struct bitmap_index * bitmap_git = xcalloc (1 , sizeof (* bitmap_git ));
689732
690- if (!open_bitmap (r , bitmap_git ) && !load_bitmap (r , bitmap_git ))
733+ if (!open_bitmap (r , bitmap_git ) && !load_bitmap (r , bitmap_git , 0 ))
691734 return bitmap_git ;
692735
693736 free_bitmap_index (bitmap_git );
@@ -2042,7 +2085,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
20422085 * from disk. this is the point of no return; after this the rev_list
20432086 * becomes invalidated and we must perform the revwalk through bitmaps
20442087 */
2045- if (load_bitmap (revs -> repo , bitmap_git ) < 0 )
2088+ if (load_bitmap (revs -> repo , bitmap_git , 0 ) < 0 )
20462089 goto cleanup ;
20472090
20482091 if (!use_boundary_traversal )
@@ -2957,6 +3000,10 @@ void free_bitmap_index(struct bitmap_index *b)
29573000 ewah_pool_free (b -> trees );
29583001 ewah_pool_free (b -> blobs );
29593002 ewah_pool_free (b -> tags );
3003+ free (b -> commits_all );
3004+ free (b -> trees_all );
3005+ free (b -> blobs_all );
3006+ free (b -> tags_all );
29603007 if (b -> bitmaps ) {
29613008 struct stored_bitmap * sb ;
29623009 kh_foreach_value (b -> bitmaps , sb , {
0 commit comments