@@ -7,10 +7,10 @@ use std::fmt;
7
7
use std:: io:: Write ;
8
8
9
9
pub struct Arguments {
10
- base_features : Vec < String > ,
11
10
base_args : Vec < BString > ,
12
11
13
12
args : Vec < BString > ,
13
+ haves : Vec < BString > ,
14
14
15
15
filter : bool ,
16
16
shallow : bool ,
@@ -48,7 +48,7 @@ impl Arguments {
48
48
}
49
49
}
50
50
pub fn have ( & mut self , id : borrowed:: Id ) {
51
- self . prefixed ( "have " , id) ;
51
+ self . haves . push ( format ! ( "have {} " , id) . into ( ) ) ;
52
52
}
53
53
pub fn deepen ( & mut self , depth : usize ) {
54
54
assert ! ( self . shallow, "'shallow' feature required for deepen" ) ;
@@ -78,7 +78,7 @@ impl Arguments {
78
78
let mut deepen_since = shallow;
79
79
let mut deepen_not = shallow;
80
80
let mut deepen_relative = shallow;
81
- let ( initial_arguments, base_features , features_for_first_want) = match version {
81
+ let ( initial_arguments, features_for_first_want) = match version {
82
82
Protocol :: V1 => {
83
83
deepen_since = has ( "deepen-since" ) ;
84
84
deepen_not = has ( "deepen-not" ) ;
@@ -90,15 +90,15 @@ impl Arguments {
90
90
None => n. to_string ( ) ,
91
91
} )
92
92
. collect :: < Vec < _ > > ( ) ;
93
- ( Vec :: new ( ) , baked_features . clone ( ) , Some ( baked_features) )
93
+ ( Vec :: new ( ) , Some ( baked_features) )
94
94
}
95
- Protocol :: V2 => ( Command :: Fetch . initial_arguments ( & features) , Vec :: new ( ) , None ) ,
95
+ Protocol :: V2 => ( Command :: Fetch . initial_arguments ( & features) , None ) ,
96
96
} ;
97
97
98
98
Arguments {
99
- base_features,
100
99
base_args : initial_arguments. clone ( ) ,
101
100
args : initial_arguments,
101
+ haves : Vec :: new ( ) ,
102
102
filter,
103
103
shallow,
104
104
deepen_not,
@@ -121,17 +121,24 @@ impl Arguments {
121
121
}
122
122
match version {
123
123
git_transport:: Protocol :: V1 => {
124
- let mut on_drop = vec ! [ client:: MessageKind :: Flush ] ;
125
- if add_done_argument {
126
- on_drop. push ( client:: MessageKind :: Text ( & b"done" [ ..] ) ) ;
127
- }
124
+ let mut on_drop = if add_done_argument {
125
+ vec ! [ client:: MessageKind :: Text ( & b"done" [ ..] ) ]
126
+ } else {
127
+ vec ! [ client:: MessageKind :: Flush ]
128
+ } ;
129
+ let is_stateful = transport. is_stateful ( ) ;
130
+ let retained_state = if is_stateful { None } else { Some ( self . args . clone ( ) ) } ;
128
131
let mut line_writer = transport. request ( client:: WriteMode :: OneLFTerminatedLinePerWriteCall , on_drop) ?;
132
+
129
133
for arg in self . args . drain ( ..) {
130
134
line_writer. write_all ( & arg) ?;
131
135
}
132
- if !is_done {
133
- // re-install features for the next round
134
- self . features_for_first_want = Some ( self . base_features . clone ( ) ) ;
136
+ line_writer. write_message ( client:: MessageKind :: Flush ) ?;
137
+ for line in self . haves . drain ( ..) {
138
+ line_writer. write_all ( & line) ?;
139
+ }
140
+ if let Some ( next_args) = retained_state {
141
+ self . args = next_args;
135
142
}
136
143
Ok ( line_writer. into_read ( ) )
137
144
}
0 commit comments