From f9bd9ec6ec6c0a76ee589b81cc3df5e44fe04e54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20R=C3=BC=C3=9Fler?= Date: Mon, 21 Oct 2024 14:24:56 +0200 Subject: [PATCH] Add shortcut when oid is identical to parent's --- gix-blame/src/lib.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/gix-blame/src/lib.rs b/gix-blame/src/lib.rs index 6b565d7472d..a1bce5dbd28 100644 --- a/gix-blame/src/lib.rs +++ b/gix-blame/src/lib.rs @@ -802,7 +802,7 @@ pub fn blame_file( )]; let mut out: Vec = vec![]; - for item in traverse { + 'outer: for item in traverse { let item = item?; let suspect = item.id; @@ -887,6 +887,30 @@ pub fn blame_file( } } } else { + let mut buffer = Vec::new(); + let commit_id = odb.find_commit(&suspect, &mut buffer).unwrap().tree(); + let tree = odb.find_tree(&commit_id, &mut buffer).unwrap(); + let entry = tree.bisect_entry(file_path, false).unwrap(); + + for parent_id in &parent_ids { + let mut buffer = Vec::new(); + let parent_commit_id = odb.find_commit(parent_id, &mut buffer).unwrap().tree(); + let parent_tree = odb.find_tree(&parent_commit_id, &mut buffer).unwrap(); + + if let Some(parent_entry) = parent_tree.bisect_entry(file_path, false) { + if entry.oid == parent_entry.oid { + // The blobs storing the blamed file in `entry` and `parent_entry` are + // identical which is why we can pass blame to the parent without further + // checks. + hunks_to_blame + .iter_mut() + .for_each(|unblamed_hunk| unblamed_hunk.pass_blame(suspect, *parent_id)); + + continue 'outer; + } + } + } + for parent_id in parent_ids { let changes_for_file_path = get_changes_for_file_path(&odb, file_path, item.id, parent_id);