@@ -398,15 +398,17 @@ pub mod decode {
398398 }
399399}
400400
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+
401407/// A function to compute a hash of kind `hash_kind` for an object of `object_kind` and its `data`.
402408#[ doc( alias = "hash_object" , alias = "git2" ) ]
403409pub 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 ) ;
408411 hasher. update ( data) ;
409-
410412 hasher. digest ( ) . into ( )
411413}
412414
@@ -423,9 +425,6 @@ pub fn compute_stream_hash(
423425 progress : & mut dyn gix_features:: progress:: Progress ,
424426 should_interrupt : & std:: sync:: atomic:: AtomicBool ,
425427) -> 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) ;
430429 gix_features:: hash:: bytes_with_hasher ( stream, stream_len, hasher, progress, should_interrupt)
431430}
0 commit comments