@@ -398,15 +398,17 @@ pub mod decode {
398
398
}
399
399
}
400
400
401
+ fn object_hasher ( hash_kind : gix_hash:: Kind , object_kind : Kind , object_size : u64 ) -> gix_features:: hash:: Hasher {
402
+ let mut hasher = gix_features:: hash:: hasher ( hash_kind) ;
403
+ hasher. update ( & encode:: loose_header ( object_kind, object_size) ) ;
404
+ hasher
405
+ }
406
+
401
407
/// A function to compute a hash of kind `hash_kind` for an object of `object_kind` and its `data`.
402
408
#[ doc( alias = "hash_object" , alias = "git2" ) ]
403
409
pub fn compute_hash ( hash_kind : gix_hash:: Kind , object_kind : Kind , data : & [ u8 ] ) -> gix_hash:: ObjectId {
404
- let header = encode:: loose_header ( object_kind, data. len ( ) as u64 ) ;
405
-
406
- let mut hasher = gix_features:: hash:: hasher ( hash_kind) ;
407
- hasher. update ( & header) ;
410
+ let mut hasher = object_hasher ( hash_kind, object_kind, data. len ( ) as u64 ) ;
408
411
hasher. update ( data) ;
409
-
410
412
hasher. digest ( ) . into ( )
411
413
}
412
414
@@ -423,9 +425,6 @@ pub fn compute_stream_hash(
423
425
progress : & mut dyn gix_features:: progress:: Progress ,
424
426
should_interrupt : & std:: sync:: atomic:: AtomicBool ,
425
427
) -> std:: io:: Result < gix_hash:: ObjectId > {
426
- let header = encode:: loose_header ( object_kind, stream_len) ;
427
- let mut hasher = gix_features:: hash:: hasher ( hash_kind) ;
428
-
429
- hasher. update ( & header) ;
428
+ let hasher = object_hasher ( hash_kind, object_kind, stream_len) ;
430
429
gix_features:: hash:: bytes_with_hasher ( stream, stream_len, hasher, progress, should_interrupt)
431
430
}
0 commit comments