@@ -54,6 +54,13 @@ struct bitmap_index {
5454 struct packed_git * pack ;
5555 struct multi_pack_index * midx ;
5656
57+ /*
58+ * If using a multi-pack index chain, 'base' points to the
59+ * bitmap index corresponding to this bitmap's midx->base_midx.
60+ */
61+ struct bitmap_index * base ;
62+ uint32_t base_nr ;
63+
5764 /* mmapped buffer of the whole bitmap index */
5865 unsigned char * map ;
5966 size_t map_size ; /* size of the mmaped buffer */
@@ -377,8 +384,13 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
377384char * midx_bitmap_filename (struct multi_pack_index * midx )
378385{
379386 struct strbuf buf = STRBUF_INIT ;
380- get_midx_filename_ext (& buf , midx -> object_dir , get_midx_checksum (midx ),
381- MIDX_EXT_BITMAP );
387+ if (midx -> has_chain )
388+ get_split_midx_filename_ext (& buf , midx -> object_dir ,
389+ get_midx_checksum (midx ),
390+ MIDX_EXT_BITMAP );
391+ else
392+ get_midx_filename_ext (& buf , midx -> object_dir ,
393+ get_midx_checksum (midx ), MIDX_EXT_BITMAP );
382394
383395 return strbuf_detach (& buf , NULL );
384396}
@@ -397,10 +409,17 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
397409{
398410 struct stat st ;
399411 char * bitmap_name = midx_bitmap_filename (midx );
400- int fd = git_open ( bitmap_name ) ;
412+ int fd ;
401413 uint32_t i , preferred_pack ;
402414 struct packed_git * preferred ;
403415
416+ fd = git_open (bitmap_name );
417+ if (fd < 0 && errno == ENOENT ) {
418+ FREE_AND_NULL (bitmap_name );
419+ bitmap_name = midx_bitmap_filename (midx );
420+ fd = git_open (bitmap_name );
421+ }
422+
404423 if (fd < 0 ) {
405424 if (errno != ENOENT )
406425 warning_errno ("cannot open '%s'" , bitmap_name );
@@ -446,7 +465,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
446465 goto cleanup ;
447466 }
448467
449- for (i = 0 ; i < bitmap_git -> midx -> num_packs ; i ++ ) {
468+ for (i = 0 ; i < bitmap_git -> midx -> num_packs + bitmap_git -> midx -> num_packs_in_base ; i ++ ) {
450469 if (prepare_midx_pack (the_repository , bitmap_git -> midx , i )) {
451470 warning (_ ("could not open pack %s" ),
452471 bitmap_git -> midx -> pack_names [i ]);
@@ -459,13 +478,20 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
459478 goto cleanup ;
460479 }
461480
462- preferred = bitmap_git -> midx -> packs [ preferred_pack ] ;
481+ preferred = nth_midxed_pack ( bitmap_git -> midx , preferred_pack ) ;
463482 if (!is_pack_valid (preferred )) {
464483 warning (_ ("preferred pack (%s) is invalid" ),
465484 preferred -> pack_name );
466485 goto cleanup ;
467486 }
468487
488+ if (midx -> base_midx ) {
489+ bitmap_git -> base = prepare_midx_bitmap_git (midx -> base_midx );
490+ bitmap_git -> base_nr = bitmap_git -> base -> base_nr + 1 ;
491+ } else {
492+ bitmap_git -> base_nr = 1 ;
493+ }
494+
469495 return 0 ;
470496
471497cleanup :
@@ -516,6 +542,7 @@ static int open_pack_bitmap_1(struct bitmap_index *bitmap_git, struct packed_git
516542 bitmap_git -> map_size = xsize_t (st .st_size );
517543 bitmap_git -> map = xmmap (NULL , bitmap_git -> map_size , PROT_READ , MAP_PRIVATE , fd , 0 );
518544 bitmap_git -> map_pos = 0 ;
545+ bitmap_git -> base_nr = 1 ;
519546 close (fd );
520547
521548 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
535562static int load_reverse_index (struct repository * r , struct bitmap_index * bitmap_git )
536563{
537564 if (bitmap_is_midx (bitmap_git )) {
538- uint32_t i ;
539- int ret ;
565+ struct multi_pack_index * m ;
540566
541567 /*
542568 * 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_
545571 * But we still need to open the individual pack .rev files,
546572 * since we will need to make use of them in pack-objects.
547573 */
548- for (i = 0 ; i < bitmap_git -> midx -> num_packs ; i ++ ) {
549- ret = load_pack_revindex (r , bitmap_git -> midx -> packs [i ]);
550- if (ret )
551- return ret ;
574+ for (m = bitmap_git -> midx ; m ; m = m -> base_midx ) {
575+ uint32_t i ;
576+ int ret ;
577+
578+ for (i = 0 ; i < m -> num_packs ; i ++ ) {
579+ ret = load_pack_revindex (r , m -> packs [i ]);
580+ if (ret )
581+ return ret ;
582+ }
552583 }
553584 return 0 ;
554585 }
@@ -574,6 +605,13 @@ static int load_bitmap(struct repository *r, struct bitmap_index *bitmap_git)
574605 if (!bitmap_git -> table_lookup && load_bitmap_entries_v1 (bitmap_git ) < 0 )
575606 goto failed ;
576607
608+ if (bitmap_git -> base ) {
609+ if (!bitmap_is_midx (bitmap_git ))
610+ BUG ("non-MIDX bitmap has non-NULL base bitmap index" );
611+ if (load_bitmap (r , bitmap_git -> base ) < 0 )
612+ goto failed ;
613+ }
614+
577615 return 0 ;
578616
579617failed :
@@ -658,10 +696,9 @@ struct bitmap_index *prepare_bitmap_git(struct repository *r)
658696
659697struct bitmap_index * prepare_midx_bitmap_git (struct multi_pack_index * midx )
660698{
661- struct repository * r = the_repository ;
662699 struct bitmap_index * bitmap_git = xcalloc (1 , sizeof (* bitmap_git ));
663700
664- if (!open_midx_bitmap_1 (bitmap_git , midx ) && ! load_bitmap ( r , bitmap_git ) )
701+ if (!open_midx_bitmap_1 (bitmap_git , midx ))
665702 return bitmap_git ;
666703
667704 free_bitmap_index (bitmap_git );
0 commit comments