@@ -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
}
@@ -1118,11 +1118,11 @@ static void *threaded_second_pass(void *data)
1118
1118
* - calculate SHA1 of all non-delta objects;
1119
1119
* - remember base (SHA1 or offset) for all deltas.
1120
1120
*/
1121
- static void parse_pack_objects (unsigned char * sha1 )
1121
+ static void parse_pack_objects (unsigned char * hash )
1122
1122
{
1123
1123
int i , nr_delays = 0 ;
1124
1124
struct ofs_delta_entry * ofs_delta = ofs_deltas ;
1125
- unsigned char ref_delta_sha1 [ 20 ] ;
1125
+ struct object_id ref_delta_oid ;
1126
1126
struct stat st ;
1127
1127
1128
1128
if (verbose )
@@ -1132,16 +1132,16 @@ static void parse_pack_objects(unsigned char *sha1)
1132
1132
for (i = 0 ; i < nr_objects ; i ++ ) {
1133
1133
struct object_entry * obj = & objects [i ];
1134
1134
void * data = unpack_raw_entry (obj , & ofs_delta -> offset ,
1135
- ref_delta_sha1 ,
1136
- obj -> idx .oid . hash );
1135
+ & ref_delta_oid ,
1136
+ & obj -> idx .oid );
1137
1137
obj -> real_type = obj -> type ;
1138
1138
if (obj -> type == OBJ_OFS_DELTA ) {
1139
1139
nr_ofs_deltas ++ ;
1140
1140
ofs_delta -> obj_no = i ;
1141
1141
ofs_delta ++ ;
1142
1142
} else if (obj -> type == OBJ_REF_DELTA ) {
1143
1143
ALLOC_GROW (ref_deltas , nr_ref_deltas + 1 , ref_deltas_alloc );
1144
- hashcpy (ref_deltas [nr_ref_deltas ].sha1 , ref_delta_sha1 );
1144
+ hashcpy (ref_deltas [nr_ref_deltas ].sha1 , ref_delta_oid . hash );
1145
1145
ref_deltas [nr_ref_deltas ].obj_no = i ;
1146
1146
nr_ref_deltas ++ ;
1147
1147
} else if (!data ) {
@@ -1159,10 +1159,10 @@ static void parse_pack_objects(unsigned char *sha1)
1159
1159
1160
1160
/* Check pack integrity */
1161
1161
flush ();
1162
- git_SHA1_Final ( sha1 , & input_ctx );
1163
- if (hashcmp (fill (20 ), sha1 ))
1162
+ the_hash_algo -> final_fn ( hash , & input_ctx );
1163
+ if (hashcmp (fill (the_hash_algo -> rawsz ), hash ))
1164
1164
die (_ ("pack is corrupted (SHA1 mismatch)" ));
1165
- use (20 );
1165
+ use (the_hash_algo -> rawsz );
1166
1166
1167
1167
/* If input_fd is a file, we should have reached its end now. */
1168
1168
if (fstat (input_fd , & st ))
@@ -1238,21 +1238,21 @@ static void resolve_deltas(void)
1238
1238
/*
1239
1239
* Third pass:
1240
1240
* - append objects to convert thin pack to full pack if required
1241
- * - write the final 20-byte SHA-1
1241
+ * - write the final pack hash
1242
1242
*/
1243
- static void fix_unresolved_deltas (struct sha1file * f );
1244
- static void conclude_pack (int fix_thin_pack , const char * curr_pack , unsigned char * pack_sha1 )
1243
+ static void fix_unresolved_deltas (struct hashfile * f );
1244
+ static void conclude_pack (int fix_thin_pack , const char * curr_pack , unsigned char * pack_hash )
1245
1245
{
1246
1246
if (nr_ref_deltas + nr_ofs_deltas == nr_resolved_deltas ) {
1247
1247
stop_progress (& progress );
1248
- /* Flush remaining pack final 20-byte SHA1 . */
1248
+ /* Flush remaining pack final hash . */
1249
1249
flush ();
1250
1250
return ;
1251
1251
}
1252
1252
1253
1253
if (fix_thin_pack ) {
1254
- struct sha1file * f ;
1255
- unsigned char read_sha1 [ 20 ], tail_sha1 [ 20 ];
1254
+ struct hashfile * f ;
1255
+ unsigned char read_hash [ GIT_MAX_RAWSZ ], tail_hash [ GIT_MAX_RAWSZ ];
1256
1256
struct strbuf msg = STRBUF_INIT ;
1257
1257
int nr_unresolved = nr_ofs_deltas + nr_ref_deltas - nr_resolved_deltas ;
1258
1258
int nr_objects_initial = nr_objects ;
@@ -1261,20 +1261,20 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
1261
1261
REALLOC_ARRAY (objects , nr_objects + nr_unresolved + 1 );
1262
1262
memset (objects + nr_objects + 1 , 0 ,
1263
1263
nr_unresolved * sizeof (* objects ));
1264
- f = sha1fd (output_fd , curr_pack );
1264
+ f = hashfd (output_fd , curr_pack );
1265
1265
fix_unresolved_deltas (f );
1266
1266
strbuf_addf (& msg , Q_ ("completed with %d local object" ,
1267
1267
"completed with %d local objects" ,
1268
1268
nr_objects - nr_objects_initial ),
1269
1269
nr_objects - nr_objects_initial );
1270
1270
stop_progress_msg (& progress , msg .buf );
1271
1271
strbuf_release (& msg );
1272
- sha1close (f , tail_sha1 , 0 );
1273
- hashcpy (read_sha1 , pack_sha1 );
1274
- fixup_pack_header_footer (output_fd , pack_sha1 ,
1272
+ hashclose (f , tail_hash , 0 );
1273
+ hashcpy (read_hash , pack_hash );
1274
+ fixup_pack_header_footer (output_fd , pack_hash ,
1275
1275
curr_pack , nr_objects ,
1276
- read_sha1 , consumed_bytes - 20 );
1277
- if (hashcmp (read_sha1 , tail_sha1 ) != 0 )
1276
+ read_hash , consumed_bytes - the_hash_algo -> rawsz );
1277
+ if (hashcmp (read_hash , tail_hash ) != 0 )
1278
1278
die (_ ("Unexpected tail checksum for %s "
1279
1279
"(disk corruption?)" ), curr_pack );
1280
1280
}
@@ -1285,7 +1285,7 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
1285
1285
nr_ofs_deltas + nr_ref_deltas - nr_resolved_deltas );
1286
1286
}
1287
1287
1288
- static int write_compressed (struct sha1file * f , void * in , unsigned int size )
1288
+ static int write_compressed (struct hashfile * f , void * in , unsigned int size )
1289
1289
{
1290
1290
git_zstream stream ;
1291
1291
int status ;
@@ -1299,7 +1299,7 @@ static int write_compressed(struct sha1file *f, void *in, unsigned int size)
1299
1299
stream .next_out = outbuf ;
1300
1300
stream .avail_out = sizeof (outbuf );
1301
1301
status = git_deflate (& stream , Z_FINISH );
1302
- sha1write (f , outbuf , sizeof (outbuf ) - stream .avail_out );
1302
+ hashwrite (f , outbuf , sizeof (outbuf ) - stream .avail_out );
1303
1303
} while (status == Z_OK );
1304
1304
1305
1305
if (status != Z_STREAM_END )
@@ -1309,7 +1309,7 @@ static int write_compressed(struct sha1file *f, void *in, unsigned int size)
1309
1309
return size ;
1310
1310
}
1311
1311
1312
- static struct object_entry * append_obj_to_pack (struct sha1file * f ,
1312
+ static struct object_entry * append_obj_to_pack (struct hashfile * f ,
1313
1313
const unsigned char * sha1 , void * buf ,
1314
1314
unsigned long size , enum object_type type )
1315
1315
{
@@ -1326,15 +1326,15 @@ static struct object_entry *append_obj_to_pack(struct sha1file *f,
1326
1326
}
1327
1327
header [n ++ ] = c ;
1328
1328
crc32_begin (f );
1329
- sha1write (f , header , n );
1329
+ hashwrite (f , header , n );
1330
1330
obj [0 ].size = size ;
1331
1331
obj [0 ].hdr_size = n ;
1332
1332
obj [0 ].type = type ;
1333
1333
obj [0 ].real_type = type ;
1334
1334
obj [1 ].idx .offset = obj [0 ].idx .offset + n ;
1335
1335
obj [1 ].idx .offset += write_compressed (f , buf , size );
1336
1336
obj [0 ].idx .crc32 = crc32_end (f );
1337
- sha1flush (f );
1337
+ hashflush (f );
1338
1338
hashcpy (obj -> idx .oid .hash , sha1 );
1339
1339
return obj ;
1340
1340
}
@@ -1346,7 +1346,7 @@ static int delta_pos_compare(const void *_a, const void *_b)
1346
1346
return a -> obj_no - b -> obj_no ;
1347
1347
}
1348
1348
1349
- static void fix_unresolved_deltas (struct sha1file * f )
1349
+ static void fix_unresolved_deltas (struct hashfile * f )
1350
1350
{
1351
1351
struct ref_delta_entry * * sorted_by_pos ;
1352
1352
int i ;
@@ -1402,7 +1402,7 @@ static const char *derive_filename(const char *pack_name, const char *suffix,
1402
1402
}
1403
1403
1404
1404
static void write_special_file (const char * suffix , const char * msg ,
1405
- const char * pack_name , const unsigned char * sha1 ,
1405
+ const char * pack_name , const unsigned char * hash ,
1406
1406
const char * * report )
1407
1407
{
1408
1408
struct strbuf name_buf = STRBUF_INIT ;
@@ -1413,7 +1413,7 @@ static void write_special_file(const char *suffix, const char *msg,
1413
1413
if (pack_name )
1414
1414
filename = derive_filename (pack_name , suffix , & name_buf );
1415
1415
else
1416
- filename = odb_pack_name (& name_buf , sha1 , suffix );
1416
+ filename = odb_pack_name (& name_buf , hash , suffix );
1417
1417
1418
1418
fd = odb_pack_keep (filename );
1419
1419
if (fd < 0 ) {
@@ -1437,7 +1437,7 @@ static void write_special_file(const char *suffix, const char *msg,
1437
1437
static void final (const char * final_pack_name , const char * curr_pack_name ,
1438
1438
const char * final_index_name , const char * curr_index_name ,
1439
1439
const char * keep_msg , const char * promisor_msg ,
1440
- unsigned char * sha1 )
1440
+ unsigned char * hash )
1441
1441
{
1442
1442
const char * report = "pack" ;
1443
1443
struct strbuf pack_name = STRBUF_INIT ;
@@ -1454,34 +1454,34 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
1454
1454
}
1455
1455
1456
1456
if (keep_msg )
1457
- write_special_file ("keep" , keep_msg , final_pack_name , sha1 ,
1457
+ write_special_file ("keep" , keep_msg , final_pack_name , hash ,
1458
1458
& report );
1459
1459
if (promisor_msg )
1460
1460
write_special_file ("promisor" , promisor_msg , final_pack_name ,
1461
- sha1 , NULL );
1461
+ hash , NULL );
1462
1462
1463
1463
if (final_pack_name != curr_pack_name ) {
1464
1464
if (!final_pack_name )
1465
- final_pack_name = odb_pack_name (& pack_name , sha1 , "pack" );
1465
+ final_pack_name = odb_pack_name (& pack_name , hash , "pack" );
1466
1466
if (finalize_object_file (curr_pack_name , final_pack_name ))
1467
1467
die (_ ("cannot store pack file" ));
1468
1468
} else if (from_stdin )
1469
1469
chmod (final_pack_name , 0444 );
1470
1470
1471
1471
if (final_index_name != curr_index_name ) {
1472
1472
if (!final_index_name )
1473
- final_index_name = odb_pack_name (& index_name , sha1 , "idx" );
1473
+ final_index_name = odb_pack_name (& index_name , hash , "idx" );
1474
1474
if (finalize_object_file (curr_index_name , final_index_name ))
1475
1475
die (_ ("cannot store index file" ));
1476
1476
} else
1477
1477
chmod (final_index_name , 0444 );
1478
1478
1479
1479
if (!from_stdin ) {
1480
- printf ("%s\n" , sha1_to_hex (sha1 ));
1480
+ printf ("%s\n" , sha1_to_hex (hash ));
1481
1481
} else {
1482
1482
struct strbuf buf = STRBUF_INIT ;
1483
1483
1484
- strbuf_addf (& buf , "%s\t%s\n" , report , sha1_to_hex (sha1 ));
1484
+ strbuf_addf (& buf , "%s\t%s\n" , report , sha1_to_hex (hash ));
1485
1485
write_or_die (1 , buf .buf , buf .len );
1486
1486
strbuf_release (& buf );
1487
1487
@@ -1652,7 +1652,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1652
1652
struct strbuf index_name_buf = STRBUF_INIT ;
1653
1653
struct pack_idx_entry * * idx_objects ;
1654
1654
struct pack_idx_option opts ;
1655
- unsigned char pack_sha1 [ 20 ];
1655
+ unsigned char pack_hash [ GIT_MAX_RAWSZ ];
1656
1656
unsigned foreign_nr = 1 ; /* zero is a "good" value, assume bad */
1657
1657
int report_end_of_input = 0 ;
1658
1658
@@ -1789,11 +1789,11 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1789
1789
if (show_stat )
1790
1790
obj_stat = xcalloc (st_add (nr_objects , 1 ), sizeof (struct object_stat ));
1791
1791
ofs_deltas = xcalloc (nr_objects , sizeof (struct ofs_delta_entry ));
1792
- parse_pack_objects (pack_sha1 );
1792
+ parse_pack_objects (pack_hash );
1793
1793
if (report_end_of_input )
1794
1794
write_in_full (2 , "\0" , 1 );
1795
1795
resolve_deltas ();
1796
- conclude_pack (fix_thin_pack , curr_pack , pack_sha1 );
1796
+ conclude_pack (fix_thin_pack , curr_pack , pack_hash );
1797
1797
free (ofs_deltas );
1798
1798
free (ref_deltas );
1799
1799
if (strict )
@@ -1805,14 +1805,14 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1805
1805
ALLOC_ARRAY (idx_objects , nr_objects );
1806
1806
for (i = 0 ; i < nr_objects ; i ++ )
1807
1807
idx_objects [i ] = & objects [i ].idx ;
1808
- curr_index = write_idx_file (index_name , idx_objects , nr_objects , & opts , pack_sha1 );
1808
+ curr_index = write_idx_file (index_name , idx_objects , nr_objects , & opts , pack_hash );
1809
1809
free (idx_objects );
1810
1810
1811
1811
if (!verify )
1812
1812
final (pack_name , curr_pack ,
1813
1813
index_name , curr_index ,
1814
1814
keep_msg , promisor_msg ,
1815
- pack_sha1 );
1815
+ pack_hash );
1816
1816
else
1817
1817
close (input_fd );
1818
1818
free (objects );
0 commit comments