@@ -81,6 +81,21 @@ pub mod diff {
81
81
ForEach ( #[ source] Box < dyn std:: error:: Error + Send + Sync + ' static > ) ,
82
82
}
83
83
84
+ /// Returned by the `for_each` function to control flow.
85
+ #[ derive( Clone , Copy , PartialOrd , PartialEq , Ord , Eq , Hash ) ]
86
+ pub enum Action {
87
+ /// Continue the traversal of changes.
88
+ Continue ,
89
+ /// Stop the traversal of changes and stop calling this function.
90
+ Cancel ,
91
+ }
92
+
93
+ impl Default for Action {
94
+ fn default ( ) -> Self {
95
+ Action :: Continue
96
+ }
97
+ }
98
+
84
99
/// Represents any possible change in order to turn one tree into another.
85
100
#[ derive( Debug , Clone , Copy ) ]
86
101
pub struct Change < ' a , ' repo , ' other_repo > {
@@ -164,7 +179,7 @@ pub mod diff {
164
179
pub fn for_each_to_obtain_tree < ' other_repo , E > (
165
180
& mut self ,
166
181
other : & Tree < ' other_repo > ,
167
- for_each : impl FnMut ( Change < ' _ , ' repo , ' other_repo > ) -> Result < git_diff :: tree :: visit :: Action , E > ,
182
+ for_each : impl FnMut ( Change < ' _ , ' repo , ' other_repo > ) -> Result < Action , E > ,
168
183
) -> Result < ( ) , Error >
169
184
where
170
185
E : std:: error:: Error + Sync + Send + ' static ,
@@ -202,8 +217,7 @@ pub mod diff {
202
217
203
218
impl < ' repo , ' other_repo , VisitFn , E > git_diff:: tree:: Visit for Delegate < ' repo , ' other_repo , VisitFn , E >
204
219
where
205
- VisitFn :
206
- for < ' delegate > FnMut ( Change < ' delegate , ' repo , ' other_repo > ) -> Result < git_diff:: tree:: visit:: Action , E > ,
220
+ VisitFn : for < ' delegate > FnMut ( Change < ' delegate , ' repo , ' other_repo > ) -> Result < Action , E > ,
207
221
E : std:: error:: Error + Sync + Send + ' static ,
208
222
{
209
223
fn pop_front_tracked_path_and_set_current ( & mut self ) { }
@@ -251,7 +265,8 @@ pub mod diff {
251
265
event,
252
266
location : self . location . as_ref ( ) ,
253
267
} ) {
254
- Ok ( action) => action,
268
+ Ok ( Action :: Cancel ) => git_diff:: tree:: visit:: Action :: Cancel ,
269
+ Ok ( Action :: Continue ) => git_diff:: tree:: visit:: Action :: Continue ,
255
270
Err ( err) => {
256
271
self . err = Some ( err) ;
257
272
git_diff:: tree:: visit:: Action :: Cancel
0 commit comments