@@ -451,50 +451,48 @@ static uint32_t midx_for_pack(struct multi_pack_index **_m,
451451 return pack_int_id - m -> num_packs_in_base ;
452452}
453453
454- int prepare_midx_pack (struct repository * r , struct multi_pack_index * m ,
455- uint32_t pack_int_id )
454+ struct packed_git * prepare_midx_pack (struct repository * r ,
455+ struct multi_pack_index * m ,
456+ uint32_t pack_int_id )
456457{
457- struct strbuf pack_name = STRBUF_INIT ;
458- struct strbuf key = STRBUF_INIT ;
459- struct packed_git * p ;
460-
461- pack_int_id = midx_for_pack (& m , pack_int_id );
462-
463- if (m -> packs [pack_int_id ] == MIDX_PACK_ERROR )
464- return 1 ;
465- if (m -> packs [pack_int_id ])
466- return 0 ;
467-
468- strbuf_addf (& pack_name , "%s/pack/%s" , m -> object_dir ,
469- m -> pack_names [pack_int_id ]);
470-
471- /* pack_map holds the ".pack" name, but we have the .idx */
472- strbuf_addbuf (& key , & pack_name );
473- strbuf_strip_suffix (& key , ".idx" );
474- strbuf_addstr (& key , ".pack" );
475- p = hashmap_get_entry_from_hash (& r -> objects -> pack_map ,
476- strhash (key .buf ), key .buf ,
477- struct packed_git , packmap_ent );
478- if (!p ) {
479- p = add_packed_git (r , pack_name .buf , pack_name .len , m -> local );
480- if (p ) {
481- install_packed_git (r , p );
482- list_add_tail (& p -> mru , & r -> objects -> packed_git_mru );
458+ uint32_t pack_pos = midx_for_pack (& m , pack_int_id );
459+
460+ if (!m -> packs [pack_pos ]) {
461+ struct strbuf pack_name = STRBUF_INIT ;
462+ struct strbuf key = STRBUF_INIT ;
463+ struct packed_git * p ;
464+
465+ strbuf_addf (& pack_name , "%s/pack/%s" , m -> object_dir ,
466+ m -> pack_names [pack_pos ]);
467+
468+ /* pack_map holds the ".pack" name, but we have the .idx */
469+ strbuf_addbuf (& key , & pack_name );
470+ strbuf_strip_suffix (& key , ".idx" );
471+ strbuf_addstr (& key , ".pack" );
472+ p = hashmap_get_entry_from_hash (& r -> objects -> pack_map ,
473+ strhash (key .buf ), key .buf ,
474+ struct packed_git , packmap_ent );
475+ if (!p ) {
476+ p = add_packed_git (r , pack_name .buf , pack_name .len ,
477+ m -> local );
478+ if (p ) {
479+ install_packed_git (r , p );
480+ list_add_tail (& p -> mru ,
481+ & r -> objects -> packed_git_mru );
482+ }
483483 }
484- }
485484
486- strbuf_release (& pack_name );
487- strbuf_release (& key );
485+ strbuf_release (& pack_name );
486+ strbuf_release (& key );
488487
489- if (! p ) {
490- m -> packs [ pack_int_id ] = MIDX_PACK_ERROR ;
491- return 1 ;
488+ m -> packs [ pack_pos ] = p ? p : MIDX_PACK_ERROR ;
489+ if ( p )
490+ p -> multi_pack_index = 1 ;
492491 }
493492
494- p -> multi_pack_index = 1 ;
495- m -> packs [pack_int_id ] = p ;
496-
497- return 0 ;
493+ if (m -> packs [pack_pos ] == MIDX_PACK_ERROR )
494+ return NULL ;
495+ return m -> packs [pack_pos ];
498496}
499497
500498struct packed_git * nth_midxed_pack (struct multi_pack_index * m ,
@@ -506,6 +504,13 @@ struct packed_git *nth_midxed_pack(struct multi_pack_index *m,
506504 return m -> packs [local_pack_int_id ];
507505}
508506
507+ const char * nth_midxed_pack_name (struct multi_pack_index * m ,
508+ uint32_t pack_int_id )
509+ {
510+ uint32_t local_pack_int_id = midx_for_pack (& m , pack_int_id );
511+ return m -> pack_names [local_pack_int_id ];
512+ }
513+
509514#define MIDX_CHUNK_BITMAPPED_PACKS_WIDTH (2 * sizeof(uint32_t))
510515
511516int nth_bitmapped_pack (struct repository * r , struct multi_pack_index * m ,
@@ -516,10 +521,11 @@ int nth_bitmapped_pack(struct repository *r, struct multi_pack_index *m,
516521 if (!m -> chunk_bitmapped_packs )
517522 return error (_ ("MIDX does not contain the BTMP chunk" ));
518523
519- if (prepare_midx_pack (r , m , pack_int_id ))
520- return error (_ ("could not load bitmapped pack %" PRIu32 ), pack_int_id );
524+ bp -> p = prepare_midx_pack (r , m , pack_int_id );
525+ if (!bp -> p )
526+ return error (_ ("could not load bitmapped pack %" PRIu32 ),
527+ pack_int_id );
521528
522- bp -> p = m -> packs [local_pack_int_id ];
523529 bp -> bitmap_pos = get_be32 ((char * )m -> chunk_bitmapped_packs +
524530 MIDX_CHUNK_BITMAPPED_PACKS_WIDTH * local_pack_int_id );
525531 bp -> bitmap_nr = get_be32 ((char * )m -> chunk_bitmapped_packs +
@@ -616,9 +622,9 @@ int fill_midx_entry(struct repository *r,
616622 midx_for_object (& m , pos );
617623 pack_int_id = nth_midxed_pack_int_id (m , pos );
618624
619- if (prepare_midx_pack (r , m , pack_int_id ))
625+ p = prepare_midx_pack (r , m , pack_int_id );
626+ if (!p )
620627 return 0 ;
621- p = m -> packs [pack_int_id - m -> num_packs_in_base ];
622628
623629 /*
624630 * We are about to tell the caller where they can locate the
@@ -919,7 +925,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
919925 _ ("Looking for referenced packfiles" ),
920926 m -> num_packs + m -> num_packs_in_base );
921927 for (i = 0 ; i < m -> num_packs + m -> num_packs_in_base ; i ++ ) {
922- if (prepare_midx_pack (r , m , i ))
928+ if (! prepare_midx_pack (r , m , i ))
923929 midx_report ("failed to load pack in position %d" , i );
924930
925931 display_progress (progress , i + 1 );
0 commit comments