@@ -141,6 +141,7 @@ pub mod rewrites {
141
141
142
142
use gix_diff:: tree:: visit:: Change ;
143
143
use gix_object:: tree:: { EntryKind , EntryMode } ;
144
+ use gix_object:: FindExt ;
144
145
145
146
use crate :: diff:: blob:: DiffLineStats ;
146
147
use crate :: diff:: { rewrites:: Tracker , Rewrites } ;
@@ -249,7 +250,7 @@ pub mod rewrites {
249
250
#[ allow( missing_docs) ]
250
251
pub enum Error {
251
252
#[ error( "Could not find blob for similarity checking" ) ]
252
- FindExistingBlob ( #[ source ] Box < dyn std :: error :: Error + Send + Sync > ) ,
253
+ FindExistingBlob ( #[ from ] gix_object :: find :: existing_object :: Error ) ,
253
254
#[ error( "Could not obtain exhaustive item set to use as possible sources for copy detection" ) ]
254
255
GetItemsForExhaustiveCopyDetection ( #[ source] Box < dyn std:: error:: Error + Send + Sync > ) ,
255
256
}
@@ -303,23 +304,20 @@ pub mod rewrites {
303
304
/// `cb(destination, source)` is called for each item, either with `Some(source)` if it's
304
305
/// the destination of a copy or rename, or with `None` for source if no relation to other
305
306
/// items in the tracked set exist.
306
- /// `find_blob(oid, buf) -> Result<BlobRef, E>` is used to access blob data for similarity checks
307
- /// if required with data and is taken directly from the object database. Worktree filters and diff conversions
308
- /// will be applied afterwards automatically.
307
+ /// `objects` is used to access blob data for similarity checks if required and is taken directly from the object database.
308
+ /// Worktree filters and diff conversions will be applied afterwards automatically.
309
309
/// `push_source_tree(push_fn: push(change, location))` is a function that is called when the entire tree of the source
310
310
/// should be added as modifications by calling `push` repeatedly to use for perfect copy tracking. Note that
311
311
/// `push` will panic if `change` is not a modification, and it's valid to not call `push` at all.
312
- pub fn emit < FindFn , E1 , PushSourceTreeFn , E2 > (
312
+ pub fn emit < PushSourceTreeFn , E > (
313
313
& mut self ,
314
314
mut cb : impl FnMut ( visit:: Destination < ' _ > , Option < visit:: Source < ' _ > > ) -> gix_diff:: tree:: visit:: Action ,
315
- mut find_blob : FindFn ,
315
+ objects : impl gix_object :: Find ,
316
316
mut push_source_tree : PushSourceTreeFn ,
317
317
) -> Result < Outcome , emit:: Error >
318
318
where
319
- FindFn : for < ' b > FnMut ( & gix_hash:: oid , & ' b mut Vec < u8 > ) -> Result < gix_object:: BlobRef < ' b > , E1 > ,
320
- PushSourceTreeFn : FnMut ( & mut dyn FnMut ( Change , & BStr ) ) -> Result < ( ) , E2 > ,
321
- E1 : std:: error:: Error + Send + Sync + ' static ,
322
- E2 : std:: error:: Error + Send + Sync + ' static ,
319
+ PushSourceTreeFn : FnMut ( & mut dyn FnMut ( Change , & BStr ) ) -> Result < ( ) , E > ,
320
+ E : std:: error:: Error + Send + Sync + ' static ,
323
321
{
324
322
fn by_id_and_location ( a : & Item , b : & Item ) -> std:: cmp:: Ordering {
325
323
a. change
@@ -338,7 +336,7 @@ pub mod rewrites {
338
336
& mut cb,
339
337
self . rewrites . percentage ,
340
338
out,
341
- & mut find_blob ,
339
+ & objects ,
342
340
) ?;
343
341
344
342
if let Some ( copies) = self . rewrites . copies {
@@ -347,7 +345,7 @@ pub mod rewrites {
347
345
& mut cb,
348
346
copies. percentage ,
349
347
out,
350
- & mut find_blob ,
348
+ & objects ,
351
349
) ?;
352
350
353
351
match copies. source {
@@ -369,7 +367,7 @@ pub mod rewrites {
369
367
& mut cb,
370
368
copies. percentage ,
371
369
out,
372
- & mut find_blob ,
370
+ & objects ,
373
371
) ?;
374
372
}
375
373
}
@@ -392,21 +390,17 @@ pub mod rewrites {
392
390
Ok ( out)
393
391
}
394
392
395
- fn match_pairs_of_kind < FindFn , E > (
393
+ fn match_pairs_of_kind (
396
394
& mut self ,
397
395
kind : visit:: Kind ,
398
396
cb : & mut impl FnMut ( visit:: Destination < ' _ > , Option < visit:: Source < ' _ > > ) -> gix_diff:: tree:: visit:: Action ,
399
397
percentage : Option < f32 > ,
400
398
mut out : Outcome ,
401
- mut find_blob : FindFn ,
402
- ) -> Result < Outcome , emit:: Error >
403
- where
404
- FindFn : for < ' b > FnMut ( & gix_hash:: oid , & ' b mut Vec < u8 > ) -> Result < gix_object:: BlobRef < ' b > , E > ,
405
- E : std:: error:: Error + Send + Sync + ' static ,
406
- {
399
+ objects : impl gix_object:: Find ,
400
+ ) -> Result < Outcome , emit:: Error > {
407
401
// we try to cheaply reduce the set of possibilities first, before possibly looking more exhaustively.
408
402
let needs_second_pass = !needs_exact_match ( percentage) ;
409
- if self . match_pairs ( cb, None /* by identity */ , kind, & mut out, & mut find_blob ) ?
403
+ if self . match_pairs ( cb, None /* by identity */ , kind, & mut out, & objects ) ?
410
404
== gix_diff:: tree:: visit:: Action :: Cancel
411
405
{
412
406
return Ok ( out) ;
@@ -428,24 +422,20 @@ pub mod rewrites {
428
422
false
429
423
} ;
430
424
if !is_limited {
431
- self . match_pairs ( cb, percentage, kind, & mut out, & mut find_blob ) ?;
425
+ self . match_pairs ( cb, percentage, kind, & mut out, & objects ) ?;
432
426
}
433
427
}
434
428
Ok ( out)
435
429
}
436
430
437
- fn match_pairs < FindFn , E > (
431
+ fn match_pairs (
438
432
& mut self ,
439
433
cb : & mut impl FnMut ( visit:: Destination < ' _ > , Option < visit:: Source < ' _ > > ) -> gix_diff:: tree:: visit:: Action ,
440
434
percentage : Option < f32 > ,
441
435
kind : visit:: Kind ,
442
436
stats : & mut Outcome ,
443
- mut find_blob : FindFn ,
444
- ) -> Result < gix_diff:: tree:: visit:: Action , emit:: Error >
445
- where
446
- FindFn : for < ' b > FnMut ( & gix_hash:: oid , & ' b mut Vec < u8 > ) -> Result < gix_object:: BlobRef < ' b > , E > ,
447
- E : std:: error:: Error + Send + Sync + ' static ,
448
- {
437
+ objects : impl gix_object:: Find ,
438
+ ) -> Result < gix_diff:: tree:: visit:: Action , emit:: Error > {
449
439
// TODO(perf): reuse object data and interner state and interned tokens, make these available to `find_match()`
450
440
let mut dest_ofs = 0 ;
451
441
while let Some ( ( mut dest_idx, dest) ) =
@@ -462,7 +452,7 @@ pub mod rewrites {
462
452
percentage. map ( |p| ( p, self . diff_algo ) ) ,
463
453
kind,
464
454
stats,
465
- & mut find_blob ,
455
+ & objects ,
466
456
& mut self . buf1 ,
467
457
& mut self . buf2 ,
468
458
) ?
@@ -543,20 +533,19 @@ pub mod rewrites {
543
533
/// Note that we always try to find by identity first even if a percentage is given as it's much faster and may reduce the set
544
534
/// of items to be searched.
545
535
#[ allow( clippy:: too_many_arguments) ]
546
- fn find_match < ' a , FindFn , E > (
536
+ fn find_match < ' a , Find > (
547
537
items : & ' a [ Item ] ,
548
538
item : & Item ,
549
539
item_idx : usize ,
550
540
percentage : Option < ( f32 , gix_diff:: blob:: Algorithm ) > ,
551
541
kind : visit:: Kind ,
552
542
stats : & mut Outcome ,
553
- mut find_worktree_blob : FindFn ,
543
+ objects : Find ,
554
544
buf1 : & mut Vec < u8 > ,
555
545
buf2 : & mut Vec < u8 > ,
556
546
) -> Result < Option < SourceTuple < ' a > > , emit:: Error >
557
547
where
558
- FindFn : for < ' b > FnMut ( & gix_hash:: oid , & ' b mut Vec < u8 > ) -> Result < gix_object:: BlobRef < ' b > , E > ,
559
- E : std:: error:: Error + Send + Sync + ' static ,
548
+ Find : gix_object:: Find ,
560
549
{
561
550
let ( item_id, item_mode) = item. change . oid_and_entry_mode ( ) ;
562
551
if needs_exact_match ( percentage. map ( |t| t. 0 ) ) || item_mode. is_link ( ) {
@@ -583,8 +572,7 @@ pub mod rewrites {
583
572
return Ok ( Some ( src) ) ;
584
573
}
585
574
} else {
586
- let new =
587
- find_worktree_blob ( item_id, buf1) . map_err ( |err| emit:: Error :: FindExistingBlob ( Box :: new ( err) ) ) ?;
575
+ let new = objects. find_blob ( item_id, buf1) ?;
588
576
let ( percentage, algo) = percentage. expect ( "it's set to something below 1.0 and we assured this" ) ;
589
577
debug_assert ! (
590
578
item. change. entry_mode( ) . is_blob( ) ,
@@ -595,8 +583,7 @@ pub mod rewrites {
595
583
. enumerate ( )
596
584
. filter ( |( src_idx, src) | * src_idx != item_idx && src. is_source_for_destination_of ( kind, item_mode) )
597
585
{
598
- let old = find_worktree_blob ( src. change . oid ( ) , buf2)
599
- . map_err ( |err| emit:: Error :: FindExistingBlob ( Box :: new ( err) ) ) ?;
586
+ let old = objects. find_blob ( src. change . oid ( ) , buf2) ?;
600
587
// TODO: make sure we get attribute handling and binary skips and filters right here. There is crate::object::blob::diff::Platform
601
588
// which should have facilities for that one day, but we don't use it because we need newlines in our tokens.
602
589
let tokens = gix_diff:: blob:: intern:: InternedInput :: new (
0 commit comments