11use std:: collections:: HashSet ;
22
3- use bstr:: { BString , ByteVec } ;
3+ use bstr:: { BString , ByteSlice , ByteVec } ;
44use gix_features:: progress:: Progress ;
5+ use gix_refspec:: RefSpec ;
6+ use gix_transport:: client:: Capabilities ;
57
68#[ cfg( feature = "async-client" ) ]
79use crate :: transport:: client:: async_io:: Transport ;
810#[ cfg( feature = "blocking-client" ) ]
911use crate :: transport:: client:: blocking_io:: Transport ;
1012use crate :: {
11- fetch,
1213 fetch:: {
14+ self ,
1315 refmap:: { Mapping , Source , SpecIndex } ,
1416 RefMap ,
1517 } ,
18+ handshake:: Ref ,
1619} ;
1720
1821/// The error returned by [`RefMap::new()`].
@@ -78,8 +81,6 @@ impl RefMap {
7881 T : Transport ,
7982 {
8083 let _span = gix_trace:: coarse!( "gix_protocol::fetch::RefMap::new()" ) ;
81- let null = gix_hash:: ObjectId :: null ( gix_hash:: Kind :: Sha1 ) ; // OK to hardcode Sha1, it's not supposed to match, ever.
82-
8384 let all_refspecs = {
8485 let mut s: Vec < _ > = fetch_refspecs. to_vec ( ) ;
8586 s. extend ( extra_refspecs. clone ( ) ) ;
@@ -115,8 +116,26 @@ impl RefMap {
115116 . await ?
116117 }
117118 } ;
119+
120+ Self :: from_refs (
121+ remote_refs,
122+ & handshake. capabilities ,
123+ fetch_refspecs,
124+ all_refspecs,
125+ extra_refspecs,
126+ )
127+ }
128+
129+ fn from_refs (
130+ remote_refs : Vec < Ref > ,
131+ capabilities : & Capabilities ,
132+ fetch_refspecs : & [ RefSpec ] ,
133+ all_refspecs : Vec < RefSpec > ,
134+ extra_refspecs : Vec < RefSpec > ,
135+ ) -> Result < Self , Error > {
118136 let num_explicit_specs = fetch_refspecs. len ( ) ;
119137 let group = gix_refspec:: MatchGroup :: from_fetch_specs ( all_refspecs. iter ( ) . map ( gix_refspec:: RefSpec :: to_ref) ) ;
138+ let null = gix_hash:: ObjectId :: null ( gix_hash:: Kind :: Sha1 ) ; // OK to hardcode Sha1, it's not supposed to match, ever.
120139 let ( res, fixes) = group
121140 . match_lhs ( remote_refs. iter ( ) . map ( |r| {
122141 let ( full_ref_name, target, object) = r. unpack ( ) ;
@@ -150,24 +169,9 @@ impl RefMap {
150169 } )
151170 . collect ( ) ;
152171
153- let object_hash = extract_object_format ( handshake) ?;
154- Ok ( RefMap {
155- mappings,
156- refspecs : fetch_refspecs. to_vec ( ) ,
157- extra_refspecs,
158- fixes,
159- remote_refs,
160- object_hash,
161- } )
162- }
163- }
164-
165- /// Assume sha1 if server says nothing, otherwise configure anything beyond sha1 in the local repo configuration
166- #[ allow( clippy:: result_large_err) ]
167- fn extract_object_format ( outcome : & crate :: handshake:: Outcome ) -> Result < gix_hash:: Kind , Error > {
168- use bstr:: ByteSlice ;
169- let object_hash =
170- if let Some ( object_format) = outcome. capabilities . capability ( "object-format" ) . and_then ( |c| c. value ( ) ) {
172+ // Assume sha1 if server says nothing, otherwise configure anything beyond sha1 in the local repo configuration
173+ let object_hash = if let Some ( object_format) = capabilities. capability ( "object-format" ) . and_then ( |c| c. value ( ) )
174+ {
171175 let object_format = object_format. to_str ( ) . map_err ( |_| Error :: UnknownObjectFormat {
172176 format : object_format. into ( ) ,
173177 } ) ?;
@@ -178,5 +182,14 @@ fn extract_object_format(outcome: &crate::handshake::Outcome) -> Result<gix_hash
178182 } else {
179183 gix_hash:: Kind :: Sha1
180184 } ;
181- Ok ( object_hash)
185+
186+ Ok ( Self {
187+ mappings,
188+ refspecs : fetch_refspecs. to_vec ( ) ,
189+ extra_refspecs,
190+ fixes,
191+ remote_refs,
192+ object_hash,
193+ } )
194+ }
182195}
0 commit comments