@@ -25,7 +25,7 @@ int cmp_idx_or_pack_name(const char *idx_or_pack_name,
2525
2626const unsigned char * get_midx_checksum (struct multi_pack_index * m )
2727{
28- return m -> data + m -> data_len - the_hash_algo -> rawsz ;
28+ return m -> data + m -> data_len - m -> repo -> hash_algo -> rawsz ;
2929}
3030
3131void get_midx_filename (struct strbuf * out , const char * object_dir )
@@ -94,7 +94,8 @@ static int midx_read_object_offsets(const unsigned char *chunk_start,
9494
9595#define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + the_hash_algo->rawsz)
9696
97- static struct multi_pack_index * load_multi_pack_index_one (const char * object_dir ,
97+ static struct multi_pack_index * load_multi_pack_index_one (struct repository * r ,
98+ const char * object_dir ,
9899 const char * midx_name ,
99100 int local )
100101{
@@ -131,7 +132,7 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir
131132 m -> data = midx_map ;
132133 m -> data_len = midx_size ;
133134 m -> local = local ;
134- m -> repo = the_repository ;
135+ m -> repo = r ;
135136
136137 m -> signature = get_be32 (m -> data );
137138 if (m -> signature != MIDX_SIGNATURE )
@@ -144,12 +145,12 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir
144145 m -> version );
145146
146147 hash_version = m -> data [MIDX_BYTE_HASH_VERSION ];
147- if (hash_version != oid_version (the_hash_algo )) {
148+ if (hash_version != oid_version (r -> hash_algo )) {
148149 error (_ ("multi-pack-index hash version %u does not match version %u" ),
149- hash_version , oid_version (the_hash_algo ));
150+ hash_version , oid_version (r -> hash_algo ));
150151 goto cleanup_fail ;
151152 }
152- m -> hash_len = the_hash_algo -> rawsz ;
153+ m -> hash_len = r -> hash_algo -> rawsz ;
153154
154155 m -> num_chunks = m -> data [MIDX_BYTE_NUM_CHUNKS ];
155156
@@ -206,8 +207,8 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir
206207 m -> pack_names [i ]);
207208 }
208209
209- trace2_data_intmax ("midx" , the_repository , "load/num_packs" , m -> num_packs );
210- trace2_data_intmax ("midx" , the_repository , "load/num_objects" , m -> num_objects );
210+ trace2_data_intmax ("midx" , r , "load/num_packs" , m -> num_packs );
211+ trace2_data_intmax ("midx" , r , "load/num_objects" , m -> num_objects );
211212
212213 free_chunkfile (cf );
213214 return m ;
@@ -240,8 +241,9 @@ void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,
240241 strbuf_addf (buf , "/multi-pack-index-%s.%s" , hash_to_hex (hash ), ext );
241242}
242243
243- static int open_multi_pack_index_chain (const char * chain_file ,
244- int * fd , struct stat * st )
244+ static int open_multi_pack_index_chain (const struct git_hash_algo * hash_algo ,
245+ const char * chain_file , int * fd ,
246+ struct stat * st )
245247{
246248 * fd = git_open (chain_file );
247249 if (* fd < 0 )
@@ -250,7 +252,7 @@ static int open_multi_pack_index_chain(const char *chain_file,
250252 close (* fd );
251253 return 0 ;
252254 }
253- if (st -> st_size < the_hash_algo -> hexsz ) {
255+ if (st -> st_size < hash_algo -> hexsz ) {
254256 close (* fd );
255257 if (!st -> st_size ) {
256258 /* treat empty files the same as missing */
@@ -292,7 +294,8 @@ static int add_midx_to_chain(struct multi_pack_index *midx,
292294 return 1 ;
293295}
294296
295- static struct multi_pack_index * load_midx_chain_fd_st (const char * object_dir ,
297+ static struct multi_pack_index * load_midx_chain_fd_st (struct repository * r ,
298+ const char * object_dir ,
296299 int local ,
297300 int fd , struct stat * st ,
298301 int * incomplete_chain )
@@ -303,7 +306,7 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,
303306 uint32_t i , count ;
304307 FILE * fp = xfdopen (fd , "r" );
305308
306- count = st -> st_size / (the_hash_algo -> hexsz + 1 );
309+ count = st -> st_size / (r -> hash_algo -> hexsz + 1 );
307310
308311 for (i = 0 ; i < count ; i ++ ) {
309312 struct multi_pack_index * m ;
@@ -312,7 +315,7 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,
312315 if (strbuf_getline_lf (& buf , fp ) == EOF )
313316 break ;
314317
315- if (get_oid_hex (buf .buf , & layer )) {
318+ if (get_oid_hex_algop (buf .buf , & layer , r -> hash_algo )) {
316319 warning (_ ("invalid multi-pack-index chain: line '%s' "
317320 "not a hash" ),
318321 buf .buf );
@@ -325,7 +328,7 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,
325328 strbuf_reset (& buf );
326329 get_split_midx_filename_ext (& buf , object_dir , layer .hash ,
327330 MIDX_EXT_MIDX );
328- m = load_multi_pack_index_one (object_dir , buf .buf , local );
331+ m = load_multi_pack_index_one (r , object_dir , buf .buf , local );
329332
330333 if (m ) {
331334 if (add_midx_to_chain (m , midx_chain )) {
@@ -348,7 +351,8 @@ static struct multi_pack_index *load_midx_chain_fd_st(const char *object_dir,
348351 return midx_chain ;
349352}
350353
351- static struct multi_pack_index * load_multi_pack_index_chain (const char * object_dir ,
354+ static struct multi_pack_index * load_multi_pack_index_chain (struct repository * r ,
355+ const char * object_dir ,
352356 int local )
353357{
354358 struct strbuf chain_file = STRBUF_INIT ;
@@ -357,10 +361,10 @@ static struct multi_pack_index *load_multi_pack_index_chain(const char *object_d
357361 struct multi_pack_index * m = NULL ;
358362
359363 get_midx_chain_filename (& chain_file , object_dir );
360- if (open_multi_pack_index_chain (chain_file .buf , & fd , & st )) {
364+ if (open_multi_pack_index_chain (r -> hash_algo , chain_file .buf , & fd , & st )) {
361365 int incomplete ;
362366 /* ownership of fd is taken over by load function */
363- m = load_midx_chain_fd_st (object_dir , local , fd , & st ,
367+ m = load_midx_chain_fd_st (r , object_dir , local , fd , & st ,
364368 & incomplete );
365369 }
366370
@@ -376,9 +380,10 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir,
376380
377381 get_midx_filename (& midx_name , object_dir );
378382
379- m = load_multi_pack_index_one (object_dir , midx_name .buf , local );
383+ m = load_multi_pack_index_one (the_repository , object_dir ,
384+ midx_name .buf , local );
380385 if (!m )
381- m = load_multi_pack_index_chain (object_dir , local );
386+ m = load_multi_pack_index_chain (the_repository , object_dir , local );
382387
383388 strbuf_release (& midx_name );
384389
@@ -520,7 +525,7 @@ int bsearch_one_midx(const struct object_id *oid, struct multi_pack_index *m,
520525 uint32_t * result )
521526{
522527 int ret = bsearch_hash (oid -> hash , m -> chunk_oid_fanout ,
523- m -> chunk_oid_lookup , the_hash_algo -> rawsz ,
528+ m -> chunk_oid_lookup , m -> repo -> hash_algo -> rawsz ,
524529 result );
525530 if (result )
526531 * result += m -> num_objects_in_base ;
@@ -551,7 +556,7 @@ struct object_id *nth_midxed_object_oid(struct object_id *oid,
551556 n = midx_for_object (& m , n );
552557
553558 oidread (oid , m -> chunk_oid_lookup + st_mult (m -> hash_len , n ),
554- the_repository -> hash_algo );
559+ m -> repo -> hash_algo );
555560 return oid ;
556561}
557562
0 commit comments