@@ -316,6 +316,15 @@ pub fn scripted_fixture_read_only(script_name: impl AsRef<Path>) -> Result<PathB
316316 scripted_fixture_read_only_with_args ( script_name, None :: < String > )
317317}
318318
319+ /// TODO:
320+ /// Document.
321+ pub fn scripted_fixture_for_hash_kind_read_only (
322+ hash_kind : gix_hash:: Kind ,
323+ script_name : impl AsRef < Path > ,
324+ ) -> Result < PathBuf > {
325+ scripted_fixture_for_hash_kind_read_only_with_args ( hash_kind, script_name, None :: < String > )
326+ }
327+
319328/// Like [`scripted_fixture_read_only`], but does not prefix the fixture directory with `tests`
320329pub fn scripted_fixture_read_only_standalone ( script_name : impl AsRef < Path > ) -> Result < PathBuf > {
321330 scripted_fixture_read_only_with_args_standalone ( script_name, None :: < String > )
@@ -424,6 +433,23 @@ pub fn scripted_fixture_read_only_with_args(
424433 scripted_fixture_read_only_with_args_inner ( script_name, args, None , DirectoryRoot :: IntegrationTest , ArgsInHash :: Yes )
425434}
426435
436+ /// TODO:
437+ /// Document.
438+ pub fn scripted_fixture_for_hash_kind_read_only_with_args (
439+ hash_kind : gix_hash:: Kind ,
440+ script_name : impl AsRef < Path > ,
441+ args : impl IntoIterator < Item = impl Into < String > > ,
442+ ) -> Result < PathBuf > {
443+ scripted_fixture_for_hash_kind_read_only_with_args_inner (
444+ hash_kind,
445+ script_name,
446+ args,
447+ None ,
448+ DirectoryRoot :: IntegrationTest ,
449+ ArgsInHash :: Yes ,
450+ )
451+ }
452+
427453/// Like `scripted_fixture_read_only()`], but passes `args` to `script_name`.
428454///
429455/// Also, don't add a suffix to the archive name as `args` are platform dependent, none-deterministic,
@@ -464,6 +490,24 @@ fn scripted_fixture_read_only_with_args_inner(
464490 destination_dir : Option < & Path > ,
465491 root : DirectoryRoot ,
466492 args_in_hash : ArgsInHash ,
493+ ) -> Result < PathBuf > {
494+ scripted_fixture_for_hash_kind_read_only_with_args_inner (
495+ gix_hash:: Kind :: Sha1 ,
496+ script_name,
497+ args,
498+ destination_dir,
499+ root,
500+ args_in_hash,
501+ )
502+ }
503+
504+ fn scripted_fixture_for_hash_kind_read_only_with_args_inner (
505+ hash_kind : gix_hash:: Kind ,
506+ script_name : impl AsRef < Path > ,
507+ args : impl IntoIterator < Item = impl Into < String > > ,
508+ destination_dir : Option < & Path > ,
509+ root : DirectoryRoot ,
510+ args_in_hash : ArgsInHash ,
467511) -> Result < PathBuf > {
468512 // Assure tempfiles get removed when aborting the test.
469513 gix_tempfile:: signal:: setup (
@@ -477,7 +521,12 @@ fn scripted_fixture_read_only_with_args_inner(
477521 let args: Vec < String > = args. into_iter ( ) . map ( Into :: into) . collect ( ) ;
478522 let script_identity = {
479523 let mut map = SCRIPT_IDENTITY . lock ( ) ;
480- map. entry ( args. iter ( ) . fold ( script_path. clone ( ) , |p, a| p. join ( a) ) )
524+ let init = if hash_kind == gix_hash:: Kind :: Sha1 {
525+ script_path. clone ( )
526+ } else {
527+ script_path. clone ( ) . join ( & hash_kind. to_string ( ) )
528+ } ;
529+ map. entry ( args. iter ( ) . fold ( init, |p, a| p. join ( a) ) )
481530 . or_insert_with ( || {
482531 let crc_value = crc:: Crc :: < u32 > :: new ( & crc:: CRC_32_CKSUM ) ;
483532 let mut crc_digest = crc_value. digest ( ) ;
@@ -509,8 +558,13 @@ fn scripted_fixture_read_only_with_args_inner(
509558 }
510559 ArgsInHash :: No => "" . into ( ) ,
511560 } ;
561+ let potential_hash_suffix = if hash_kind == gix_hash:: Kind :: Sha1 {
562+ "" . into ( )
563+ } else {
564+ format ! ( "_{}" , hash_kind. to_string( ) )
565+ } ;
512566 Path :: new ( "generated-archives" ) . join ( format ! (
513- "{}{suffix}.tar{}" ,
567+ "{}{suffix}{potential_hash_suffix} .tar{}" ,
514568 script_basename. to_str( ) . expect( "valid UTF-8" ) ,
515569 if cfg!( feature = "xz" ) { ".xz" } else { "" }
516570 ) )
@@ -519,14 +573,12 @@ fn scripted_fixture_read_only_with_args_inner(
519573 ) ;
520574 let ( force_run, script_result_directory) = destination_dir. map_or_else (
521575 || {
522- let dir = fixture_path_inner (
523- Path :: new ( "generated-do-not-edit" ) . join ( script_basename) . join ( format ! (
524- "{}-{}" ,
525- script_identity,
526- family_name( )
527- ) ) ,
528- root,
529- ) ;
576+ let mut path = Path :: new ( "generated-do-not-edit" ) . join ( script_basename) ;
577+ if hash_kind != gix_hash:: Kind :: Sha1 {
578+ path = path. join ( hash_kind. to_string ( ) ) ;
579+ } ;
580+ path = path. join ( format ! ( "{}-{}" , script_identity, family_name( ) ) ) ;
581+ let dir = fixture_path_inner ( path, root) ;
530582 ( false , dir)
531583 } ,
532584 |d| ( true , d. to_owned ( ) ) ,
@@ -588,13 +640,13 @@ fn scripted_fixture_read_only_with_args_inner(
588640 }
589641 let script_absolute_path = env:: current_dir ( ) ?. join ( script_path) ;
590642 let mut cmd = std:: process:: Command :: new ( & script_absolute_path) ;
591- let output = match configure_command ( & mut cmd, & args, & script_result_directory) . output ( ) {
643+ let output = match configure_command ( & mut cmd, hash_kind , & args, & script_result_directory) . output ( ) {
592644 Ok ( out) => out,
593645 Err ( err)
594646 if err. kind ( ) == std:: io:: ErrorKind :: PermissionDenied || err. raw_os_error ( ) == Some ( 193 ) /* windows */ =>
595647 {
596648 cmd = std:: process:: Command :: new ( bash_program ( ) ) ;
597- configure_command ( cmd. arg ( script_absolute_path) , & args, & script_result_directory) . output ( ) ?
649+ configure_command ( cmd. arg ( script_absolute_path) , hash_kind , & args, & script_result_directory) . output ( ) ?
598650 }
599651 Err ( err) => return Err ( err. into ( ) ) ,
600652 } ;
@@ -625,6 +677,7 @@ const NULL_DEVICE: &str = "/dev/null";
625677
626678fn configure_command < ' a , I : IntoIterator < Item = S > , S : AsRef < OsStr > > (
627679 cmd : & ' a mut std:: process:: Command ,
680+ hash_kind : gix_hash:: Kind ,
628681 args : I ,
629682 script_result_directory : & Path ,
630683) -> & ' a mut std:: process:: Command {
@@ -644,6 +697,7 @@ fn configure_command<'a, I: IntoIterator<Item = S>, S: AsRef<OsStr>>(
644697 . env_remove ( "GIT_WORK_TREE" )
645698 . env_remove ( "GIT_COMMON_DIR" )
646699 . env_remove ( "GIT_ASKPASS" )
700+ . env_remove ( "GIT_DEFAULT_HASH" )
647701 . env_remove ( "SSH_ASKPASS" )
648702 . env ( "MSYS" , msys_for_git_bash_on_windows)
649703 . env ( "GIT_CONFIG_NOSYSTEM" , "1" )
@@ -664,6 +718,7 @@ fn configure_command<'a, I: IntoIterator<Item = S>, S: AsRef<OsStr>>(
664718 . env ( "GIT_CONFIG_VALUE_2" , "main" )
665719 . env ( "GIT_CONFIG_KEY_3" , "protocol.file.allow" )
666720 . env ( "GIT_CONFIG_VALUE_3" , "always" )
721+ . env ( "GIT_DEFAULT_HASH" , hash_kind. to_string ( ) )
667722}
668723
669724/// Get the path attempted as a `bash` interpreter, for fixture scripts having no `#!` we can use.
@@ -1051,7 +1106,12 @@ mod tests {
10511106 let mut cmd = std:: process:: Command :: new ( GIT_PROGRAM ) ;
10521107 cmd. env ( "GIT_CONFIG_SYSTEM" , SCOPE_ENV_VALUE ) ;
10531108 cmd. env ( "GIT_CONFIG_GLOBAL" , SCOPE_ENV_VALUE ) ;
1054- configure_command ( & mut cmd, [ "config" , "-l" , "--show-origin" ] , temp. path ( ) ) ;
1109+ configure_command (
1110+ & mut cmd,
1111+ gix_hash:: Kind :: Sha1 ,
1112+ [ "config" , "-l" , "--show-origin" ] ,
1113+ temp. path ( ) ,
1114+ ) ;
10551115
10561116 let output = cmd. output ( ) . expect ( "can run git" ) ;
10571117 let lines: Vec < _ > = output
0 commit comments