@@ -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 , BString } ;
68
+ use crate :: bstr:: { BStr , BString , ByteVec } ;
69
69
use crate :: ext:: ObjectIdExt ;
70
70
use crate :: { Id , Repository , Tree } ;
71
71
use git_object:: TreeRefIter ;
@@ -131,13 +131,31 @@ pub mod diff {
131
131
Platform {
132
132
state : Default :: default ( ) ,
133
133
lhs : self ,
134
+ tracking : None ,
134
135
}
135
136
}
136
137
}
137
138
139
+ /// The diffing platform returned by [`Tree::changes()`].
140
+ #[ derive( Clone ) ]
138
141
pub struct Platform < ' a , ' repo > {
139
142
state : git_diff:: tree:: State ,
140
143
lhs : & ' a Tree < ' repo > ,
144
+ tracking : Option < Tracking > ,
145
+ }
146
+
147
+ #[ derive( Clone , Copy ) ]
148
+ enum Tracking {
149
+ FileName ,
150
+ }
151
+
152
+ /// Configuration
153
+ impl < ' a , ' repo > Platform < ' a , ' repo > {
154
+ /// Keep track of file-names, which makes the [`location`][Change::location] field usable with the filename of the changed item.
155
+ pub fn track_filename ( & mut self ) -> & mut Self {
156
+ self . tracking = Some ( Tracking :: FileName ) ;
157
+ self
158
+ }
141
159
}
142
160
143
161
/// Add the item to compare to.
@@ -155,6 +173,7 @@ pub mod diff {
155
173
let mut delegate = Delegate {
156
174
repo : self . lhs . repo ,
157
175
other_repo : other. repo ,
176
+ tracking : self . tracking ,
158
177
location : BString :: default ( ) ,
159
178
visit : for_each,
160
179
err : None ,
@@ -175,6 +194,7 @@ pub mod diff {
175
194
struct Delegate < ' repo , ' other_repo , VisitFn , E > {
176
195
repo : & ' repo Repository ,
177
196
other_repo : & ' other_repo Repository ,
197
+ tracking : Option < Tracking > ,
178
198
location : BString ,
179
199
visit : VisitFn ,
180
200
err : Option < E > ,
@@ -192,7 +212,15 @@ pub mod diff {
192
212
{ }
193
213
}
194
214
195
- fn push_path_component ( & mut self , _component : & BStr ) { }
215
+ fn push_path_component ( & mut self , component : & BStr ) {
216
+ match self . tracking {
217
+ Some ( Tracking :: FileName ) => {
218
+ self . location . clear ( ) ;
219
+ self . location . push_str ( component) ;
220
+ }
221
+ None => { }
222
+ }
223
+ }
196
224
197
225
fn pop_path_component ( & mut self ) { }
198
226
0 commit comments