1- #define USE_THE_REPOSITORY_VARIABLE
2-
31#include "git-compat-util.h"
42#include "gettext.h"
53#include "pack-revindex.h"
97#include "strbuf.h"
108#include "trace2.h"
119#include "parse.h"
10+ #include "repository.h"
1211#include "midx.h"
1312#include "csum-file.h"
1413
@@ -137,7 +136,7 @@ static void create_pack_revindex(struct packed_git *p)
137136 const unsigned num_ent = p -> num_objects ;
138137 unsigned i ;
139138 const char * index = p -> index_data ;
140- const unsigned hashsz = the_hash_algo -> rawsz ;
139+ const unsigned hashsz = p -> repo -> hash_algo -> rawsz ;
141140
142141 ALLOC_ARRAY (p -> revindex , num_ent + 1 );
143142 index += 4 * 256 ;
@@ -193,15 +192,20 @@ static char *pack_revindex_filename(struct packed_git *p)
193192}
194193
195194#define RIDX_HEADER_SIZE (12)
196- #define RIDX_MIN_SIZE (RIDX_HEADER_SIZE + (2 * the_hash_algo->rawsz))
195+
196+ static size_t ridx_min_size (const struct git_hash_algo * algo )
197+ {
198+ return RIDX_HEADER_SIZE + (2 * algo -> rawsz );
199+ }
197200
198201struct revindex_header {
199202 uint32_t signature ;
200203 uint32_t version ;
201204 uint32_t hash_id ;
202205};
203206
204- static int load_revindex_from_disk (char * revindex_name ,
207+ static int load_revindex_from_disk (const struct git_hash_algo * algo ,
208+ char * revindex_name ,
205209 uint32_t num_objects ,
206210 const uint32_t * * data_p , size_t * len_p )
207211{
@@ -228,12 +232,12 @@ static int load_revindex_from_disk(char *revindex_name,
228232
229233 revindex_size = xsize_t (st .st_size );
230234
231- if (revindex_size < RIDX_MIN_SIZE ) {
235+ if (revindex_size < ridx_min_size ( algo ) ) {
232236 ret = error (_ ("reverse-index file %s is too small" ), revindex_name );
233237 goto cleanup ;
234238 }
235239
236- if (revindex_size - RIDX_MIN_SIZE != st_mult (sizeof (uint32_t ), num_objects )) {
240+ if (revindex_size - ridx_min_size ( algo ) != st_mult (sizeof (uint32_t ), num_objects )) {
237241 ret = error (_ ("reverse-index file %s is corrupt" ), revindex_name );
238242 goto cleanup ;
239243 }
@@ -279,7 +283,8 @@ int load_pack_revindex_from_disk(struct packed_git *p)
279283
280284 revindex_name = pack_revindex_filename (p );
281285
282- ret = load_revindex_from_disk (revindex_name ,
286+ ret = load_revindex_from_disk (p -> repo -> hash_algo ,
287+ revindex_name ,
283288 p -> num_objects ,
284289 & p -> revindex_map ,
285290 & p -> revindex_size );
@@ -322,7 +327,7 @@ int verify_pack_revindex(struct packed_git *p)
322327 if (!p -> revindex_map || !p -> revindex_data )
323328 return res ;
324329
325- if (!hashfile_checksum_valid (the_repository -> hash_algo ,
330+ if (!hashfile_checksum_valid (p -> repo -> hash_algo ,
326331 (const unsigned char * )p -> revindex_map , p -> revindex_size )) {
327332 error (_ ("invalid checksum" ));
328333 res = -1 ;
@@ -375,19 +380,20 @@ int load_midx_revindex(struct multi_pack_index *m)
375380 * not want to accidentally call munmap() in the middle of the
376381 * MIDX.
377382 */
378- trace2_data_string ("load_midx_revindex" , the_repository ,
383+ trace2_data_string ("load_midx_revindex" , m -> repo ,
379384 "source" , "midx" );
380385 m -> revindex_data = (const uint32_t * )m -> chunk_revindex ;
381386 return 0 ;
382387 }
383388
384- trace2_data_string ("load_midx_revindex" , the_repository ,
389+ trace2_data_string ("load_midx_revindex" , m -> repo ,
385390 "source" , "rev" );
386391
387392 get_midx_filename_ext (m -> repo -> hash_algo , & revindex_name , m -> object_dir ,
388393 get_midx_checksum (m ), MIDX_EXT_REV );
389394
390- ret = load_revindex_from_disk (revindex_name .buf ,
395+ ret = load_revindex_from_disk (m -> repo -> hash_algo ,
396+ revindex_name .buf ,
391397 m -> num_objects ,
392398 & m -> revindex_map ,
393399 & m -> revindex_len );
@@ -419,7 +425,7 @@ int offset_to_pack_pos(struct packed_git *p, off_t ofs, uint32_t *pos)
419425{
420426 unsigned lo , hi ;
421427
422- if (load_pack_revindex (the_repository , p ) < 0 )
428+ if (load_pack_revindex (p -> repo , p ) < 0 )
423429 return -1 ;
424430
425431 lo = 0 ;
@@ -465,7 +471,7 @@ off_t pack_pos_to_offset(struct packed_git *p, uint32_t pos)
465471 if (p -> revindex )
466472 return p -> revindex [pos ].offset ;
467473 else if (pos == p -> num_objects )
468- return p -> pack_size - the_hash_algo -> rawsz ;
474+ return p -> pack_size - p -> repo -> hash_algo -> rawsz ;
469475 else
470476 return nth_packed_object_offset (p , pack_pos_to_index (p , pos ));
471477}
0 commit comments