@@ -12,7 +12,7 @@ use gix_pack::data::{
1212
1313use crate :: pack:: {
1414 data:: output:: { DbKind , db} ,
15- hex_to_id,
15+ hex_to_id, hex_to_id_for_hash , object_hash ,
1616} ;
1717
1818#[ test]
@@ -64,12 +64,25 @@ fn traversals() -> crate::Result {
6464 }
6565 }
6666 }
67+ let object_hash = object_hash ( ) ;
6768 let whole_pack = Count {
68- trees : 21 ,
69+ trees : match object_hash {
70+ gix_hash:: Kind :: Sha1 => 21 ,
71+ gix_hash:: Kind :: Sha256 => 20 ,
72+ _ => unimplemented ! ( ) ,
73+ } ,
6974 commits : 16 ,
70- blobs : 288 ,
75+ blobs : match object_hash {
76+ gix_hash:: Kind :: Sha1 => 288 ,
77+ gix_hash:: Kind :: Sha256 => 323 ,
78+ _ => unimplemented ! ( ) ,
79+ } ,
7180 tags : 1 ,
72- delta_ref : 542 ,
81+ delta_ref : match object_hash {
82+ gix_hash:: Kind :: Sha1 => 542 ,
83+ gix_hash:: Kind :: Sha256 => 508 ,
84+ _ => unimplemented ! ( ) ,
85+ } ,
7386 delta_oid : 0 , // these are basically none-existing in non-legacy packs, but are used only in thin packs on the wire
7487 } ;
7588 let whole_pack_obj_count = ObjectCount {
@@ -82,7 +95,7 @@ fn traversals() -> crate::Result {
8295 DbKind :: DeterministicGeneratedContent ,
8396 DbKind :: DeterministicGeneratedContentMultiIndex ,
8497 ] {
85- let db = db ( db_kind) ?;
98+ let db = db ( db_kind, object_hash ) ?;
8699 for (
87100 expansion_mode,
88101 expected_count,
@@ -132,10 +145,18 @@ fn traversals() -> crate::Result {
132145 Count {
133146 trees : 3 ,
134147 commits : 2 , // todo: why more?
135- blobs : 19 ,
148+ blobs : match object_hash {
149+ gix_hash:: Kind :: Sha1 => 19 ,
150+ gix_hash:: Kind :: Sha256 => 22 ,
151+ _ => unimplemented ! ( ) ,
152+ } ,
136153 tags : 0 ,
137154 delta_ref : 5 ,
138- delta_oid : 74 ,
155+ delta_oid : match object_hash {
156+ gix_hash:: Kind :: Sha1 => 74 ,
157+ gix_hash:: Kind :: Sha256 => 71 ,
158+ _ => unimplemented ! ( ) ,
159+ } ,
139160 } ,
140161 ObjectCount {
141162 trees : 5 ,
@@ -153,7 +174,11 @@ fn traversals() -> crate::Result {
153174 decoded_and_recompressed_objects : 0 ,
154175 missing_objects : 0 ,
155176 objects_copied_from_pack : 103 ,
156- ref_delta_objects : 74 ,
177+ ref_delta_objects : match object_hash {
178+ gix_hash:: Kind :: Sha1 => 74 ,
179+ gix_hash:: Kind :: Sha256 => 71 ,
180+ _ => unimplemented ! ( ) ,
181+ } ,
157182 } ,
158183 hex_to_id ( "25114bd8820b393c402cd53ad8ec7f6a84bb0633" ) ,
159184 Some ( hex_to_id ( "29ab9797aff1ca826afb699680356695d19c5acb" ) ) ,
@@ -183,9 +208,17 @@ fn traversals() -> crate::Result {
183208 total_objects : 103 ,
184209 } ,
185210 output:: entry:: iter_from_counts:: Outcome {
186- decoded_and_recompressed_objects : 74 ,
211+ decoded_and_recompressed_objects : match object_hash {
212+ gix_hash:: Kind :: Sha1 => 74 ,
213+ gix_hash:: Kind :: Sha256 => 71 ,
214+ _ => unimplemented ! ( ) ,
215+ } ,
187216 missing_objects : 0 ,
188- objects_copied_from_pack : 29 ,
217+ objects_copied_from_pack : match object_hash {
218+ gix_hash:: Kind :: Sha1 => 29 ,
219+ gix_hash:: Kind :: Sha256 => 32 ,
220+ _ => unimplemented ! ( ) ,
221+ } ,
189222 ref_delta_objects : 0 ,
190223 } ,
191224 hex_to_id ( "d83d42128e40957c5174920189a0390b5a70f446" ) ,
@@ -239,13 +272,17 @@ fn traversals() -> crate::Result {
239272 . iter ( )
240273 . copied ( )
241274 {
242- let head = hex_to_id ( "dfcb5e39ac6eb30179808bbab721e8a28ce1b52e" ) ;
275+ let head = hex_to_id_for_hash (
276+ object_hash,
277+ "dfcb5e39ac6eb30179808bbab721e8a28ce1b52e" ,
278+ "ad454f92f046c2873aebac2686d30d5b100ee10fae1a28e2994df52a0c097cae" ,
279+ ) ;
243280 let mut commits = gix_traverse:: commit:: Simple :: new ( Some ( head) , db. clone ( ) )
244281 . map ( Result :: unwrap)
245282 . map ( |c| c. id )
246283 . collect :: < Vec < _ > > ( ) ;
247284 if let Some ( take) = take {
248- commits. resize ( take, gix_hash :: Kind :: Sha1 . null ( ) ) ;
285+ commits. resize ( take, object_hash . null ( ) ) ;
249286 }
250287
251288 let deterministic_count_needs_single_thread = Some ( 1 ) ;
@@ -254,11 +291,15 @@ fn traversals() -> crate::Result {
254291 Box :: new (
255292 commits
256293 . into_iter ( )
257- . chain ( std:: iter:: once ( hex_to_id ( if take. is_some ( ) {
258- "0000000000000000000000000000000000000000"
294+ . chain ( std:: iter:: once ( if take. is_some ( ) {
295+ object_hash . null ( )
259296 } else {
260- "e3fb53cbb4c346d48732a24f09cf445e49bc63d6"
261- } ) ) )
297+ hex_to_id_for_hash (
298+ object_hash,
299+ "e3fb53cbb4c346d48732a24f09cf445e49bc63d6" ,
300+ "859b1fd3fd3cc6a0a016edc9f439afd33f87e524dc1fd2befd1ac550953d3b3b" ,
301+ )
302+ } ) )
262303 . filter ( |o| !o. is_null ( ) )
263304 . map ( Ok ) ,
264305 ) ,
@@ -313,7 +354,13 @@ fn traversals() -> crate::Result {
313354 "two different ways of counting, still the same in the end"
314355 ) ;
315356
316- write_and_verify ( db. clone ( ) , entries, expected_pack_hash, expected_thin_pack_hash) ?;
357+ write_and_verify (
358+ db. clone ( ) ,
359+ entries,
360+ object_hash,
361+ expected_pack_hash,
362+ expected_thin_pack_hash,
363+ ) ?;
317364 }
318365 }
319366
@@ -324,8 +371,9 @@ fn traversals() -> crate::Result {
324371fn empty_pack_is_allowed ( ) {
325372 assert_eq ! (
326373 write_and_verify(
327- db( DbKind :: DeterministicGeneratedContent ) . unwrap( ) ,
374+ db( DbKind :: DeterministicGeneratedContent , object_hash ( ) ) . unwrap( ) ,
328375 vec![ ] ,
376+ object_hash( ) ,
329377 hex_to_id( "029d08823bd8a8eab510ad6ac75c823cfd3ed31e" ) ,
330378 None ,
331379 )
@@ -339,6 +387,7 @@ fn empty_pack_is_allowed() {
339387fn write_and_verify (
340388 db : gix_odb:: HandleArc ,
341389 entries : Vec < output:: Entry > ,
390+ object_hash : gix_hash:: Kind ,
342391 _expected_pack_hash : gix_hash:: ObjectId ,
343392 _expected_thin_pack_hash : Option < gix_hash:: ObjectId > ,
344393) -> crate :: Result {
@@ -355,7 +404,7 @@ fn write_and_verify(
355404 & mut pack_file,
356405 num_entries as u32 ,
357406 pack:: data:: Version :: V2 ,
358- gix_hash :: Kind :: Sha1 ,
407+ object_hash ,
359408 ) ;
360409 let mut n = pack_writer. next ( ) . expect ( "one entries bundle was written" ) ?;
361410 n += pack_writer. next ( ) . expect ( "the trailer was written" ) ?;
@@ -374,7 +423,7 @@ fn write_and_verify(
374423 pack_file. metadata( ) ?. len( ) ,
375424 "it reports the correct amount of written bytes"
376425 ) ;
377- let pack = pack:: data:: File :: at ( & pack_file_path, gix_hash :: Kind :: Sha1 ) ?;
426+ let pack = pack:: data:: File :: at ( & pack_file_path, object_hash ) ?;
378427 let should_interrupt = AtomicBool :: new ( false ) ;
379428 let hash = pack. verify_checksum ( & mut progress:: Discard , & should_interrupt) ?;
380429 assert_eq ! (
@@ -386,15 +435,17 @@ fn write_and_verify(
386435 // assert_eq!(hash, expected_pack_hash, "pack hashes are stable if the input is");
387436
388437 // Re-generate the index from the pack for validation.
389- let object_hash = gix_hash:: Kind :: Sha1 ; // TODO: parameterize this
390438 let bundle = pack:: Bundle :: at (
391439 pack:: Bundle :: write_to_directory (
392440 & mut std:: io:: BufReader :: new ( std:: fs:: File :: open ( pack_file_path) ?) ,
393441 Some ( tmp_dir. path ( ) ) ,
394442 & mut progress:: Discard ,
395443 & should_interrupt,
396444 Some ( & db) ,
397- pack:: bundle:: write:: Options :: default ( ) ,
445+ pack:: bundle:: write:: Options {
446+ object_hash,
447+ ..Default :: default ( )
448+ } ,
398449 ) ?
399450 . data_path
400451 . ok_or ( "pack data directory should be set" ) ?,
0 commit comments