@@ -122,17 +122,15 @@ pub fn file(
122
122
}
123
123
124
124
let first_hunk_for_suspect = hunks_to_blame.iter().find(|hunk| hunk.has_suspect(&suspect));
125
-
let is_still_suspect = first_hunk_for_suspect.is_some();
126
-
if !is_still_suspect {
125
+
let Some(first_hunk_for_suspect) = first_hunk_for_suspect else {
127
126
// There are no `UnblamedHunk`s associated with this `suspect`, so we can continue with
128
127
// the next one.
129
128
continue 'outer;
130
-
}
129
+
};
131
130
132
131
// We know `first_hunk_for_suspect` can’t be `None` here because we check `is_some()`
133
132
// above.
134
-
let current_file_path: BString = first_hunk_for_suspect
135
-
.unwrap()
133
+
let current_file_path = first_hunk_for_suspect
136
134
.source_file_name
137
135
.clone()
138
136
.unwrap_or_else(|| file_path.to_owned());
@@ -259,6 +257,7 @@ pub fn file(
259
257
&mut buf,
260
258
&mut buf2,
261
259
&mut buf3,
260
+
options.rewrites,
262
261
)?;
263
262
let Some(modification) = changes_for_file_path else {
264
263
if more_than_one_parent {
@@ -293,6 +292,7 @@ pub fn file(
293
292
id,
294
293
previous_id,
295
294
file_path,
295
+
file_path,
296
296
options.diff_algorithm,
297
297
&mut stats,
298
298
)?;
@@ -309,6 +309,7 @@ pub fn file(
309
309
id,
310
310
source_id,
311
311
file_path,
312
+
source_location.as_ref(),
312
313
options.diff_algorithm,
313
314
&mut stats,
314
315
)?;
@@ -433,6 +434,8 @@ fn coalesce_blame_entries(lines_blamed: Vec<BlameEntry>) -> Vec<BlameEntry> {
433
434
})
434
435
}
435
436
437
+
/// The union of [`gix_diff::tree::recorder::Change`] and [`gix_diff::tree_with_rewrites::Change`],
438
+
/// keeping only the blame-relevant information.
436
439
enum TreeDiffChange {
437
440
Addition,
438
441
Deletion,
@@ -497,6 +500,7 @@ fn tree_diff_at_file_path(
497
500
commit_buf: &mut Vec<u8>,
498
501
lhs_tree_buf: &mut Vec<u8>,
499
502
rhs_tree_buf: &mut Vec<u8>,
503
+
rewrites: Option<gix_diff::Rewrites>,
500
504
) -> Result<Option<TreeDiffChange>, Error> {
501
505
let parent_tree_id = find_commit(cache, &odb, &parent_id, commit_buf)?.tree_id()?;
502
506
@@ -513,9 +517,15 @@ fn tree_diff_at_file_path(
513
517
// Here, we follow git’s behaviour. We return when we’ve found a `Modification`. We try a
514
518
// second time with rename tracking when the change is either an `Addition` or a `Deletion`
515
519
// because those can turn out to have been a `Rewrite`.
520
+
// TODO(perf): renames are usually rare enough to not care about the work duplication done here.
521
+
// But in theory, a rename tracker could be used by us, on demand, and we could stuff the
522
+
// changes in there and have it find renames, without repeating the diff.
516
523
if matches!(result, Some(TreeDiffChange::Modification { .. })) {
517
524
return Ok(result);
518
525
}
526
+
let Some(rewrites) = rewrites else {
527
+
return Ok(result);
528
+
};
519
529
520
530
let result = tree_diff_with_rewrites_at_file_path(
521
531
&odb,
@@ -525,6 +535,7 @@ fn tree_diff_at_file_path(
525
535
resource_cache,
526
536
parent_tree_iter,
527
537
tree_iter,
538
+
rewrites,
528
539
)?;
529
540
530
541
Ok(result)
@@ -626,7 +637,7 @@ fn tree_diff_without_rewrites_at_file_path(
626
637
stats.trees_diffed += 1;
627
638
628
639
match result {
629
-
Ok(_) | Err(gix_diff::tree::Error::Cancelled) => Ok(recorder.change.map(std::convert::Into::into)),
640
+
Ok(_) | Err(gix_diff::tree::Error::Cancelled) => Ok(recorder.change.map(Into::into)),
630
641
Err(error) => Err(Error::DiffTree(error)),
631
642
}
632
643
}
@@ -640,12 +651,13 @@ fn tree_diff_with_rewrites_at_file_path(
640
651
resource_cache: &mut gix_diff::blob::Platform,
641
652
parent_tree_iter: gix_object::TreeRefIter<'_>,
642
653
tree_iter: gix_object::TreeRefIter<'_>,
654
+
rewrites: gix_diff::Rewrites,
643
655
) -> Result<Option<TreeDiffChange>, Error> {
644
656
let mut change: Option<gix_diff::tree_with_rewrites::Change> = None;
645
657
646
658
let options: gix_diff::tree_with_rewrites::Options = gix_diff::tree_with_rewrites::Options {
647
659
location: Some(gix_diff::tree::recorder::Location::Path),
648
-
rewrites: Some(gix_diff::Rewrites::default()),
660
+
rewrites: Some(rewrites),
649
661
};
650
662
let result = gix_diff::tree_with_rewrites(
651
663
parent_tree_iter,
@@ -667,18 +679,20 @@ fn tree_diff_with_rewrites_at_file_path(
667
679
668
680
match result {
669
681
Ok(_) | Err(gix_diff::tree_with_rewrites::Error::Diff(gix_diff::tree::Error::Cancelled)) => {
670
-
Ok(change.map(std::convert::Into::into))
682
+
Ok(change.map(Into::into))
671
683
}
672
684
Err(error) => Err(Error::DiffTreeWithRewrites(error)),
673
685
}
674
686
}
675
687
688
+
#[allow(clippy::too_many_arguments)]
676
689
fn blob_changes(
677
690
odb: impl gix_object::Find + gix_object::FindHeader,
678
691
resource_cache: &mut gix_diff::blob::Platform,
679
692
oid: ObjectId,
680
693
previous_oid: ObjectId,
681
694
file_path: &BStr,
695
+
previous_file_path: &BStr,
682
696
diff_algorithm: gix_diff::blob::Algorithm,
683
697
stats: &mut Statistics,
684
698
) -> Result<Vec<Change>, Error> {
@@ -738,7 +752,7 @@ fn blob_changes(
738
752
resource_cache.set_resource(
739
753
previous_oid,
740
754
gix_object::tree::EntryKind::Blob,
741
-
file_path,
755
+
previous_file_path,
742
756
gix_diff::blob::ResourceKind::OldOrSource,
743
757
&odb,
744
758
)?;
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4