Cleanup worktrees' shared state when unsharing

This commit is contained in:
Antonio Scandurra 2022-01-17 10:58:49 +01:00
parent 5415663a73
commit f51cf6b05e
4 changed files with 62 additions and 21 deletions

View file

@ -428,6 +428,11 @@ impl Project {
rpc.send(proto::UnshareProject { project_id }).await?;
this.update(&mut cx, |this, cx| {
this.collaborators.clear();
for worktree in &this.worktrees {
worktree.update(cx, |worktree, _| {
worktree.as_local_mut().unwrap().unshare();
});
}
cx.notify()
});
Ok(())

View file

@ -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> {