@@ -122,7 +122,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
122
122
uint32_t offset = htonl (obj -> offset );
123
123
sha1write (f , & offset , 4 );
124
124
}
125
- sha1write (f , obj -> oid .hash , 20 );
125
+ sha1write (f , obj -> oid .hash , the_hash_algo -> rawsz );
126
126
if ((opts -> flags & WRITE_IDX_STRICT ) &&
127
127
(i && !oidcmp (& list [-2 ]-> oid , & obj -> oid )))
128
128
die ("The same object %s appears twice in the pack" ,
@@ -169,7 +169,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
169
169
}
170
170
}
171
171
172
- sha1write (f , sha1 , 20 );
172
+ sha1write (f , sha1 , the_hash_algo -> rawsz );
173
173
sha1close (f , NULL , ((opts -> flags & WRITE_IDX_VERIFY )
174
174
? CSUM_CLOSE : CSUM_FSYNC ));
175
175
return index_name ;
@@ -203,20 +203,20 @@ off_t write_pack_header(struct sha1file *f, uint32_t nr_entries)
203
203
* interested in the resulting SHA1 of pack data above partial_pack_offset.
204
204
*/
205
205
void fixup_pack_header_footer (int pack_fd ,
206
- unsigned char * new_pack_sha1 ,
206
+ unsigned char * new_pack_hash ,
207
207
const char * pack_name ,
208
208
uint32_t object_count ,
209
- unsigned char * partial_pack_sha1 ,
209
+ unsigned char * partial_pack_hash ,
210
210
off_t partial_pack_offset )
211
211
{
212
212
int aligned_sz , buf_sz = 8 * 1024 ;
213
- git_SHA_CTX old_sha1_ctx , new_sha1_ctx ;
213
+ git_hash_ctx old_hash_ctx , new_hash_ctx ;
214
214
struct pack_header hdr ;
215
215
char * buf ;
216
216
ssize_t read_result ;
217
217
218
- git_SHA1_Init ( & old_sha1_ctx );
219
- git_SHA1_Init ( & new_sha1_ctx );
218
+ the_hash_algo -> init_fn ( & old_hash_ctx );
219
+ the_hash_algo -> init_fn ( & new_hash_ctx );
220
220
221
221
if (lseek (pack_fd , 0 , SEEK_SET ) != 0 )
222
222
die_errno ("Failed seeking to start of '%s'" , pack_name );
@@ -228,62 +228,63 @@ void fixup_pack_header_footer(int pack_fd,
228
228
pack_name );
229
229
if (lseek (pack_fd , 0 , SEEK_SET ) != 0 )
230
230
die_errno ("Failed seeking to start of '%s'" , pack_name );
231
- git_SHA1_Update ( & old_sha1_ctx , & hdr , sizeof (hdr ));
231
+ the_hash_algo -> update_fn ( & old_hash_ctx , & hdr , sizeof (hdr ));
232
232
hdr .hdr_entries = htonl (object_count );
233
- git_SHA1_Update ( & new_sha1_ctx , & hdr , sizeof (hdr ));
233
+ the_hash_algo -> update_fn ( & new_hash_ctx , & hdr , sizeof (hdr ));
234
234
write_or_die (pack_fd , & hdr , sizeof (hdr ));
235
235
partial_pack_offset -= sizeof (hdr );
236
236
237
237
buf = xmalloc (buf_sz );
238
238
aligned_sz = buf_sz - sizeof (hdr );
239
239
for (;;) {
240
240
ssize_t m , n ;
241
- m = (partial_pack_sha1 && partial_pack_offset < aligned_sz ) ?
241
+ m = (partial_pack_hash && partial_pack_offset < aligned_sz ) ?
242
242
partial_pack_offset : aligned_sz ;
243
243
n = xread (pack_fd , buf , m );
244
244
if (!n )
245
245
break ;
246
246
if (n < 0 )
247
247
die_errno ("Failed to checksum '%s'" , pack_name );
248
- git_SHA1_Update ( & new_sha1_ctx , buf , n );
248
+ the_hash_algo -> update_fn ( & new_hash_ctx , buf , n );
249
249
250
250
aligned_sz -= n ;
251
251
if (!aligned_sz )
252
252
aligned_sz = buf_sz ;
253
253
254
- if (!partial_pack_sha1 )
254
+ if (!partial_pack_hash )
255
255
continue ;
256
256
257
- git_SHA1_Update ( & old_sha1_ctx , buf , n );
257
+ the_hash_algo -> update_fn ( & old_hash_ctx , buf , n );
258
258
partial_pack_offset -= n ;
259
259
if (partial_pack_offset == 0 ) {
260
- unsigned char sha1 [ 20 ];
261
- git_SHA1_Final ( sha1 , & old_sha1_ctx );
262
- if (hashcmp (sha1 , partial_pack_sha1 ) != 0 )
260
+ unsigned char hash [ GIT_MAX_RAWSZ ];
261
+ the_hash_algo -> final_fn ( hash , & old_hash_ctx );
262
+ if (hashcmp (hash , partial_pack_hash ) != 0 )
263
263
die ("Unexpected checksum for %s "
264
264
"(disk corruption?)" , pack_name );
265
265
/*
266
266
* Now let's compute the SHA1 of the remainder of the
267
267
* pack, which also means making partial_pack_offset
268
268
* big enough not to matter anymore.
269
269
*/
270
- git_SHA1_Init ( & old_sha1_ctx );
270
+ the_hash_algo -> init_fn ( & old_hash_ctx );
271
271
partial_pack_offset = ~partial_pack_offset ;
272
272
partial_pack_offset -= MSB (partial_pack_offset , 1 );
273
273
}
274
274
}
275
275
free (buf );
276
276
277
- if (partial_pack_sha1 )
278
- git_SHA1_Final ( partial_pack_sha1 , & old_sha1_ctx );
279
- git_SHA1_Final ( new_pack_sha1 , & new_sha1_ctx );
280
- write_or_die (pack_fd , new_pack_sha1 , 20 );
277
+ if (partial_pack_hash )
278
+ the_hash_algo -> final_fn ( partial_pack_hash , & old_hash_ctx );
279
+ the_hash_algo -> final_fn ( new_pack_hash , & new_hash_ctx );
280
+ write_or_die (pack_fd , new_pack_hash , the_hash_algo -> rawsz );
281
281
fsync_or_die (pack_fd , pack_name );
282
282
}
283
283
284
284
char * index_pack_lockfile (int ip_out )
285
285
{
286
- char packname [46 ];
286
+ char packname [GIT_MAX_HEXSZ + 6 ];
287
+ const int len = the_hash_algo -> hexsz + 6 ;
287
288
288
289
/*
289
290
* The first thing we expect from index-pack's output
@@ -292,9 +293,9 @@ char *index_pack_lockfile(int ip_out)
292
293
* case, we need it to remove the corresponding .keep file
293
294
* later on. If we don't get that then tough luck with it.
294
295
*/
295
- if (read_in_full (ip_out , packname , 46 ) == 46 && packname [45 ] == '\n' ) {
296
+ if (read_in_full (ip_out , packname , len ) == len && packname [len - 1 ] == '\n' ) {
296
297
const char * name ;
297
- packname [45 ] = 0 ;
298
+ packname [len - 1 ] = 0 ;
298
299
if (skip_prefix (packname , "keep\t" , & name ))
299
300
return xstrfmt ("%s/pack/pack-%s.keep" ,
300
301
get_object_directory (), name );
0 commit comments