Skip to content

Commit c5e0261

Browse files
cruesslerByron
authored andcommitted
Add shortcut when oid is identical to parent's
1 parent 4271ff7 commit c5e0261

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

gix-blame/src/lib.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ pub fn blame_file<E>(
802802
)];
803803
let mut out: Vec<BlameEntry> = vec![];
804804

805-
for item in traverse {
805+
'outer: for item in traverse {
806806
let item = item?;
807807
let suspect = item.id;
808808

@@ -887,6 +887,30 @@ pub fn blame_file<E>(
887887
}
888888
}
889889
} else {
890+
let mut buffer = Vec::new();
891+
let commit_id = odb.find_commit(&suspect, &mut buffer).unwrap().tree();
892+
let tree = odb.find_tree(&commit_id, &mut buffer).unwrap();
893+
let entry = tree.bisect_entry(file_path, false).unwrap();
894+
895+
for parent_id in &parent_ids {
896+
let mut buffer = Vec::new();
897+
let parent_commit_id = odb.find_commit(parent_id, &mut buffer).unwrap().tree();
898+
let parent_tree = odb.find_tree(&parent_commit_id, &mut buffer).unwrap();
899+
900+
if let Some(parent_entry) = parent_tree.bisect_entry(file_path, false) {
901+
if entry.oid == parent_entry.oid {
902+
// The blobs storing the blamed file in `entry` and `parent_entry` are
903+
// identical which is why we can pass blame to the parent without further
904+
// checks.
905+
hunks_to_blame
906+
.iter_mut()
907+
.for_each(|unblamed_hunk| unblamed_hunk.pass_blame(suspect, *parent_id));
908+
909+
continue 'outer;
910+
}
911+
}
912+
}
913+
890914
for parent_id in parent_ids {
891915
let changes_for_file_path = get_changes_for_file_path(&odb, file_path, item.id, parent_id);
892916

0 commit comments

Comments
 (0)