1+ /// What to do after preparing ls-refs.
2+ #[ derive( PartialEq , Eq , Debug , Hash , Ord , PartialOrd , Clone ) ]
3+ pub enum RefsAction {
4+ /// Continue by sending a 'ls-refs' command.
5+ Continue ,
6+ /// Skip 'ls-refs' entirely.
7+ ///
8+ /// This is useful if the `ref-in-want` capability is taken advantage of. When fetching, one
9+ /// must then send `want-ref`s during the negotiation phase.
10+ Skip ,
11+ }
12+
113mod fetch_fn {
214 use std:: borrow:: Cow ;
315
@@ -13,7 +25,7 @@ mod fetch_fn {
1325 use gix_transport:: client:: blocking_io:: { ExtendedBufRead , HandleProgress , Transport } ;
1426 use maybe_async:: maybe_async;
1527
16- use super :: { Action , Delegate } ;
28+ use super :: { Action , Delegate , RefsAction } ;
1729 use crate :: fetch:: Error ;
1830
1931 /// A way to indicate how to treat the connection underlying the transport, potentially allowing to reuse it.
@@ -91,18 +103,24 @@ mod fetch_fn {
91103 let agent = gix_protocol:: agent ( agent) ;
92104 let refs = match refs {
93105 Some ( refs) => refs,
94- None => {
95- gix_protocol:: ls_refs (
96- & mut transport,
97- & capabilities,
98- |a| delegate. prepare_ls_refs ( a) ,
99- Vec :: new ( ) ,
100- & mut progress,
101- trace,
102- ( "agent" , Some ( Cow :: Owned ( agent. clone ( ) ) ) ) ,
103- )
104- . await ?
105- }
106+ None => match delegate. action ( ) {
107+ Ok ( RefsAction :: Skip ) => Vec :: new ( ) ,
108+ Ok ( RefsAction :: Continue ) => {
109+ gix_protocol:: ls_refs (
110+ & mut transport,
111+ & capabilities,
112+ Vec :: new ( ) ,
113+ & mut progress,
114+ trace,
115+ ( "agent" , Some ( Cow :: Owned ( agent. clone ( ) ) ) ) ,
116+ )
117+ . await ?
118+ }
119+ Err ( err) => {
120+ indicate_end_of_interaction ( transport, trace) . await ?;
121+ return Err ( err. into ( ) ) ;
122+ }
123+ } ,
106124 } ;
107125
108126 let fetch = Command :: Fetch ;
@@ -199,10 +217,11 @@ mod delegate {
199217 use gix_protocol:: {
200218 fetch:: { Arguments , Response } ,
201219 handshake:: Ref ,
202- ls_refs:: { self , RefsAction } ,
203220 } ;
204221 use gix_transport:: client:: Capabilities ;
205222
223+ use super :: RefsAction ;
224+
206225 /// Defines what to do next after certain [`Delegate`] operations.
207226 #[ derive( PartialEq , Eq , Debug , Hash , Ord , PartialOrd , Clone , Copy ) ]
208227 pub enum Action {
@@ -231,10 +250,10 @@ mod delegate {
231250 /// Note that some arguments are preset based on typical use, and `features` are preset to maximize options.
232251 /// The `server` capabilities can be used to see which additional capabilities the server supports as per the handshake which happened prior.
233252 ///
234- /// If the delegate returns [`ls_refs::Action ::Skip`], no `ls-refs` command is sent to the server.
253+ /// If the delegate returns [`RefsAction ::Skip`], no `ls-refs` command is sent to the server.
235254 ///
236255 /// Note that this is called only if we are using protocol version 2.
237- fn prepare_ls_refs ( & mut self , _server : & Capabilities ) -> std:: io:: Result < RefsAction > {
256+ fn action ( & mut self ) -> std:: io:: Result < RefsAction > {
238257 Ok ( RefsAction :: Continue )
239258 }
240259
@@ -299,8 +318,8 @@ mod delegate {
299318 self . deref ( ) . handshake_extra_parameters ( )
300319 }
301320
302- fn prepare_ls_refs ( & mut self , _server : & Capabilities ) -> io:: Result < RefsAction > {
303- self . deref_mut ( ) . prepare_ls_refs ( _server )
321+ fn action ( & mut self ) -> io:: Result < RefsAction > {
322+ self . deref_mut ( ) . action ( )
304323 }
305324
306325 fn prepare_fetch (
@@ -328,8 +347,8 @@ mod delegate {
328347 self . deref ( ) . handshake_extra_parameters ( )
329348 }
330349
331- fn prepare_ls_refs ( & mut self , _server : & Capabilities ) -> io:: Result < RefsAction > {
332- self . deref_mut ( ) . prepare_ls_refs ( _server )
350+ fn action ( & mut self ) -> io:: Result < RefsAction > {
351+ self . deref_mut ( ) . action ( )
333352 }
334353
335354 fn prepare_fetch (
0 commit comments