git: Fix race condition when [un]staging hunks in quick succession (#26422)

- [x] Fix `[un]stage` hunk operations cancelling pending ones
  - [x] Add test
- [ ] bugs I stumbled upon (try to repro again before merging)
  - [x] holding `git::StageAndNext` skips hunks randomly 
    - [x] Add test
  - [x] restoring a file keeps it in the git panel
- [x] Double clicking on `toggle staged` fast makes Zed disagree with
`git` CLI
- [x] checkbox shows ✔️ (fully staged) after a single
stage

Release Notes:

- N/A

---------

Co-authored-by: Cole <cole@zed.dev>
Co-authored-by: Max <max@zed.dev>
This commit is contained in:
João Marcos 2025-03-13 14:41:04 -03:00 committed by GitHub
parent 18fcdf1d2c
commit 00359271d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 406 additions and 83 deletions

View file

@ -406,6 +406,7 @@ where
self.seek_internal(pos, bias, &mut (), cx)
}
/// Advances the cursor and returns traversed items as a tree.
#[track_caller]
pub fn slice<Target>(
&mut self,

View file

@ -225,6 +225,15 @@ impl<T: Item> SumTree<T> {
}))
}
/// Useful in cases where the item type has a non-trivial context type, but the zero value of the summary type doesn't depend on that context.
pub fn from_summary(summary: T::Summary) -> Self {
SumTree(Arc::new(Node::Leaf {
summary,
items: ArrayVec::new(),
item_summaries: ArrayVec::new(),
}))
}
pub fn from_item(item: T, cx: &<T::Summary as Summary>::Context) -> Self {
let mut tree = Self::new(cx);
tree.push(item, cx);