Unify remote code paths in git store
Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com>
This commit is contained in:
parent
d95f2342e8
commit
c75868f3d5
2 changed files with 21 additions and 58 deletions
|
@ -44,9 +44,7 @@ use parking_lot::Mutex;
|
||||||
use postage::stream::Stream as _;
|
use postage::stream::Stream as _;
|
||||||
use rpc::{
|
use rpc::{
|
||||||
AnyProtoClient, TypedEnvelope,
|
AnyProtoClient, TypedEnvelope,
|
||||||
proto::{
|
proto::{self, FromProto, ToProto, git_reset, split_repository_update},
|
||||||
self, FromProto, REMOTE_SERVER_PROJECT_ID, ToProto, git_reset, split_repository_update,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -143,14 +141,10 @@ enum GitStoreState {
|
||||||
project_environment: Entity<ProjectEnvironment>,
|
project_environment: Entity<ProjectEnvironment>,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
},
|
},
|
||||||
Ssh {
|
|
||||||
upstream_client: AnyProtoClient,
|
|
||||||
upstream_project_id: ProjectId,
|
|
||||||
downstream: Option<(AnyProtoClient, ProjectId)>,
|
|
||||||
},
|
|
||||||
Remote {
|
Remote {
|
||||||
upstream_client: AnyProtoClient,
|
upstream_client: AnyProtoClient,
|
||||||
upstream_project_id: ProjectId,
|
upstream_project_id: u64,
|
||||||
|
downstream: Option<(AnyProtoClient, ProjectId)>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,7 +351,7 @@ impl GitStore {
|
||||||
worktree_store: &Entity<WorktreeStore>,
|
worktree_store: &Entity<WorktreeStore>,
|
||||||
buffer_store: Entity<BufferStore>,
|
buffer_store: Entity<BufferStore>,
|
||||||
upstream_client: AnyProtoClient,
|
upstream_client: AnyProtoClient,
|
||||||
project_id: ProjectId,
|
project_id: u64,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new(
|
Self::new(
|
||||||
|
@ -366,23 +360,6 @@ impl GitStore {
|
||||||
GitStoreState::Remote {
|
GitStoreState::Remote {
|
||||||
upstream_client,
|
upstream_client,
|
||||||
upstream_project_id: project_id,
|
upstream_project_id: project_id,
|
||||||
},
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn ssh(
|
|
||||||
worktree_store: &Entity<WorktreeStore>,
|
|
||||||
buffer_store: Entity<BufferStore>,
|
|
||||||
upstream_client: AnyProtoClient,
|
|
||||||
cx: &mut Context<Self>,
|
|
||||||
) -> Self {
|
|
||||||
Self::new(
|
|
||||||
worktree_store.clone(),
|
|
||||||
buffer_store,
|
|
||||||
GitStoreState::Ssh {
|
|
||||||
upstream_client,
|
|
||||||
upstream_project_id: ProjectId(REMOTE_SERVER_PROJECT_ID),
|
|
||||||
downstream: None,
|
downstream: None,
|
||||||
},
|
},
|
||||||
cx,
|
cx,
|
||||||
|
@ -453,7 +430,7 @@ impl GitStore {
|
||||||
|
|
||||||
pub fn shared(&mut self, project_id: u64, client: AnyProtoClient, cx: &mut Context<Self>) {
|
pub fn shared(&mut self, project_id: u64, client: AnyProtoClient, cx: &mut Context<Self>) {
|
||||||
match &mut self.state {
|
match &mut self.state {
|
||||||
GitStoreState::Ssh {
|
GitStoreState::Remote {
|
||||||
downstream: downstream_client,
|
downstream: downstream_client,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
|
@ -529,9 +506,6 @@ impl GitStore {
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
GitStoreState::Remote { .. } => {
|
|
||||||
debug_panic!("shared called on remote store");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -543,15 +517,12 @@ impl GitStore {
|
||||||
} => {
|
} => {
|
||||||
downstream_client.take();
|
downstream_client.take();
|
||||||
}
|
}
|
||||||
GitStoreState::Ssh {
|
GitStoreState::Remote {
|
||||||
downstream: downstream_client,
|
downstream: downstream_client,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
downstream_client.take();
|
downstream_client.take();
|
||||||
}
|
}
|
||||||
GitStoreState::Remote { .. } => {
|
|
||||||
debug_panic!("unshared called on remote store");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
self.shared_diffs.clear();
|
self.shared_diffs.clear();
|
||||||
}
|
}
|
||||||
|
@ -1049,21 +1020,17 @@ impl GitStore {
|
||||||
} => downstream_client
|
} => downstream_client
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|state| (state.client.clone(), state.project_id)),
|
.map(|state| (state.client.clone(), state.project_id)),
|
||||||
GitStoreState::Ssh {
|
GitStoreState::Remote {
|
||||||
downstream: downstream_client,
|
downstream: downstream_client,
|
||||||
..
|
..
|
||||||
} => downstream_client.clone(),
|
} => downstream_client.clone(),
|
||||||
GitStoreState::Remote { .. } => None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn upstream_client(&self) -> Option<AnyProtoClient> {
|
fn upstream_client(&self) -> Option<AnyProtoClient> {
|
||||||
match &self.state {
|
match &self.state {
|
||||||
GitStoreState::Local { .. } => None,
|
GitStoreState::Local { .. } => None,
|
||||||
GitStoreState::Ssh {
|
GitStoreState::Remote {
|
||||||
upstream_client, ..
|
|
||||||
}
|
|
||||||
| GitStoreState::Remote {
|
|
||||||
upstream_client, ..
|
upstream_client, ..
|
||||||
} => Some(upstream_client.clone()),
|
} => Some(upstream_client.clone()),
|
||||||
}
|
}
|
||||||
|
@ -1434,12 +1401,7 @@ impl GitStore {
|
||||||
cx.background_executor()
|
cx.background_executor()
|
||||||
.spawn(async move { fs.git_init(&path, fallback_branch_name) })
|
.spawn(async move { fs.git_init(&path, fallback_branch_name) })
|
||||||
}
|
}
|
||||||
GitStoreState::Ssh {
|
GitStoreState::Remote {
|
||||||
upstream_client,
|
|
||||||
upstream_project_id: project_id,
|
|
||||||
..
|
|
||||||
}
|
|
||||||
| GitStoreState::Remote {
|
|
||||||
upstream_client,
|
upstream_client,
|
||||||
upstream_project_id: project_id,
|
upstream_project_id: project_id,
|
||||||
..
|
..
|
||||||
|
@ -1449,7 +1411,7 @@ impl GitStore {
|
||||||
cx.background_executor().spawn(async move {
|
cx.background_executor().spawn(async move {
|
||||||
client
|
client
|
||||||
.request(proto::GitInit {
|
.request(proto::GitInit {
|
||||||
project_id: project_id.0,
|
project_id: project_id,
|
||||||
abs_path: path.to_string_lossy().to_string(),
|
abs_path: path.to_string_lossy().to_string(),
|
||||||
fallback_branch_name,
|
fallback_branch_name,
|
||||||
})
|
})
|
||||||
|
@ -1473,13 +1435,18 @@ impl GitStore {
|
||||||
cx.background_executor()
|
cx.background_executor()
|
||||||
.spawn(async move { fs.git_clone(&repo, &path).await })
|
.spawn(async move { fs.git_clone(&repo, &path).await })
|
||||||
}
|
}
|
||||||
GitStoreState::Ssh {
|
GitStoreState::Remote {
|
||||||
upstream_client,
|
upstream_client,
|
||||||
upstream_project_id,
|
upstream_project_id,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
|
if upstream_client.is_via_collab() {
|
||||||
|
return Task::ready(Err(anyhow!(
|
||||||
|
"Git Clone isn't supported for project guests"
|
||||||
|
)));
|
||||||
|
}
|
||||||
let request = upstream_client.request(proto::GitClone {
|
let request = upstream_client.request(proto::GitClone {
|
||||||
project_id: upstream_project_id.0,
|
project_id: *upstream_project_id,
|
||||||
abs_path: path.to_string_lossy().to_string(),
|
abs_path: path.to_string_lossy().to_string(),
|
||||||
remote_repo: repo,
|
remote_repo: repo,
|
||||||
});
|
});
|
||||||
|
@ -1493,9 +1460,6 @@ impl GitStore {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
GitStoreState::Remote { .. } => {
|
|
||||||
Task::ready(Err(anyhow!("Git Clone isn't supported for remote users")))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,9 +42,7 @@ pub use manifest_tree::ManifestTree;
|
||||||
|
|
||||||
use anyhow::{Context as _, Result, anyhow};
|
use anyhow::{Context as _, Result, anyhow};
|
||||||
use buffer_store::{BufferStore, BufferStoreEvent};
|
use buffer_store::{BufferStore, BufferStoreEvent};
|
||||||
use client::{
|
use client::{Client, Collaborator, PendingEntitySubscription, TypedEnvelope, UserStore, proto};
|
||||||
Client, Collaborator, PendingEntitySubscription, ProjectId, TypedEnvelope, UserStore, proto,
|
|
||||||
};
|
|
||||||
use clock::ReplicaId;
|
use clock::ReplicaId;
|
||||||
|
|
||||||
use dap::client::DebugAdapterClient;
|
use dap::client::DebugAdapterClient;
|
||||||
|
@ -1290,10 +1288,11 @@ impl Project {
|
||||||
});
|
});
|
||||||
|
|
||||||
let git_store = cx.new(|cx| {
|
let git_store = cx.new(|cx| {
|
||||||
GitStore::ssh(
|
GitStore::remote(
|
||||||
&worktree_store,
|
&worktree_store,
|
||||||
buffer_store.clone(),
|
buffer_store.clone(),
|
||||||
remote_proto.clone(),
|
remote_proto.clone(),
|
||||||
|
REMOTE_SERVER_PROJECT_ID,
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
@ -1518,7 +1517,7 @@ impl Project {
|
||||||
&worktree_store,
|
&worktree_store,
|
||||||
buffer_store.clone(),
|
buffer_store.clone(),
|
||||||
client.clone().into(),
|
client.clone().into(),
|
||||||
ProjectId(remote_id),
|
remote_id,
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue