@@ -79,34 +79,56 @@ pub(crate) mod hero {
7979 use gix_features:: progress:: Progress ;
8080 use std:: borrow:: Cow ;
8181
82- impl Handshake {
83- /// Obtain a [refmap](crate::fetch::RefMap) either from this instance, taking it out in the process, if the handshake was
84- /// created from a V1 connection, or use `transport` to fetch the refmap as a separate command invocation.
82+ pub enum FetchRefMap < ' a > {
83+ Map ( RefMap ) ,
84+ Command ( crate :: LsRefsCommand < ' a > , crate :: fetch:: refmap:: init:: Context ) ,
85+ }
86+
87+ impl FetchRefMap < ' _ > {
88+ /// Fetch the refmap, either by returning the existing one or invoking the command.
8589 #[ allow( clippy:: result_large_err) ]
8690 #[ maybe_async:: maybe_async]
87- pub async fn fetch_or_extract_refmap < T > (
88- & mut self ,
91+ pub async fn fetch (
92+ self ,
8993 mut progress : impl Progress ,
90- transport : & mut T ,
91- user_agent : ( & ' static str , Option < Cow < ' static , str > > ) ,
94+ transport : & mut impl Transport ,
9295 trace_packetlines : bool ,
96+ ) -> Result < crate :: fetch:: RefMap , crate :: fetch:: refmap:: init:: Error > {
97+ let ( cmd, cx) = match self {
98+ FetchRefMap :: Map ( map) => return Ok ( map) ,
99+ FetchRefMap :: Command ( cmd, cx) => ( cmd, cx) ,
100+ } ;
101+
102+ let capabilities = cmd. capabilities ;
103+ let remote_refs = cmd. invoke ( transport, & mut progress, trace_packetlines) . await ?;
104+ RefMap :: from_refs ( remote_refs, capabilities, cx)
105+ }
106+ }
107+
108+ impl Handshake {
109+ /// Prepare fetching a [refmap](crate::fetch::RefMap) if not present in the handshake.
110+ #[ allow( clippy:: result_large_err) ]
111+ pub fn fetch_or_extract_refmap (
112+ & mut self ,
113+ user_agent : ( & ' static str , Option < Cow < ' static , str > > ) ,
93114 prefix_from_spec_as_filter_on_remote : bool ,
94115 refmap_context : crate :: fetch:: refmap:: init:: Context ,
95- ) -> Result < crate :: fetch:: RefMap , crate :: fetch:: refmap:: init:: Error >
96- where
97- T : Transport ,
98- {
116+ ) -> Result < FetchRefMap < ' _ > , crate :: fetch:: refmap:: init:: Error > {
99117 if let Some ( refs) = self . refs . take ( ) {
100- return crate :: fetch:: RefMap :: from_refs ( refs, & self . capabilities , refmap_context) ;
118+ return Ok ( FetchRefMap :: Map ( crate :: fetch:: RefMap :: from_refs (
119+ refs,
120+ & self . capabilities ,
121+ refmap_context,
122+ ) ?) ) ;
101123 }
102124
103125 let _span = gix_trace:: coarse!( "gix_protocol::handshake::fetch_or_extract_refmap()" ) ;
104126 let all_refspecs = refmap_context. aggregate_refspecs ( ) ;
105127 let prefix_refspecs = prefix_from_spec_as_filter_on_remote. then_some ( & all_refspecs[ ..] ) ;
106- let remote_refs = crate :: LsRefsCommand :: new ( prefix_refspecs , & self . capabilities , user_agent )
107- . invoke ( transport , & mut progress , trace_packetlines )
108- . await ? ;
109- RefMap :: from_refs ( remote_refs , & self . capabilities , refmap_context )
128+ Ok ( FetchRefMap :: Command (
129+ crate :: LsRefsCommand :: new ( prefix_refspecs , & self . capabilities , user_agent ) ,
130+ refmap_context ,
131+ ) )
110132 }
111133 }
112134 }
@@ -146,6 +168,7 @@ mod error {
146168 }
147169 }
148170}
171+
149172#[ cfg( feature = "handshake" ) ]
150173pub use error:: Error ;
151174
0 commit comments