@@ -50,7 +50,7 @@ void hashflush(struct hashfile *f)
5050
5151 if (offset ) {
5252 if (!f -> skip_hash )
53- the_hash_algo -> unsafe_update_fn (& f -> ctx , f -> buffer , offset );
53+ f -> algop -> update_fn (& f -> ctx , f -> buffer , offset );
5454 flush (f , f -> buffer , offset );
5555 f -> offset = 0 ;
5656 }
@@ -71,14 +71,14 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result,
7171 hashflush (f );
7272
7373 if (f -> skip_hash )
74- hashclr (f -> buffer , the_repository -> hash_algo );
74+ hashclr (f -> buffer , f -> algop );
7575 else
76- the_hash_algo -> unsafe_final_fn (f -> buffer , & f -> ctx );
76+ f -> algop -> final_fn (f -> buffer , & f -> ctx );
7777
7878 if (result )
79- hashcpy (result , f -> buffer , the_repository -> hash_algo );
79+ hashcpy (result , f -> buffer , f -> algop );
8080 if (flags & CSUM_HASH_IN_STREAM )
81- flush (f , f -> buffer , the_hash_algo -> rawsz );
81+ flush (f , f -> buffer , f -> algop -> rawsz );
8282 if (flags & CSUM_FSYNC )
8383 fsync_component_or_die (component , f -> fd , f -> name );
8484 if (flags & CSUM_CLOSE ) {
@@ -128,7 +128,7 @@ void hashwrite(struct hashfile *f, const void *buf, unsigned int count)
128128 * f->offset is necessarily zero.
129129 */
130130 if (!f -> skip_hash )
131- the_hash_algo -> unsafe_update_fn (& f -> ctx , buf , nr );
131+ f -> algop -> update_fn (& f -> ctx , buf , nr );
132132 flush (f , buf , nr );
133133 } else {
134134 /*
@@ -174,7 +174,9 @@ static struct hashfile *hashfd_internal(int fd, const char *name,
174174 f -> name = name ;
175175 f -> do_crc = 0 ;
176176 f -> skip_hash = 0 ;
177- the_hash_algo -> unsafe_init_fn (& f -> ctx );
177+
178+ f -> algop = unsafe_hash_algo (the_hash_algo );
179+ f -> algop -> init_fn (& f -> ctx );
178180
179181 f -> buffer_len = buffer_len ;
180182 f -> buffer = xmalloc (buffer_len );
@@ -204,11 +206,18 @@ struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp
204206 return hashfd_internal (fd , name , tp , 8 * 1024 );
205207}
206208
209+ void hashfile_checkpoint_init (struct hashfile * f ,
210+ struct hashfile_checkpoint * checkpoint )
211+ {
212+ memset (checkpoint , 0 , sizeof (* checkpoint ));
213+ f -> algop -> init_fn (& checkpoint -> ctx );
214+ }
215+
207216void hashfile_checkpoint (struct hashfile * f , struct hashfile_checkpoint * checkpoint )
208217{
209218 hashflush (f );
210219 checkpoint -> offset = f -> total ;
211- the_hash_algo -> unsafe_clone_fn (& checkpoint -> ctx , & f -> ctx );
220+ f -> algop -> clone_fn (& checkpoint -> ctx , & f -> ctx );
212221}
213222
214223int hashfile_truncate (struct hashfile * f , struct hashfile_checkpoint * checkpoint )
@@ -219,7 +228,7 @@ int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint
219228 lseek (f -> fd , offset , SEEK_SET ) != offset )
220229 return -1 ;
221230 f -> total = offset ;
222- the_hash_algo -> unsafe_clone_fn (& f -> ctx , & checkpoint -> ctx );
231+ f -> algop -> clone_fn (& f -> ctx , & checkpoint -> ctx );
223232 f -> offset = 0 ; /* hashflush() was called in checkpoint */
224233 return 0 ;
225234}
@@ -240,14 +249,15 @@ int hashfile_checksum_valid(const unsigned char *data, size_t total_len)
240249{
241250 unsigned char got [GIT_MAX_RAWSZ ];
242251 git_hash_ctx ctx ;
243- size_t data_len = total_len - the_hash_algo -> rawsz ;
252+ const struct git_hash_algo * algop = unsafe_hash_algo (the_hash_algo );
253+ size_t data_len = total_len - algop -> rawsz ;
244254
245- if (total_len < the_hash_algo -> rawsz )
255+ if (total_len < algop -> rawsz )
246256 return 0 ; /* say "too short"? */
247257
248- the_hash_algo -> unsafe_init_fn (& ctx );
249- the_hash_algo -> unsafe_update_fn (& ctx , data , data_len );
250- the_hash_algo -> unsafe_final_fn (got , & ctx );
258+ algop -> init_fn (& ctx );
259+ algop -> update_fn (& ctx , data , data_len );
260+ algop -> final_fn (got , & ctx );
251261
252- return hasheq (got , data + data_len , the_repository -> hash_algo );
262+ return hasheq (got , data + data_len , algop );
253263}
0 commit comments