@@ -4,10 +4,9 @@ use gix_diff::blob::intern::TokenSource;
4
4
use gix_diff:: tree:: Visit ;
5
5
use gix_hash:: ObjectId ;
6
6
use gix_object:: {
7
- bstr:: { BStr , BString , ByteSlice , ByteVec } ,
7
+ bstr:: { BStr , BString } ,
8
8
FindExt ,
9
9
} ;
10
- use std:: collections:: VecDeque ;
11
10
use std:: num:: NonZeroU32 ;
12
11
use std:: ops:: Range ;
13
12
@@ -344,64 +343,45 @@ fn tree_diff_at_file_path(
344
343
// The name is preliminary and can potentially include more context. Also, this should probably be
345
344
// moved to its own location.
346
345
struct Recorder {
346
+ inner : gix_diff:: tree:: Recorder ,
347
347
interesting_path : BString ,
348
- path_deque : VecDeque < BString > ,
349
- path : BString ,
350
348
change : Option < gix_diff:: tree:: recorder:: Change > ,
351
349
}
352
350
353
351
impl Recorder {
354
352
fn new ( interesting_path : BString ) -> Self {
353
+ let inner = gix_diff:: tree:: Recorder :: default ( ) . track_location ( Some ( gix_diff:: tree:: recorder:: Location :: Path ) ) ;
354
+
355
355
Recorder {
356
+ inner,
356
357
interesting_path,
357
- path_deque : Default :: default ( ) ,
358
- path : Default :: default ( ) ,
359
358
change : None ,
360
359
}
361
360
}
362
-
363
- fn pop_element ( & mut self ) {
364
- if let Some ( pos) = self . path . rfind_byte ( b'/' ) {
365
- self . path . resize ( pos, 0 ) ;
366
- } else {
367
- self . path . clear ( ) ;
368
- }
369
- }
370
-
371
- fn push_element ( & mut self , name : & BStr ) {
372
- if name. is_empty ( ) {
373
- return ;
374
- }
375
- if !self . path . is_empty ( ) {
376
- self . path . push ( b'/' ) ;
377
- }
378
- self . path . push_str ( name) ;
379
- }
380
361
}
381
362
382
363
impl Visit for Recorder {
383
364
fn pop_front_tracked_path_and_set_current ( & mut self ) {
384
- self . path = self . path_deque . pop_front ( ) . expect ( "every parent is set only once" ) ;
365
+ self . inner . pop_front_tracked_path_and_set_current ( ) ;
385
366
}
386
367
387
368
fn push_back_tracked_path_component ( & mut self , component : & BStr ) {
388
- self . push_element ( component) ;
389
- self . path_deque . push_back ( self . path . clone ( ) ) ;
369
+ self . inner . push_back_tracked_path_component ( component) ;
390
370
}
391
371
392
372
fn push_path_component ( & mut self , component : & BStr ) {
393
- self . push_element ( component) ;
373
+ self . inner . push_path_component ( component) ;
394
374
}
395
375
396
376
fn pop_path_component ( & mut self ) {
397
- self . pop_element ( ) ;
377
+ self . inner . pop_path_component ( ) ;
398
378
}
399
379
400
380
fn visit ( & mut self , change : gix_diff:: tree:: visit:: Change ) -> gix_diff:: tree:: visit:: Action {
401
381
use gix_diff:: tree:: visit:: Action :: * ;
402
382
use gix_diff:: tree:: visit:: Change :: * ;
403
383
404
- if self . path == self . interesting_path {
384
+ if self . inner . path ( ) == self . interesting_path {
405
385
self . change = Some ( match change {
406
386
Deletion {
407
387
entry_mode,
@@ -410,7 +390,7 @@ impl Visit for Recorder {
410
390
} => gix_diff:: tree:: recorder:: Change :: Deletion {
411
391
entry_mode,
412
392
oid,
413
- path : self . path . clone ( ) ,
393
+ path : self . inner . path_clone ( ) ,
414
394
relation,
415
395
} ,
416
396
Addition {
@@ -420,7 +400,7 @@ impl Visit for Recorder {
420
400
} => gix_diff:: tree:: recorder:: Change :: Addition {
421
401
entry_mode,
422
402
oid,
423
- path : self . path . clone ( ) ,
403
+ path : self . inner . path_clone ( ) ,
424
404
relation,
425
405
} ,
426
406
Modification {
@@ -433,7 +413,7 @@ impl Visit for Recorder {
433
413
previous_oid,
434
414
entry_mode,
435
415
oid,
436
- path : self . path . clone ( ) ,
416
+ path : self . inner . path_clone ( ) ,
437
417
} ,
438
418
} ) ;
439
419
0 commit comments