@@ -943,8 +943,9 @@ static struct stored_bitmap *lazy_bitmap_for_commit(struct bitmap_index *bitmap_
943
943
return NULL ;
944
944
}
945
945
946
- struct ewah_bitmap * bitmap_for_commit (struct bitmap_index * bitmap_git ,
947
- struct commit * commit )
946
+ static struct ewah_bitmap * find_bitmap_for_commit (struct bitmap_index * bitmap_git ,
947
+ struct commit * commit ,
948
+ struct bitmap_index * * found )
948
949
{
949
950
khiter_t hash_pos ;
950
951
if (!bitmap_git )
@@ -954,18 +955,30 @@ struct ewah_bitmap *bitmap_for_commit(struct bitmap_index *bitmap_git,
954
955
if (hash_pos >= kh_end (bitmap_git -> bitmaps )) {
955
956
struct stored_bitmap * bitmap = NULL ;
956
957
if (!bitmap_git -> table_lookup )
957
- return bitmap_for_commit (bitmap_git -> base , commit );
958
+ return find_bitmap_for_commit (bitmap_git -> base , commit ,
959
+ found );
958
960
959
961
/* this is a fairly hot codepath - no trace2_region please */
960
962
/* NEEDSWORK: cache misses aren't recorded */
961
963
bitmap = lazy_bitmap_for_commit (bitmap_git , commit );
962
964
if (!bitmap )
963
- return bitmap_for_commit (bitmap_git -> base , commit );
965
+ return find_bitmap_for_commit (bitmap_git -> base , commit ,
966
+ found );
967
+ if (found )
968
+ * found = bitmap_git ;
964
969
return lookup_stored_bitmap (bitmap );
965
970
}
971
+ if (found )
972
+ * found = bitmap_git ;
966
973
return lookup_stored_bitmap (kh_value (bitmap_git -> bitmaps , hash_pos ));
967
974
}
968
975
976
+ struct ewah_bitmap * bitmap_for_commit (struct bitmap_index * bitmap_git ,
977
+ struct commit * commit )
978
+ {
979
+ return find_bitmap_for_commit (bitmap_git , commit , NULL );
980
+ }
981
+
969
982
static inline int bitmap_position_extended (struct bitmap_index * bitmap_git ,
970
983
const struct object_id * oid )
971
984
{
@@ -2489,6 +2502,8 @@ struct bitmap_test_data {
2489
2502
struct bitmap * tags ;
2490
2503
struct progress * prg ;
2491
2504
size_t seen ;
2505
+
2506
+ struct bitmap_test_data * base_tdata ;
2492
2507
};
2493
2508
2494
2509
static void test_bitmap_type (struct bitmap_test_data * tdata ,
@@ -2497,6 +2512,11 @@ static void test_bitmap_type(struct bitmap_test_data *tdata,
2497
2512
enum object_type bitmap_type = OBJ_NONE ;
2498
2513
int bitmaps_nr = 0 ;
2499
2514
2515
+ if (bitmap_is_midx (tdata -> bitmap_git )) {
2516
+ while (pos < tdata -> bitmap_git -> midx -> num_objects_in_base )
2517
+ tdata = tdata -> base_tdata ;
2518
+ }
2519
+
2500
2520
if (bitmap_get (tdata -> commits , pos )) {
2501
2521
bitmap_type = OBJ_COMMIT ;
2502
2522
bitmaps_nr ++ ;
@@ -2560,13 +2580,57 @@ static void test_show_commit(struct commit *commit, void *data)
2560
2580
display_progress (tdata -> prg , ++ tdata -> seen );
2561
2581
}
2562
2582
2583
+ static uint32_t bitmap_total_entry_count (struct bitmap_index * bitmap_git )
2584
+ {
2585
+ uint32_t total = 0 ;
2586
+ do {
2587
+ total = st_add (total , bitmap_git -> entry_count );
2588
+ bitmap_git = bitmap_git -> base ;
2589
+ } while (bitmap_git );
2590
+
2591
+ return total ;
2592
+ }
2593
+
2594
+ static void prepare_bitmap_test_data (struct bitmap_test_data * tdata ,
2595
+ struct bitmap_index * bitmap_git )
2596
+ {
2597
+ memset (tdata , 0 , sizeof (struct bitmap_test_data ));
2598
+
2599
+ tdata -> bitmap_git = bitmap_git ;
2600
+ tdata -> base = bitmap_new ();
2601
+ tdata -> commits = ewah_to_bitmap (bitmap_git -> commits );
2602
+ tdata -> trees = ewah_to_bitmap (bitmap_git -> trees );
2603
+ tdata -> blobs = ewah_to_bitmap (bitmap_git -> blobs );
2604
+ tdata -> tags = ewah_to_bitmap (bitmap_git -> tags );
2605
+
2606
+ if (bitmap_git -> base ) {
2607
+ CALLOC_ARRAY (tdata -> base_tdata , 1 );
2608
+ prepare_bitmap_test_data (tdata -> base_tdata , bitmap_git -> base );
2609
+ }
2610
+ }
2611
+
2612
+ static void free_bitmap_test_data (struct bitmap_test_data * tdata )
2613
+ {
2614
+ if (!tdata )
2615
+ return ;
2616
+
2617
+ free_bitmap_test_data (tdata -> base_tdata );
2618
+ free (tdata -> base_tdata );
2619
+
2620
+ bitmap_free (tdata -> base );
2621
+ bitmap_free (tdata -> commits );
2622
+ bitmap_free (tdata -> trees );
2623
+ bitmap_free (tdata -> blobs );
2624
+ bitmap_free (tdata -> tags );
2625
+ }
2626
+
2563
2627
void test_bitmap_walk (struct rev_info * revs )
2564
2628
{
2565
2629
struct object * root ;
2566
2630
struct bitmap * result = NULL ;
2567
2631
size_t result_popcnt ;
2568
2632
struct bitmap_test_data tdata ;
2569
- struct bitmap_index * bitmap_git ;
2633
+ struct bitmap_index * bitmap_git , * found ;
2570
2634
struct ewah_bitmap * bm ;
2571
2635
2572
2636
if (!(bitmap_git = prepare_bitmap_git (revs -> repo )))
@@ -2575,17 +2639,26 @@ void test_bitmap_walk(struct rev_info *revs)
2575
2639
if (revs -> pending .nr != 1 )
2576
2640
die (_ ("you must specify exactly one commit to test" ));
2577
2641
2578
- fprintf_ln (stderr , "Bitmap v%d test (%d entries%s)" ,
2642
+ fprintf_ln (stderr , "Bitmap v%d test (%d entries%s, %d total )" ,
2579
2643
bitmap_git -> version ,
2580
2644
bitmap_git -> entry_count ,
2581
- bitmap_git -> table_lookup ? "" : " loaded" );
2645
+ bitmap_git -> table_lookup ? "" : " loaded" ,
2646
+ bitmap_total_entry_count (bitmap_git ));
2582
2647
2583
2648
root = revs -> pending .objects [0 ].item ;
2584
- bm = bitmap_for_commit (bitmap_git , (struct commit * )root );
2649
+ bm = find_bitmap_for_commit (bitmap_git , (struct commit * )root , & found );
2585
2650
2586
2651
if (bm ) {
2587
2652
fprintf_ln (stderr , "Found bitmap for '%s'. %d bits / %08x checksum" ,
2588
- oid_to_hex (& root -> oid ), (int )bm -> bit_size , ewah_checksum (bm ));
2653
+ oid_to_hex (& root -> oid ),
2654
+ (int )bm -> bit_size , ewah_checksum (bm ));
2655
+
2656
+ if (bitmap_is_midx (found ))
2657
+ fprintf_ln (stderr , "Located via MIDX '%s'." ,
2658
+ hash_to_hex (get_midx_checksum (found -> midx )));
2659
+ else
2660
+ fprintf_ln (stderr , "Located via pack '%s'." ,
2661
+ hash_to_hex (found -> pack -> hash ));
2589
2662
2590
2663
result = ewah_to_bitmap (bm );
2591
2664
}
@@ -2602,14 +2675,8 @@ void test_bitmap_walk(struct rev_info *revs)
2602
2675
if (prepare_revision_walk (revs ))
2603
2676
die (_ ("revision walk setup failed" ));
2604
2677
2605
- tdata .bitmap_git = bitmap_git ;
2606
- tdata .base = bitmap_new ();
2607
- tdata .commits = ewah_to_bitmap (bitmap_git -> commits );
2608
- tdata .trees = ewah_to_bitmap (bitmap_git -> trees );
2609
- tdata .blobs = ewah_to_bitmap (bitmap_git -> blobs );
2610
- tdata .tags = ewah_to_bitmap (bitmap_git -> tags );
2678
+ prepare_bitmap_test_data (& tdata , bitmap_git );
2611
2679
tdata .prg = start_progress ("Verifying bitmap entries" , result_popcnt );
2612
- tdata .seen = 0 ;
2613
2680
2614
2681
traverse_commit_list (revs , & test_show_commit , & test_show_object , & tdata );
2615
2682
@@ -2621,11 +2688,7 @@ void test_bitmap_walk(struct rev_info *revs)
2621
2688
die (_ ("mismatch in bitmap results" ));
2622
2689
2623
2690
bitmap_free (result );
2624
- bitmap_free (tdata .base );
2625
- bitmap_free (tdata .commits );
2626
- bitmap_free (tdata .trees );
2627
- bitmap_free (tdata .blobs );
2628
- bitmap_free (tdata .tags );
2691
+ free_bitmap_test_data (& tdata );
2629
2692
free_bitmap_index (bitmap_git );
2630
2693
}
2631
2694
0 commit comments