18
18
#define MIDX_HASH_LEN 20
19
19
#define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + MIDX_HASH_LEN)
20
20
21
- #define MIDX_MAX_CHUNKS 1
21
+ #define MIDX_MAX_CHUNKS 2
22
22
#define MIDX_CHUNK_ALIGNMENT 4
23
23
#define MIDX_CHUNKID_PACKNAMES 0x504e414d /* "PNAM" */
24
+ #define MIDX_CHUNKID_OIDLOOKUP 0x4f49444c /* "OIDL" */
24
25
#define MIDX_CHUNKLOOKUP_WIDTH (sizeof(uint32_t) + sizeof(uint64_t))
25
26
26
27
static char * get_midx_filename (const char * object_dir )
@@ -101,6 +102,10 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir)
101
102
m -> chunk_pack_names = m -> data + chunk_offset ;
102
103
break ;
103
104
105
+ case MIDX_CHUNKID_OIDLOOKUP :
106
+ m -> chunk_oid_lookup = m -> data + chunk_offset ;
107
+ break ;
108
+
104
109
case 0 :
105
110
die (_ ("terminating multi-pack-index chunk id appears earlier than expected" ));
106
111
break ;
@@ -116,6 +121,8 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir)
116
121
117
122
if (!m -> chunk_pack_names )
118
123
die (_ ("multi-pack-index missing required pack-name chunk" ));
124
+ if (!m -> chunk_oid_lookup )
125
+ die (_ ("multi-pack-index missing required OID lookup chunk" ));
119
126
120
127
m -> pack_names = xcalloc (m -> num_packs , sizeof (* m -> pack_names ));
121
128
@@ -382,6 +389,32 @@ static size_t write_midx_pack_names(struct hashfile *f,
382
389
return written ;
383
390
}
384
391
392
+ static size_t write_midx_oid_lookup (struct hashfile * f , unsigned char hash_len ,
393
+ struct pack_midx_entry * objects ,
394
+ uint32_t nr_objects )
395
+ {
396
+ struct pack_midx_entry * list = objects ;
397
+ uint32_t i ;
398
+ size_t written = 0 ;
399
+
400
+ for (i = 0 ; i < nr_objects ; i ++ ) {
401
+ struct pack_midx_entry * obj = list ++ ;
402
+
403
+ if (i < nr_objects - 1 ) {
404
+ struct pack_midx_entry * next = list ;
405
+ if (oidcmp (& obj -> oid , & next -> oid ) >= 0 )
406
+ BUG ("OIDs not in order: %s >= %s" ,
407
+ oid_to_hex (& obj -> oid ),
408
+ oid_to_hex (& next -> oid ));
409
+ }
410
+
411
+ hashwrite (f , obj -> oid .hash , (int )hash_len );
412
+ written += hash_len ;
413
+ }
414
+
415
+ return written ;
416
+ }
417
+
385
418
int write_midx_file (const char * object_dir )
386
419
{
387
420
unsigned char cur_chunk , num_chunks = 0 ;
@@ -428,17 +461,21 @@ int write_midx_file(const char *object_dir)
428
461
FREE_AND_NULL (midx_name );
429
462
430
463
cur_chunk = 0 ;
431
- num_chunks = 1 ;
464
+ num_chunks = 2 ;
432
465
433
466
written = write_midx_header (f , num_chunks , packs .nr );
434
467
435
468
chunk_ids [cur_chunk ] = MIDX_CHUNKID_PACKNAMES ;
436
469
chunk_offsets [cur_chunk ] = written + (num_chunks + 1 ) * MIDX_CHUNKLOOKUP_WIDTH ;
437
470
438
471
cur_chunk ++ ;
439
- chunk_ids [cur_chunk ] = 0 ;
472
+ chunk_ids [cur_chunk ] = MIDX_CHUNKID_OIDLOOKUP ;
440
473
chunk_offsets [cur_chunk ] = chunk_offsets [cur_chunk - 1 ] + packs .pack_name_concat_len ;
441
474
475
+ cur_chunk ++ ;
476
+ chunk_ids [cur_chunk ] = 0 ;
477
+ chunk_offsets [cur_chunk ] = chunk_offsets [cur_chunk - 1 ] + nr_entries * MIDX_HASH_LEN ;
478
+
442
479
for (i = 0 ; i <= num_chunks ; i ++ ) {
443
480
if (i && chunk_offsets [i ] < chunk_offsets [i - 1 ])
444
481
BUG ("incorrect chunk offsets: %" PRIu64 " before %" PRIu64 ,
@@ -468,6 +505,10 @@ int write_midx_file(const char *object_dir)
468
505
written += write_midx_pack_names (f , packs .names , packs .nr );
469
506
break ;
470
507
508
+ case MIDX_CHUNKID_OIDLOOKUP :
509
+ written += write_midx_oid_lookup (f , MIDX_HASH_LEN , entries , nr_entries );
510
+ break ;
511
+
471
512
default :
472
513
BUG ("trying to write unknown chunk id %" PRIx32 ,
473
514
chunk_ids [i ]);
0 commit comments