Skip to content

Commit 43202d3

Browse files
committed
Don't panic when suspect isn't known when converting unblamed to blame-entry
This can apparently happen, and now we handle this case and keep looking for the remaining blame entries.
1 parent 3ac8be1 commit 43202d3

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

gix-blame/src/file/function.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,14 @@ fn pass_blame_from_to(from: ObjectId, to: ObjectId, hunks_to_blame: &mut Vec<Unb
211211
/// Convert each of the unblamed hunk in `hunks_to_blame` into a [`BlameEntry`], consuming them in the process.
212212
/// `suspect` is expected to be present in the suspect-map in each [`UnblamedHunk`].
213213
fn unblamed_to_out(hunks_to_blame: &mut Vec<UnblamedHunk>, out: &mut Vec<BlameEntry>, suspect: ObjectId) {
214-
out.extend(
215-
hunks_to_blame
216-
.drain(..)
217-
.map(|hunk| BlameEntry::from_unblamed_hunk(hunk, suspect)),
218-
);
214+
let mut without_suspect = Vec::new();
215+
out.extend(hunks_to_blame.drain(..).filter_map(|hunk| {
216+
BlameEntry::from_unblamed_hunk(&hunk, suspect).or_else(|| {
217+
without_suspect.push(hunk);
218+
None
219+
})
220+
}));
221+
*hunks_to_blame = without_suspect;
219222
}
220223

221224
/// This function merges adjacent blame entries. It merges entries that are adjacent both in the

gix-blame/src/file/mod.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -468,18 +468,15 @@ impl BlameEntry {
468468
}
469469

470470
/// Create an offset from a portion of the *Blamed File*.
471-
fn from_unblamed_hunk(mut unblamed_hunk: UnblamedHunk, commit_id: ObjectId) -> Self {
472-
let range_in_source_file = unblamed_hunk
473-
.suspects
474-
.remove(&commit_id)
475-
.expect("Private and only called when we now `commit_id` is in the suspect list");
471+
fn from_unblamed_hunk(unblamed_hunk: &UnblamedHunk, commit_id: ObjectId) -> Option<Self> {
472+
let range_in_source_file = unblamed_hunk.suspects.get(&commit_id)?;
476473

477-
Self {
474+
Some(Self {
478475
start_in_blamed_file: unblamed_hunk.range_in_blamed_file.start,
479476
start_in_source_file: range_in_source_file.start,
480477
len: force_non_zero(range_in_source_file.len() as u32),
481478
commit_id,
482-
}
479+
})
483480
}
484481
}
485482

0 commit comments

Comments
 (0)