@@ -65,7 +65,7 @@ impl<'repo> Tree<'repo> {
65
65
#[ allow( missing_docs) ]
66
66
///
67
67
pub mod diff {
68
- use crate :: bstr:: BStr ;
68
+ use crate :: bstr:: { BStr , BString } ;
69
69
use crate :: ext:: ObjectIdExt ;
70
70
use crate :: { Id , Repository , Tree } ;
71
71
use git_object:: TreeRefIter ;
@@ -83,6 +83,17 @@ pub mod diff {
83
83
84
84
/// Represents any possible change in order to turn one tree into another.
85
85
#[ derive( Debug , Clone , Copy ) ]
86
+ pub struct Change < ' a , ' repo , ' other_repo > {
87
+ /// The location of the file or directory described by `event`, if tracking was enabled.
88
+ ///
89
+ /// Otherwise this value is always an empty path.
90
+ pub location : & ' a BStr ,
91
+ /// The diff event itself to provide information about what would need to change.
92
+ pub event : Event < ' repo , ' other_repo > ,
93
+ }
94
+
95
+ /// An event emitted when finding differences between two trees.
96
+ #[ derive( Debug , Clone , Copy ) ]
86
97
pub enum Event < ' repo , ' other_repo > {
87
98
/// An entry was added, like the addition of a file or directory.
88
99
Addition {
@@ -135,7 +146,7 @@ pub mod diff {
135
146
pub fn for_each_to_obtain_tree < ' other_repo , E > (
136
147
& mut self ,
137
148
other : & Tree < ' other_repo > ,
138
- for_each : impl FnMut ( Event < ' repo , ' other_repo > ) -> Result < git_diff:: tree:: visit:: Action , E > ,
149
+ for_each : impl FnMut ( Change < ' _ , ' repo , ' other_repo > ) -> Result < git_diff:: tree:: visit:: Action , E > ,
139
150
) -> Result < ( ) , Error >
140
151
where
141
152
E : std:: error:: Error + Sync + Send + ' static ,
@@ -144,6 +155,7 @@ pub mod diff {
144
155
let mut delegate = Delegate {
145
156
repo : self . lhs . repo ,
146
157
other_repo : other. repo ,
158
+ location : BString :: default ( ) ,
147
159
visit : for_each,
148
160
err : None ,
149
161
} ;
@@ -163,13 +175,15 @@ pub mod diff {
163
175
struct Delegate < ' repo , ' other_repo , VisitFn , E > {
164
176
repo : & ' repo Repository ,
165
177
other_repo : & ' other_repo Repository ,
178
+ location : BString ,
166
179
visit : VisitFn ,
167
180
err : Option < E > ,
168
181
}
169
182
170
183
impl < ' repo , ' other_repo , VisitFn , E > git_diff:: tree:: Visit for Delegate < ' repo , ' other_repo , VisitFn , E >
171
184
where
172
- VisitFn : FnMut ( Event < ' repo , ' other_repo > ) -> Result < git_diff:: tree:: visit:: Action , E > ,
185
+ VisitFn :
186
+ for < ' delegate > FnMut ( Change < ' delegate , ' repo , ' other_repo > ) -> Result < git_diff:: tree:: visit:: Action , E > ,
173
187
E : std:: error:: Error + Sync + Send + ' static ,
174
188
{
175
189
fn pop_front_tracked_path_and_set_current ( & mut self ) { }
@@ -205,7 +219,10 @@ pub mod diff {
205
219
id : oid. attach ( self . other_repo ) ,
206
220
} ,
207
221
} ;
208
- match ( self . visit ) ( event) {
222
+ match ( self . visit ) ( Change {
223
+ event,
224
+ location : self . location . as_ref ( ) ,
225
+ } ) {
209
226
Ok ( action) => action,
210
227
Err ( err) => {
211
228
self . err = Some ( err) ;
0 commit comments