Skip to content

Commit 89e54c7

Browse files
committed
Add shortcut when oid is identical to parent's
1 parent a6e9e32 commit 89e54c7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

gix-blame/src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,9 +824,33 @@ pub fn blame_file<E>(
824824
break;
825825
}
826826

827+
let mut buffer = Vec::new();
828+
let commit_id = odb.find_commit(&suspect, &mut buffer).unwrap().tree();
829+
let tree = odb.find_tree(&commit_id, &mut buffer).unwrap();
830+
831+
let Some(entry) = tree.bisect_entry(file_path, false) else {
832+
continue;
833+
};
834+
827835
if parent_ids.len() == 1 {
828836
let parent_id: ObjectId = *parent_ids.last().unwrap();
829837

838+
let mut buffer = Vec::new();
839+
let parent_commit_id = odb.find_commit(&parent_id, &mut buffer).unwrap().tree();
840+
let parent_tree = odb.find_tree(&parent_commit_id, &mut buffer).unwrap();
841+
842+
if let Some(parent_entry) = parent_tree.bisect_entry(file_path, false) {
843+
if entry.oid == parent_entry.oid {
844+
// The blobs storing the blamed file in `entry` and `parent_entry` are identical
845+
// which is why we can pass blame to the parent without further checks.
846+
hunks_to_blame
847+
.iter_mut()
848+
.for_each(|unblamed_hunk| unblamed_hunk.pass_blame(suspect, parent_id));
849+
850+
continue;
851+
}
852+
}
853+
830854
let changes_for_file_path = get_changes_for_file_path(&odb, file_path, item.id, parent_id);
831855

832856
let [ref modification]: [gix_diff::tree::recorder::Change] = changes_for_file_path[..] else {

0 commit comments

Comments
 (0)