Skip to content

Commit 3c4d051

Browse files
committed
Use lookup_entry_by_path instead of bisect_entry
`bisect_entry` is the wrong function to search for entries here as it does not take nesting in paths into account.
1 parent 8b273d4 commit 3c4d051

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

gix-blame/src/lib.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -826,9 +826,13 @@ pub fn blame_file<E>(
826826

827827
let mut buffer = Vec::new();
828828
let commit_id = odb.find_commit(&suspect, &mut buffer).unwrap().tree();
829-
let tree = odb.find_tree(&commit_id, &mut buffer).unwrap();
829+
let tree_iter = odb.find_tree_iter(&commit_id, &mut buffer).unwrap();
830830

831-
let Some(entry) = tree.bisect_entry(file_path, false) else {
831+
let mut entry_buffer = Vec::new();
832+
let Some(entry) = tree_iter
833+
.lookup_entry_by_path(&odb, &mut entry_buffer, file_path.to_str().unwrap())
834+
.unwrap()
835+
else {
832836
continue;
833837
};
834838

@@ -837,9 +841,13 @@ pub fn blame_file<E>(
837841

838842
let mut buffer = Vec::new();
839843
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();
844+
let parent_tree_iter = odb.find_tree_iter(&parent_commit_id, &mut buffer).unwrap();
841845

842-
if let Some(parent_entry) = parent_tree.bisect_entry(file_path, false) {
846+
let mut entry_buffer = Vec::new();
847+
if let Some(parent_entry) = parent_tree_iter
848+
.lookup_entry_by_path(&odb, &mut entry_buffer, file_path.to_str().unwrap())
849+
.unwrap()
850+
{
843851
if entry.oid == parent_entry.oid {
844852
// The blobs storing the blamed file in `entry` and `parent_entry` are identical
845853
// which is why we can pass blame to the parent without further checks.
@@ -889,15 +897,24 @@ pub fn blame_file<E>(
889897
} else {
890898
let mut buffer = Vec::new();
891899
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();
900+
let tree_iter = odb.find_tree_iter(&commit_id, &mut buffer).unwrap();
901+
902+
let mut entry_buffer = Vec::new();
903+
let entry = tree_iter
904+
.lookup_entry_by_path(&odb, &mut entry_buffer, file_path.to_str().unwrap())
905+
.unwrap()
906+
.unwrap();
894907

895908
for parent_id in &parent_ids {
896909
let mut buffer = Vec::new();
897910
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();
911+
let parent_tree_iter = odb.find_tree_iter(&parent_commit_id, &mut buffer).unwrap();
899912

900-
if let Some(parent_entry) = parent_tree.bisect_entry(file_path, false) {
913+
let mut entry_buffer = Vec::new();
914+
if let Some(parent_entry) = parent_tree_iter
915+
.lookup_entry_by_path(&odb, &mut entry_buffer, file_path.to_str().unwrap())
916+
.unwrap()
917+
{
901918
if entry.oid == parent_entry.oid {
902919
// The blobs storing the blamed file in `entry` and `parent_entry` are
903920
// identical which is why we can pass blame to the parent without further

0 commit comments

Comments
 (0)