Skip to content

Commit 52b2859

Browse files
committed
adapt to changes in gix related rename tracking
1 parent e1f5825 commit 52b2859

File tree

3 files changed

+30
-44
lines changed

3 files changed

+30
-44
lines changed

gitoxide-core/src/query/engine/update.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use anyhow::{anyhow, bail};
99
use gix::objs::find::Error;
1010
use gix::{
1111
bstr::{BStr, BString, ByteSlice},
12+
diff::rewrites::CopySource,
1213
features::progress,
13-
object::tree::diff::rewrites::CopySource,
1414
parallel::{InOrderIter, SequenceId},
1515
prelude::ObjectIdExt,
1616
Count, Progress,
@@ -139,11 +139,10 @@ pub fn update(
139139
});
140140

141141
let rewrites = {
142-
let mut r =
143-
gix::object::tree::diff::Rewrites::try_from_config(&repo.config_snapshot(), true)?.unwrap_or_default();
144-
r.copies = Some(gix::object::tree::diff::rewrites::Copies {
142+
let mut r = gix::diff::Rewrites::try_from_config(&repo.config_snapshot(), true)?.unwrap_or_default();
143+
r.copies = Some(gix::diff::rewrites::Copies {
145144
source: if find_copies_harder {
146-
CopySource::FromSetOfModifiedFilesAndSourceTree
145+
CopySource::FromSetOfModifiedFilesAndAllSources
147146
} else {
148147
CopySource::FromSetOfModifiedFiles
149148
},

gix/src/diff.rs

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ pub mod rewrites {
141141

142142
use gix_diff::tree::visit::Change;
143143
use gix_object::tree::EntryMode;
144+
use gix_object::FindExt;
144145

145146
use crate::diff::blob::DiffLineStats;
146147
use crate::diff::{rewrites::Tracker, Rewrites};
@@ -249,7 +250,7 @@ pub mod rewrites {
249250
#[allow(missing_docs)]
250251
pub enum Error {
251252
#[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),
253254
#[error("Could not obtain exhaustive item set to use as possible sources for copy detection")]
254255
GetItemsForExhaustiveCopyDetection(#[source] Box<dyn std::error::Error + Send + Sync>),
255256
}
@@ -303,23 +304,20 @@ pub mod rewrites {
303304
/// `cb(destination, source)` is called for each item, either with `Some(source)` if it's
304305
/// the destination of a copy or rename, or with `None` for source if no relation to other
305306
/// 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.
309309
/// `push_source_tree(push_fn: push(change, location))` is a function that is called when the entire tree of the source
310310
/// should be added as modifications by calling `push` repeatedly to use for perfect copy tracking. Note that
311311
/// `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>(
313313
&mut self,
314314
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,
316316
mut push_source_tree: PushSourceTreeFn,
317317
) -> Result<Outcome, emit::Error>
318318
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,
323321
{
324322
fn by_id_and_location(a: &Item, b: &Item) -> std::cmp::Ordering {
325323
a.change
@@ -338,7 +336,7 @@ pub mod rewrites {
338336
&mut cb,
339337
self.rewrites.percentage,
340338
out,
341-
&mut find_blob,
339+
&objects,
342340
)?;
343341

344342
if let Some(copies) = self.rewrites.copies {
@@ -347,7 +345,7 @@ pub mod rewrites {
347345
&mut cb,
348346
copies.percentage,
349347
out,
350-
&mut find_blob,
348+
&objects,
351349
)?;
352350

353351
match copies.source {
@@ -369,7 +367,7 @@ pub mod rewrites {
369367
&mut cb,
370368
copies.percentage,
371369
out,
372-
&mut find_blob,
370+
&objects,
373371
)?;
374372
}
375373
}
@@ -392,21 +390,17 @@ pub mod rewrites {
392390
Ok(out)
393391
}
394392

395-
fn match_pairs_of_kind<FindFn, E>(
393+
fn match_pairs_of_kind(
396394
&mut self,
397395
kind: visit::Kind,
398396
cb: &mut impl FnMut(visit::Destination<'_>, Option<visit::Source<'_>>) -> gix_diff::tree::visit::Action,
399397
percentage: Option<f32>,
400398
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> {
407401
// we try to cheaply reduce the set of possibilities first, before possibly looking more exhaustively.
408402
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)?
410404
== gix_diff::tree::visit::Action::Cancel
411405
{
412406
return Ok(out);
@@ -428,24 +422,20 @@ pub mod rewrites {
428422
false
429423
};
430424
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)?;
432426
}
433427
}
434428
Ok(out)
435429
}
436430

437-
fn match_pairs<FindFn, E>(
431+
fn match_pairs(
438432
&mut self,
439433
cb: &mut impl FnMut(visit::Destination<'_>, Option<visit::Source<'_>>) -> gix_diff::tree::visit::Action,
440434
percentage: Option<f32>,
441435
kind: visit::Kind,
442436
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> {
449439
// TODO(perf): reuse object data and interner state and interned tokens, make these available to `find_match()`
450440
let mut dest_ofs = 0;
451441
while let Some((mut dest_idx, dest)) =
@@ -462,7 +452,7 @@ pub mod rewrites {
462452
percentage.map(|p| (p, self.diff_algo)),
463453
kind,
464454
stats,
465-
&mut find_blob,
455+
&objects,
466456
&mut self.buf1,
467457
&mut self.buf2,
468458
)?
@@ -543,20 +533,19 @@ pub mod rewrites {
543533
/// 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
544534
/// of items to be searched.
545535
#[allow(clippy::too_many_arguments)]
546-
fn find_match<'a, FindFn, E>(
536+
fn find_match<'a, Find>(
547537
items: &'a [Item],
548538
item: &Item,
549539
item_idx: usize,
550540
percentage: Option<(f32, gix_diff::blob::Algorithm)>,
551541
kind: visit::Kind,
552542
stats: &mut Outcome,
553-
mut find_worktree_blob: FindFn,
543+
objects: Find,
554544
buf1: &mut Vec<u8>,
555545
buf2: &mut Vec<u8>,
556546
) -> Result<Option<SourceTuple<'a>>, emit::Error>
557547
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,
560549
{
561550
let (item_id, item_mode) = item.change.oid_and_entry_mode();
562551
if needs_exact_match(percentage.map(|t| t.0)) || item_mode == gix_object::tree::EntryMode::Link {
@@ -583,8 +572,7 @@ pub mod rewrites {
583572
return Ok(Some(src));
584573
}
585574
} 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)?;
588576
let (percentage, algo) = percentage.expect("it's set to something below 1.0 and we assured this");
589577
debug_assert!(
590578
item.change.entry_mode().is_blob(),
@@ -595,8 +583,7 @@ pub mod rewrites {
595583
.enumerate()
596584
.filter(|(src_idx, src)| *src_idx != item_idx && src.is_source_for_destination_of(kind, item_mode))
597585
{
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)?;
600587
// TODO: make sure we get attribute handling and binary skips and filters right here. There is crate::object::blob::diff::Platform
601588
// which should have facilities for that one day, but we don't use it because we need newlines in our tokens.
602589
let tokens = gix_diff::blob::intern::InternedInput::new(

gix/src/object/tree/diff/for_each.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ where
174174
&mut self.err,
175175
),
176176
},
177-
|oid, buf| self.src_tree.repo.objects.find_blob(oid, buf),
177+
&self.src_tree.repo.objects,
178178
|push| {
179179
self.src_tree
180180
.traverse()

0 commit comments

Comments
 (0)