@@ -45,15 +45,13 @@ impl StageOne {
4545 . map ( |version| Core :: REPOSITORY_FORMAT_VERSION . try_into_usize ( version) )
4646 . transpose ( ) ?
4747 . unwrap_or_default ( ) ;
48- let object_hash = ( repo_format_version != 1 )
49- . then_some ( Ok ( gix_hash:: Kind :: Sha1 ) )
50- . or_else ( || {
51- config
52- . string ( Extensions :: OBJECT_FORMAT )
53- . map ( |format| Extensions :: OBJECT_FORMAT . try_into_object_format ( format) )
54- } )
55- . transpose ( ) ?
56- . unwrap_or ( gix_hash:: Kind :: Sha1 ) ;
48+ let object_hash = match ( repo_format_version, config. string ( Extensions :: OBJECT_FORMAT ) ) {
49+ // objectFormat is a repository format version 1 extension.
50+ ( 1 , Some ( format) ) => Extensions :: OBJECT_FORMAT . try_into_object_format ( format) ?,
51+ ( 0 , Some ( _) ) => return Err ( Error :: ObjectFormatRequiresV1 ) ,
52+ ( 0 | 1 , None ) => legacy_object_hash ( ) ?,
53+ ( version, _) => return Err ( Error :: UnsupportedRepositoryFormatVersion { version } ) ,
54+ } ;
5755
5856 let extension_worktree = util:: config_bool (
5957 & config,
@@ -104,6 +102,22 @@ impl StageOne {
104102 }
105103}
106104
105+ /// Return the object hash for a repository that does not set `extensions.objectFormat`.
106+ ///
107+ /// Git interprets a missing objectFormat as the original Sha1 layout, so we return
108+ /// gix_hash::Kind::Sha1 whenever this build can handle it.
109+ /// In Sha256-only builds we cannot open such a repository, so return an error instead.
110+ fn legacy_object_hash ( ) -> Result < gix_hash:: Kind , Error > {
111+ #[ cfg( feature = "sha1" ) ]
112+ {
113+ Ok ( gix_hash:: Kind :: Sha1 )
114+ }
115+ #[ cfg( not( feature = "sha1" ) ) ]
116+ {
117+ Err ( Error :: UnsupportedObjectFormat { name : "sha1" . into ( ) } )
118+ }
119+ }
120+
107121fn load_config (
108122 config_path : std:: path:: PathBuf ,
109123 buf : & mut Vec < u8 > ,
0 commit comments