Cleanup worktrees' shared state when unsharing
This commit is contained in:
parent
5415663a73
commit
f51cf6b05e
4 changed files with 62 additions and 21 deletions
|
@ -1009,6 +1009,7 @@ pub struct LocalWorktree {
|
|||
struct ShareState {
|
||||
project_id: u64,
|
||||
snapshots_tx: Sender<Snapshot>,
|
||||
_maintain_remote_snapshot: Option<Task<()>>,
|
||||
}
|
||||
|
||||
pub struct RemoteWorktree {
|
||||
|
@ -1565,29 +1566,27 @@ impl LocalWorktree {
|
|||
let rpc = self.client.clone();
|
||||
let worktree_id = cx.model_id() as u64;
|
||||
let (snapshots_to_send_tx, snapshots_to_send_rx) = smol::channel::unbounded::<Snapshot>();
|
||||
let maintain_remote_snapshot = cx.background().spawn({
|
||||
let rpc = rpc.clone();
|
||||
let snapshot = snapshot.clone();
|
||||
async move {
|
||||
let mut prev_snapshot = snapshot;
|
||||
while let Ok(snapshot) = snapshots_to_send_rx.recv().await {
|
||||
let message =
|
||||
snapshot.build_update(&prev_snapshot, project_id, worktree_id, false);
|
||||
match rpc.send(message).await {
|
||||
Ok(()) => prev_snapshot = snapshot,
|
||||
Err(err) => log::error!("error sending snapshot diff {}", err),
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
self.share = Some(ShareState {
|
||||
project_id,
|
||||
snapshots_tx: snapshots_to_send_tx,
|
||||
_maintain_remote_snapshot: Some(maintain_remote_snapshot),
|
||||
});
|
||||
|
||||
cx.background()
|
||||
.spawn({
|
||||
let rpc = rpc.clone();
|
||||
let snapshot = snapshot.clone();
|
||||
async move {
|
||||
let mut prev_snapshot = snapshot;
|
||||
while let Ok(snapshot) = snapshots_to_send_rx.recv().await {
|
||||
let message =
|
||||
snapshot.build_update(&prev_snapshot, project_id, worktree_id, false);
|
||||
match rpc.send(message).await {
|
||||
Ok(()) => prev_snapshot = snapshot,
|
||||
Err(err) => log::error!("error sending snapshot diff {}", err),
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
||||
let diagnostic_summaries = self.diagnostic_summaries.clone();
|
||||
let share_message = cx.background().spawn(async move {
|
||||
proto::ShareWorktree {
|
||||
|
@ -1601,6 +1600,14 @@ impl LocalWorktree {
|
|||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
pub fn unshare(&mut self) {
|
||||
self.share.take();
|
||||
}
|
||||
|
||||
pub fn is_shared(&self) -> bool {
|
||||
self.share.is_some()
|
||||
}
|
||||
}
|
||||
|
||||
fn build_gitignore(abs_path: &Path, fs: &dyn Fs) -> Result<Gitignore> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue