@@ -91,7 +91,7 @@ static unsigned int input_offset, input_len;
91
91
static off_t consumed_bytes ;
92
92
static off_t max_input_size ;
93
93
static unsigned deepest_delta ;
94
- static git_SHA_CTX input_ctx ;
94
+ static git_hash_ctx input_ctx ;
95
95
static uint32_t input_crc32 ;
96
96
static int input_fd , output_fd ;
97
97
static const char * curr_pack ;
@@ -253,7 +253,7 @@ static void flush(void)
253
253
if (input_offset ) {
254
254
if (output_fd >= 0 )
255
255
write_or_die (output_fd , input_buffer , input_offset );
256
- git_SHA1_Update (& input_ctx , input_buffer , input_offset );
256
+ the_hash_algo -> update_fn (& input_ctx , input_buffer , input_offset );
257
257
memmove (input_buffer , input_buffer + input_offset , input_len );
258
258
input_offset = 0 ;
259
259
}
@@ -326,7 +326,7 @@ static const char *open_pack_file(const char *pack_name)
326
326
output_fd = -1 ;
327
327
nothread_data .pack_fd = input_fd ;
328
328
}
329
- git_SHA1_Init (& input_ctx );
329
+ the_hash_algo -> init_fn (& input_ctx );
330
330
return pack_name ;
331
331
}
332
332
@@ -437,22 +437,22 @@ static int is_delta_type(enum object_type type)
437
437
}
438
438
439
439
static void * unpack_entry_data (off_t offset , unsigned long size ,
440
- enum object_type type , unsigned char * sha1 )
440
+ enum object_type type , struct object_id * oid )
441
441
{
442
442
static char fixed_buf [8192 ];
443
443
int status ;
444
444
git_zstream stream ;
445
445
void * buf ;
446
- git_SHA_CTX c ;
446
+ git_hash_ctx c ;
447
447
char hdr [32 ];
448
448
int hdrlen ;
449
449
450
450
if (!is_delta_type (type )) {
451
451
hdrlen = xsnprintf (hdr , sizeof (hdr ), "%s %lu" , typename (type ), size ) + 1 ;
452
- git_SHA1_Init (& c );
453
- git_SHA1_Update (& c , hdr , hdrlen );
452
+ the_hash_algo -> init_fn (& c );
453
+ the_hash_algo -> update_fn (& c , hdr , hdrlen );
454
454
} else
455
- sha1 = NULL ;
455
+ oid = NULL ;
456
456
if (type == OBJ_BLOB && size > big_file_threshold )
457
457
buf = fixed_buf ;
458
458
else
@@ -469,8 +469,8 @@ static void *unpack_entry_data(off_t offset, unsigned long size,
469
469
stream .avail_in = input_len ;
470
470
status = git_inflate (& stream , 0 );
471
471
use (input_len - stream .avail_in );
472
- if (sha1 )
473
- git_SHA1_Update (& c , last_out , stream .next_out - last_out );
472
+ if (oid )
473
+ the_hash_algo -> update_fn (& c , last_out , stream .next_out - last_out );
474
474
if (buf == fixed_buf ) {
475
475
stream .next_out = buf ;
476
476
stream .avail_out = sizeof (fixed_buf );
@@ -479,15 +479,15 @@ static void *unpack_entry_data(off_t offset, unsigned long size,
479
479
if (stream .total_out != size || status != Z_STREAM_END )
480
480
bad_object (offset , _ ("inflate returned %d" ), status );
481
481
git_inflate_end (& stream );
482
- if (sha1 )
483
- git_SHA1_Final ( sha1 , & c );
482
+ if (oid )
483
+ the_hash_algo -> final_fn ( oid -> hash , & c );
484
484
return buf == fixed_buf ? NULL : buf ;
485
485
}
486
486
487
487
static void * unpack_raw_entry (struct object_entry * obj ,
488
488
off_t * ofs_offset ,
489
- unsigned char * ref_sha1 ,
490
- unsigned char * sha1 )
489
+ struct object_id * ref_oid ,
490
+ struct object_id * oid )
491
491
{
492
492
unsigned char * p ;
493
493
unsigned long size , c ;
@@ -515,8 +515,8 @@ static void *unpack_raw_entry(struct object_entry *obj,
515
515
516
516
switch (obj -> type ) {
517
517
case OBJ_REF_DELTA :
518
- hashcpy (ref_sha1 , fill (20 ));
519
- use (20 );
518
+ hashcpy (ref_oid -> hash , fill (the_hash_algo -> rawsz ));
519
+ use (the_hash_algo -> rawsz );
520
520
break ;
521
521
case OBJ_OFS_DELTA :
522
522
p = fill (1 );
@@ -546,7 +546,7 @@ static void *unpack_raw_entry(struct object_entry *obj,
546
546
}
547
547
obj -> hdr_size = consumed_bytes - obj -> idx .offset ;
548
548
549
- data = unpack_entry_data (obj -> idx .offset , obj -> size , obj -> type , sha1 );
549
+ data = unpack_entry_data (obj -> idx .offset , obj -> size , obj -> type , oid );
550
550
obj -> idx .crc32 = input_crc32 ;
551
551
return data ;
552
552
}
@@ -1119,11 +1119,11 @@ static void *threaded_second_pass(void *data)
1119
1119
* - calculate SHA1 of all non-delta objects;
1120
1120
* - remember base (SHA1 or offset) for all deltas.
1121
1121
*/
1122
- static void parse_pack_objects (unsigned char * sha1 )
1122
+ static void parse_pack_objects (unsigned char * hash )
1123
1123
{
1124
1124
int i , nr_delays = 0 ;
1125
1125
struct ofs_delta_entry * ofs_delta = ofs_deltas ;
1126
- unsigned char ref_delta_sha1 [ 20 ] ;
1126
+ struct object_id ref_delta_oid ;
1127
1127
struct stat st ;
1128
1128
1129
1129
if (verbose )
@@ -1133,16 +1133,16 @@ static void parse_pack_objects(unsigned char *sha1)
1133
1133
for (i = 0 ; i < nr_objects ; i ++ ) {
1134
1134
struct object_entry * obj = & objects [i ];
1135
1135
void * data = unpack_raw_entry (obj , & ofs_delta -> offset ,
1136
- ref_delta_sha1 ,
1137
- obj -> idx .oid . hash );
1136
+ & ref_delta_oid ,
1137
+ & obj -> idx .oid );
1138
1138
obj -> real_type = obj -> type ;
1139
1139
if (obj -> type == OBJ_OFS_DELTA ) {
1140
1140
nr_ofs_deltas ++ ;
1141
1141
ofs_delta -> obj_no = i ;
1142
1142
ofs_delta ++ ;
1143
1143
} else if (obj -> type == OBJ_REF_DELTA ) {
1144
1144
ALLOC_GROW (ref_deltas , nr_ref_deltas + 1 , ref_deltas_alloc );
1145
- hashcpy (ref_deltas [nr_ref_deltas ].sha1 , ref_delta_sha1 );
1145
+ hashcpy (ref_deltas [nr_ref_deltas ].sha1 , ref_delta_oid . hash );
1146
1146
ref_deltas [nr_ref_deltas ].obj_no = i ;
1147
1147
nr_ref_deltas ++ ;
1148
1148
} else if (!data ) {
@@ -1160,10 +1160,10 @@ static void parse_pack_objects(unsigned char *sha1)
1160
1160
1161
1161
/* Check pack integrity */
1162
1162
flush ();
1163
- git_SHA1_Final ( sha1 , & input_ctx );
1164
- if (hashcmp (fill (20 ), sha1 ))
1163
+ the_hash_algo -> final_fn ( hash , & input_ctx );
1164
+ if (hashcmp (fill (the_hash_algo -> rawsz ), hash ))
1165
1165
die (_ ("pack is corrupted (SHA1 mismatch)" ));
1166
- use (20 );
1166
+ use (the_hash_algo -> rawsz );
1167
1167
1168
1168
/* If input_fd is a file, we should have reached its end now. */
1169
1169
if (fstat (input_fd , & st ))
@@ -1239,21 +1239,21 @@ static void resolve_deltas(void)
1239
1239
/*
1240
1240
* Third pass:
1241
1241
* - append objects to convert thin pack to full pack if required
1242
- * - write the final 20-byte SHA-1
1242
+ * - write the final pack hash
1243
1243
*/
1244
1244
static void fix_unresolved_deltas (struct sha1file * f );
1245
- static void conclude_pack (int fix_thin_pack , const char * curr_pack , unsigned char * pack_sha1 )
1245
+ static void conclude_pack (int fix_thin_pack , const char * curr_pack , unsigned char * pack_hash )
1246
1246
{
1247
1247
if (nr_ref_deltas + nr_ofs_deltas == nr_resolved_deltas ) {
1248
1248
stop_progress (& progress );
1249
- /* Flush remaining pack final 20-byte SHA1 . */
1249
+ /* Flush remaining pack final hash . */
1250
1250
flush ();
1251
1251
return ;
1252
1252
}
1253
1253
1254
1254
if (fix_thin_pack ) {
1255
1255
struct sha1file * f ;
1256
- unsigned char read_sha1 [ 20 ], tail_sha1 [ 20 ];
1256
+ unsigned char read_hash [ GIT_MAX_RAWSZ ], tail_hash [ GIT_MAX_RAWSZ ];
1257
1257
struct strbuf msg = STRBUF_INIT ;
1258
1258
int nr_unresolved = nr_ofs_deltas + nr_ref_deltas - nr_resolved_deltas ;
1259
1259
int nr_objects_initial = nr_objects ;
@@ -1270,12 +1270,12 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
1270
1270
nr_objects - nr_objects_initial );
1271
1271
stop_progress_msg (& progress , msg .buf );
1272
1272
strbuf_release (& msg );
1273
- sha1close (f , tail_sha1 , 0 );
1274
- hashcpy (read_sha1 , pack_sha1 );
1275
- fixup_pack_header_footer (output_fd , pack_sha1 ,
1273
+ sha1close (f , tail_hash , 0 );
1274
+ hashcpy (read_hash , pack_hash );
1275
+ fixup_pack_header_footer (output_fd , pack_hash ,
1276
1276
curr_pack , nr_objects ,
1277
- read_sha1 , consumed_bytes - 20 );
1278
- if (hashcmp (read_sha1 , tail_sha1 ) != 0 )
1277
+ read_hash , consumed_bytes - the_hash_algo -> rawsz );
1278
+ if (hashcmp (read_hash , tail_hash ) != 0 )
1279
1279
die (_ ("Unexpected tail checksum for %s "
1280
1280
"(disk corruption?)" ), curr_pack );
1281
1281
}
@@ -1392,7 +1392,7 @@ static void fix_unresolved_deltas(struct sha1file *f)
1392
1392
static void final (const char * final_pack_name , const char * curr_pack_name ,
1393
1393
const char * final_index_name , const char * curr_index_name ,
1394
1394
const char * keep_name , const char * keep_msg ,
1395
- unsigned char * sha1 )
1395
+ unsigned char * hash )
1396
1396
{
1397
1397
const char * report = "pack" ;
1398
1398
struct strbuf pack_name = STRBUF_INIT ;
@@ -1413,7 +1413,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
1413
1413
int keep_fd , keep_msg_len = strlen (keep_msg );
1414
1414
1415
1415
if (!keep_name )
1416
- keep_name = odb_pack_name (& keep_name_buf , sha1 , "keep" );
1416
+ keep_name = odb_pack_name (& keep_name_buf , hash , "keep" );
1417
1417
1418
1418
keep_fd = odb_pack_keep (keep_name );
1419
1419
if (keep_fd < 0 ) {
@@ -1434,26 +1434,26 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
1434
1434
1435
1435
if (final_pack_name != curr_pack_name ) {
1436
1436
if (!final_pack_name )
1437
- final_pack_name = odb_pack_name (& pack_name , sha1 , "pack" );
1437
+ final_pack_name = odb_pack_name (& pack_name , hash , "pack" );
1438
1438
if (finalize_object_file (curr_pack_name , final_pack_name ))
1439
1439
die (_ ("cannot store pack file" ));
1440
1440
} else if (from_stdin )
1441
1441
chmod (final_pack_name , 0444 );
1442
1442
1443
1443
if (final_index_name != curr_index_name ) {
1444
1444
if (!final_index_name )
1445
- final_index_name = odb_pack_name (& index_name , sha1 , "idx" );
1445
+ final_index_name = odb_pack_name (& index_name , hash , "idx" );
1446
1446
if (finalize_object_file (curr_index_name , final_index_name ))
1447
1447
die (_ ("cannot store index file" ));
1448
1448
} else
1449
1449
chmod (final_index_name , 0444 );
1450
1450
1451
1451
if (!from_stdin ) {
1452
- printf ("%s\n" , sha1_to_hex (sha1 ));
1452
+ printf ("%s\n" , sha1_to_hex (hash ));
1453
1453
} else {
1454
1454
struct strbuf buf = STRBUF_INIT ;
1455
1455
1456
- strbuf_addf (& buf , "%s\t%s\n" , report , sha1_to_hex (sha1 ));
1456
+ strbuf_addf (& buf , "%s\t%s\n" , report , sha1_to_hex (hash ));
1457
1457
write_or_die (1 , buf .buf , buf .len );
1458
1458
strbuf_release (& buf );
1459
1459
@@ -1637,7 +1637,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1637
1637
keep_name_buf = STRBUF_INIT ;
1638
1638
struct pack_idx_entry * * idx_objects ;
1639
1639
struct pack_idx_option opts ;
1640
- unsigned char pack_sha1 [ 20 ];
1640
+ unsigned char pack_hash [ GIT_MAX_RAWSZ ];
1641
1641
unsigned foreign_nr = 1 ; /* zero is a "good" value, assume bad */
1642
1642
int report_end_of_input = 0 ;
1643
1643
@@ -1768,11 +1768,11 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1768
1768
if (show_stat )
1769
1769
obj_stat = xcalloc (st_add (nr_objects , 1 ), sizeof (struct object_stat ));
1770
1770
ofs_deltas = xcalloc (nr_objects , sizeof (struct ofs_delta_entry ));
1771
- parse_pack_objects (pack_sha1 );
1771
+ parse_pack_objects (pack_hash );
1772
1772
if (report_end_of_input )
1773
1773
write_in_full (2 , "\0" , 1 );
1774
1774
resolve_deltas ();
1775
- conclude_pack (fix_thin_pack , curr_pack , pack_sha1 );
1775
+ conclude_pack (fix_thin_pack , curr_pack , pack_hash );
1776
1776
free (ofs_deltas );
1777
1777
free (ref_deltas );
1778
1778
if (strict )
@@ -1784,14 +1784,14 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1784
1784
ALLOC_ARRAY (idx_objects , nr_objects );
1785
1785
for (i = 0 ; i < nr_objects ; i ++ )
1786
1786
idx_objects [i ] = & objects [i ].idx ;
1787
- curr_index = write_idx_file (index_name , idx_objects , nr_objects , & opts , pack_sha1 );
1787
+ curr_index = write_idx_file (index_name , idx_objects , nr_objects , & opts , pack_hash );
1788
1788
free (idx_objects );
1789
1789
1790
1790
if (!verify )
1791
1791
final (pack_name , curr_pack ,
1792
1792
index_name , curr_index ,
1793
1793
keep_name , keep_msg ,
1794
- pack_sha1 );
1794
+ pack_hash );
1795
1795
else
1796
1796
close (input_fd );
1797
1797
free (objects );
0 commit comments