From d12698abb5b67c70bc957f1ea269f4ad719a654e Mon Sep 17 00:00:00 2001 From: Mattias Granlund Date: Mon, 24 Jun 2024 23:11:39 +0300 Subject: [PATCH] Fix bug in hunk -> branch assignment - return early on lock only if hunk matches or intersects --- crates/gitbutler-core/src/virtual_branches/virtual.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/gitbutler-core/src/virtual_branches/virtual.rs b/crates/gitbutler-core/src/virtual_branches/virtual.rs index e37738fe9..3acca599d 100644 --- a/crates/gitbutler-core/src/virtual_branches/virtual.rs +++ b/crates/gitbutler-core/src/virtual_branches/virtual.rs @@ -1823,10 +1823,10 @@ fn get_applied_status( // if any of the current hunks intersects with the owned hunk, we want to keep it for (i, git_diff_hunk) in git_diff_hunks.iter().enumerate() { let hash = Hunk::hash_diff(&git_diff_hunk.diff_lines); - if locks.contains_key(&hash) { - return None; // Defer allocation to unclaimed hunks processing - } if claimed_hunk.eq(&Hunk::from(git_diff_hunk)) { + if locks.contains_key(&hash) { + return None; // Defer allocation to unclaimed hunks processing + } let timestamp = claimed_hunk.timestamp_ms().unwrap_or(mtime); diffs_by_branch .entry(branch.id) @@ -1843,6 +1843,9 @@ fn get_applied_status( .with_hash(hash), ); } else if claimed_hunk.intersects(git_diff_hunk) { + if locks.contains_key(&hash) { + return None; // Defer allocation to unclaimed hunks processing + } diffs_by_branch .entry(branch.id) .or_default()