Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

git_ui: Avoid blocking main thread during stage/unstage (#47806)

Marco Mihai Condrache0c9b8fdba801
diff --git a/crates/project/src/git_store.rs b/crates/project/src/git_store.rs
index e9330014c3f..f1a777711d5 100644
--- a/crates/project/src/git_store.rs
+++ b/crates/project/src/git_store.rs
@@ -5022,43 +5022,69 @@ impl Repository {
}
pub fn stage_all(&mut self, cx: &mut Context<Self>) -> Task<anyhow::Result<()>> {
- let to_stage = self
- .cached_status()
- .filter_map(|entry| {
- if let Some(ops) = self.pending_ops_for_path(&entry.repo_path) {
- if ops.staging() || ops.staged() {
+ let snapshot = self.snapshot.clone();
+ let pending_ops = self.pending_ops.clone();
+ let to_stage = cx.background_spawn(async move {
+ snapshot
+ .status()
+ .filter_map(|entry| {
+ if let Some(ops) =
+ pending_ops.get(&PathKey(entry.repo_path.as_ref().clone()), ())
+ {
+ if ops.staging() || ops.staged() {
+ None
+ } else {
+ Some(entry.repo_path)
+ }
+ } else if entry.status.staging().is_fully_staged() {
None
} else {
Some(entry.repo_path)
}
- } else if entry.status.staging().is_fully_staged() {
- None
- } else {
- Some(entry.repo_path)
- }
- })
- .collect();
- self.stage_or_unstage_entries(true, to_stage, cx)
+ })
+ .collect()
+ });
+
+ cx.spawn(async move |this, cx| {
+ let to_stage = to_stage.await;
+ this.update(cx, |this, cx| {
+ this.stage_or_unstage_entries(true, to_stage, cx)
+ })?
+ .await
+ })
}
pub fn unstage_all(&mut self, cx: &mut Context<Self>) -> Task<anyhow::Result<()>> {
- let to_unstage = self
- .cached_status()
- .filter_map(|entry| {
- if let Some(ops) = self.pending_ops_for_path(&entry.repo_path) {
- if !ops.staging() && !ops.staged() {
+ let snapshot = self.snapshot.clone();
+ let pending_ops = self.pending_ops.clone();
+ let to_unstage = cx.background_spawn(async move {
+ snapshot
+ .status()
+ .filter_map(|entry| {
+ if let Some(ops) =
+ pending_ops.get(&PathKey(entry.repo_path.as_ref().clone()), ())
+ {
+ if !ops.staging() && !ops.staged() {
+ None
+ } else {
+ Some(entry.repo_path)
+ }
+ } else if entry.status.staging().is_fully_unstaged() {
None
} else {
Some(entry.repo_path)
}
- } else if entry.status.staging().is_fully_unstaged() {
- None
- } else {
- Some(entry.repo_path)
- }
- })
- .collect();
- self.stage_or_unstage_entries(false, to_unstage, cx)
+ })
+ .collect()
+ });
+
+ cx.spawn(async move |this, cx| {
+ let to_unstage = to_unstage.await;
+ this.update(cx, |this, cx| {
+ this.stage_or_unstage_entries(false, to_unstage, cx)
+ })?
+ .await
+ })
}
pub fn stash_all(&mut self, cx: &mut Context<Self>) -> Task<anyhow::Result<()>> {