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: Stop remote operations blocking commit views (#64720)

Azeem Shaik1a28cff4b409
diff --git a/crates/collab/tests/integration/git_tests.rs b/crates/collab/tests/integration/git_tests.rs
index 1443566112b..c88faf8205f 100644
--- a/crates/collab/tests/integration/git_tests.rs
+++ b/crates/collab/tests/integration/git_tests.rs
@@ -21,7 +21,7 @@ use gpui::{
};
use project::{
ProjectPath,
- git_store::{CommitDataState, MAX_CONCURRENT_BLOB_READS, Repository},
+ git_store::{CommitDataState, MAX_CONCURRENT_OBJECT_READS, Repository},
};
use rand::{SeedableRng, rngs::StdRng};
use serde_json::json;
@@ -465,7 +465,7 @@ async fn test_blob_read_rpcs_are_bounded_on_host(
.await;
let active_call_a = cx_a.read(ActiveCall::global);
- const FILE_COUNT: usize = MAX_CONCURRENT_BLOB_READS + 4;
+ const FILE_COUNT: usize = MAX_CONCURRENT_OBJECT_READS + 4;
let names = (0..FILE_COUNT)
.map(|index| format!("f{index:02}.txt"))
.collect::<Vec<_>>();
@@ -521,7 +521,7 @@ async fn test_blob_read_rpcs_are_bounded_on_host(
}
executor.run_until_parked();
- assert_eq!(gate.peak_concurrent(), MAX_CONCURRENT_BLOB_READS);
+ assert_eq!(gate.peak_concurrent(), MAX_CONCURRENT_OBJECT_READS);
gate.open();
executor.run_until_parked();
@@ -530,6 +530,68 @@ async fn test_blob_read_rpcs_are_bounded_on_host(
}
}
+#[gpui::test]
+async fn test_show_rpcs_are_routed_by_revision_kind_on_host(
+ executor: BackgroundExecutor,
+ cx_a: &mut TestAppContext,
+ cx_b: &mut TestAppContext,
+) {
+ use futures::FutureExt as _;
+
+ let mut server = TestServer::start(executor.clone()).await;
+ let client_a = server.create_client(cx_a, "user_a").await;
+ let client_b = server.create_client(cx_b, "user_b").await;
+ server
+ .create_room(&mut [(&client_a, cx_a), (&client_b, cx_b)])
+ .await;
+ let active_call_a = cx_a.read(ActiveCall::global);
+
+ client_a
+ .fs()
+ .insert_tree(path!("/dir"), json!({ ".git": {} }))
+ .await;
+ let head_sha = "1".repeat(40);
+ client_a
+ .fs()
+ .set_head_for_repo(Path::new(path!("/dir/.git")), &[], head_sha.clone());
+
+ let (project_a, _) = client_a.build_local_project(path!("/dir"), cx_a).await;
+ let project_id = active_call_a
+ .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx))
+ .await
+ .unwrap();
+ let project_b = client_b.join_remote_project(project_id, cx_b).await;
+ executor.run_until_parked();
+
+ let repo_a = project_a.read_with(cx_a, |project, cx| project.active_repository(cx).unwrap());
+ let repo_b = project_b.read_with(cx_b, |project, cx| project.active_repository(cx).unwrap());
+
+ let (release_tx, release_rx) = futures::channel::oneshot::channel::<()>();
+ let held = repo_a.update(cx_a, |repo, _| {
+ repo.send_job("hold", None, move |_, _| async move {
+ release_rx.await.ok();
+ })
+ });
+
+ let mut by_sha = repo_b.update(cx_b, |repo, cx| repo.show_commit(head_sha.clone(), cx));
+ let mut by_ref = repo_b.update(cx_b, |repo, _| repo.show("HEAD".into()));
+ executor.run_until_parked();
+ let details = (&mut by_sha)
+ .now_or_never()
+ .expect("show_commit waited on the host job queue")
+ .unwrap();
+ assert_eq!(details.sha.as_ref(), head_sha);
+ assert!(
+ (&mut by_ref).now_or_never().is_none(),
+ "show by ref skipped the host job queue"
+ );
+
+ release_tx.send(()).ok();
+ held.await.unwrap();
+ executor.run_until_parked();
+ assert_eq!(by_ref.await.unwrap().unwrap().sha.as_ref(), head_sha);
+}
+
#[gpui::test]
async fn test_remote_git_worktrees(
executor: BackgroundExecutor,
diff --git a/crates/git_ui/src/commit_view.rs b/crates/git_ui/src/commit_view.rs
index 4db00ef647d..0db0fe01afc 100644
--- a/crates/git_ui/src/commit_view.rs
+++ b/crates/git_ui/src/commit_view.rs
@@ -212,12 +212,12 @@ impl CommitView {
cx: &mut App,
) {
let commit_diff = repo
- .update(cx, |repo, _| {
- repo.load_commit_diff(commit_sha.clone(), ignore_shallow_boundary)
+ .update(cx, |repo, cx| {
+ repo.load_commit_diff(commit_sha.clone(), ignore_shallow_boundary, cx)
})
.ok();
let commit_details = repo
- .update(cx, |repo, _| repo.show(commit_sha.clone()))
+ .update(cx, |repo, cx| repo.show_commit(commit_sha.clone(), cx))
.ok();
window
@@ -225,8 +225,8 @@ impl CommitView {
let commit_diff = commit_diff?;
let commit_details = commit_details?;
let (commit_diff, commit_details) = futures::join!(commit_diff, commit_details);
- let mut commit_diff = commit_diff.log_err()?.log_err()?;
- let commit_details = commit_details.log_err()?.log_err()?;
+ let mut commit_diff = commit_diff.log_err()?;
+ let commit_details = commit_details.log_err()?;
// Filter to specific file if requested
if let Some(ref filter_path) = file_filter {
diff --git a/crates/git_ui/src/git_graph.rs b/crates/git_ui/src/git_graph.rs
index 97b10ea3aa6..8b3d4a08bd3 100644
--- a/crates/git_ui/src/git_graph.rs
+++ b/crates/git_ui/src/git_graph.rs
@@ -2156,11 +2156,11 @@ impl GitGraph {
self.load_selected_commit_message(cx, &commit_message_handle, &repository);
- let diff_receiver =
- repository.update(cx, |repo, _| repo.load_commit_diff(diff_handle, false));
+ let diff_task =
+ repository.update(cx, |repo, cx| repo.load_commit_diff(diff_handle, false, cx));
self._commit_diff_task = Some(cx.spawn(async move |this, cx| {
- if let Ok(Ok(diff)) = diff_receiver.await {
+ if let Ok(diff) = diff_task.await {
this.update(cx, |this, cx| {
let stats = compute_diff_stats(&diff);
this.selected_commit_diff = Some(diff);
diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs
index 1e3e49da653..d4860999968 100644
--- a/crates/git_ui/src/git_panel.rs
+++ b/crates/git_ui/src/git_panel.rs
@@ -8102,10 +8102,7 @@ impl GitPanel {
let Some(repo) = self.active_repository.clone() else {
return Task::ready(Err(anyhow::anyhow!("no active repo")));
};
- repo.update(cx, |repo, cx| {
- let show = repo.show(sha);
- cx.spawn(async move |_, _| show.await?)
- })
+ repo.update(cx, |repo, cx| repo.show_commit(sha, cx))
}
fn build_context_menu(
diff --git a/crates/git_ui/src/project_diff.rs b/crates/git_ui/src/project_diff.rs
index 75a28b0d9a9..b9e64d79372 100644
--- a/crates/git_ui/src/project_diff.rs
+++ b/crates/git_ui/src/project_diff.rs
@@ -999,7 +999,7 @@ mod tests {
use editor::test::editor_test_context::{EditorTestContext, assert_state_with_diff};
use gpui::{TestAppContext, VisualTestContext};
use multi_buffer::PathKey;
- use project::{FakeFs, git_store::MAX_CONCURRENT_BLOB_READS};
+ use project::{FakeFs, git_store::MAX_CONCURRENT_OBJECT_READS};
use serde_json::json;
use settings::{DiffViewStyle, GitPanelGroupBy, GitPanelSortBy, SettingsStore};
use std::path::Path;
@@ -1616,7 +1616,7 @@ mod tests {
async fn test_merge_base_loading_is_incremental(cx: &mut TestAppContext) {
init_test(cx);
- const FILE_COUNT: usize = MAX_CONCURRENT_BLOB_READS + 4;
+ const FILE_COUNT: usize = MAX_CONCURRENT_OBJECT_READS + 4;
let names = (0..FILE_COUNT)
.map(|index| format!("f{index:02}.txt"))
diff --git a/crates/project/src/git_store.rs b/crates/project/src/git_store.rs
index afcb419d1e6..d02a4c5bfb7 100644
--- a/crates/project/src/git_store.rs
+++ b/crates/project/src/git_store.rs
@@ -116,13 +116,13 @@ pub struct GitStore {
diffs: HashMap<BufferId, Entity<BufferGitState>>,
buffer_ids_by_index_text_buffer_id: HashMap<BufferId, BufferId>,
shared_diffs: HashMap<proto::PeerId, HashMap<BufferId, SharedDiffs>>,
- blob_read_limiter: Arc<Semaphore>,
+ object_read_limiter: Arc<Semaphore>,
_subscriptions: Vec<Subscription>,
}
const MIN_PARKED_REPOSITORY_DEPTH: usize = 2;
-pub const MAX_CONCURRENT_BLOB_READS: usize = 16;
+pub const MAX_CONCURRENT_OBJECT_READS: usize = 16;
#[derive(Clone, Debug)]
pub struct ParkedRepository {
@@ -687,7 +687,7 @@ pub struct Repository {
unshallow_state: UnshallowState,
commit_message_buffer: Option<Entity<Buffer>>,
git_store: WeakEntity<GitStore>,
- blob_read_limiter: Arc<Semaphore>,
+ object_read_limiter: Arc<Semaphore>,
// For a local repository, holds paths that have had worktree events since the last status scan completed,
// and that should be examined during the next status scan.
paths_needing_status_update: Vec<Vec<RepoPath>>,
@@ -1024,7 +1024,7 @@ impl GitStore {
_subscriptions,
loading_diffs: HashMap::default(),
shared_diffs: HashMap::default(),
- blob_read_limiter: Arc::new(Semaphore::new(MAX_CONCURRENT_BLOB_READS)),
+ object_read_limiter: Arc::new(Semaphore::new(MAX_CONCURRENT_OBJECT_READS)),
diffs: HashMap::default(),
buffer_ids_by_index_text_buffer_id: HashMap::default(),
}
@@ -2918,7 +2918,7 @@ impl GitStore {
let id = RepositoryId(next_repository_id.fetch_add(1, atomic::Ordering::Release));
let git_store = cx.weak_entity();
- let blob_read_limiter = self.blob_read_limiter.clone();
+ let object_read_limiter = self.object_read_limiter.clone();
let repo = cx.new(|cx| {
let mut repo = Repository::local(
id,
@@ -2930,7 +2930,7 @@ impl GitStore {
fs,
is_trusted,
git_store,
- blob_read_limiter,
+ object_read_limiter,
cx,
);
if let Some(updates_tx) = updates_tx.as_ref() {
@@ -3399,7 +3399,7 @@ impl GitStore {
.map(|p| Path::new(p).into());
let mut repo_subscription = None;
- let blob_read_limiter = this.blob_read_limiter.clone();
+ let object_read_limiter = this.object_read_limiter.clone();
let repo = this.repositories.entry(id).or_insert_with(|| {
let git_store = cx.weak_entity();
let repo = cx.new(|cx| {
@@ -3412,7 +3412,7 @@ impl GitStore {
ProjectId(update.project_id),
client,
git_store,
- blob_read_limiter,
+ object_read_limiter,
cx,
)
});
@@ -4404,11 +4404,17 @@ impl GitStore {
let repository_id = RepositoryId::from_proto(envelope.payload.repository_id);
let repository_handle = Self::repository_for_request(&this, repository_id, &mut cx)?;
+ let commit = envelope.payload.commit;
let commit = repository_handle
- .update(&mut cx, |repository_handle, _| {
- repository_handle.show(envelope.payload.commit)
+ .update(&mut cx, |repository_handle, cx| {
+ if commit.parse::<Oid>().is_ok() {
+ repository_handle.show_commit(commit, cx)
+ } else {
+ let show = repository_handle.show(commit);
+ cx.background_spawn(async move { show.await? })
+ }
})
- .await??;
+ .await?;
Ok(proto::GitCommitDetails {
sha: commit.sha.into(),
message: commit.message.into(),
@@ -4552,13 +4558,14 @@ impl GitStore {
let repository_handle = Self::repository_for_request(&this, repository_id, &mut cx)?;
let commit_diff = repository_handle
- .update(&mut cx, |repository_handle, _| {
+ .update(&mut cx, |repository_handle, cx| {
repository_handle.load_commit_diff(
envelope.payload.commit,
envelope.payload.ignore_shallow_boundary,
+ cx,
)
})
- .await??;
+ .await?;
Ok(proto::LoadCommitDiffResponse {
files: commit_diff
.files
@@ -6540,7 +6547,7 @@ impl Repository {
fs: Arc<dyn Fs>,
is_trusted: bool,
git_store: WeakEntity<GitStore>,
- blob_read_limiter: Arc<Semaphore>,
+ object_read_limiter: Arc<Semaphore>,
cx: &mut Context<Self>,
) -> Self {
let snapshot = RepositorySnapshot::empty(
@@ -6555,7 +6562,7 @@ impl Repository {
let mut repo = Repository {
this: cx.weak_entity(),
git_store,
- blob_read_limiter,
+ object_read_limiter,
snapshot,
unshallow_state: UnshallowState::default(),
pending_ops: Default::default(),
@@ -6587,7 +6594,7 @@ impl Repository {
project_id: ProjectId,
client: AnyProtoClient,
git_store: WeakEntity<GitStore>,
- blob_read_limiter: Arc<Semaphore>,
+ object_read_limiter: Arc<Semaphore>,
cx: &mut Context<Self>,
) -> Self {
let snapshot = RepositorySnapshot::empty(
@@ -6610,7 +6617,7 @@ impl Repository {
unshallow_state: UnshallowState::default(),
commit_message_buffer: None,
git_store,
- blob_read_limiter,
+ object_read_limiter,
pending_ops: Default::default(),
paths_needing_status_update: Default::default(),
job_sender,
@@ -7165,42 +7172,65 @@ impl Repository {
pub fn show(&mut self, commit: String) -> oneshot::Receiver<Result<CommitDetails>> {
let id = self.id;
- self.send_job("show", None, move |git_repo, _cx| async move {
- match git_repo {
- RepositoryState::Local(LocalRepositoryState { backend, .. }) => {
- backend.show(commit).await
- }
- RepositoryState::Remote(RemoteRepositoryState { project_id, client }) => {
- let resp = client
- .request(proto::GitShow {
- project_id: project_id.0,
- repository_id: id.to_proto(),
- commit,
- })
- .await?;
+ self.send_job("show", None, move |state, _cx| {
+ Self::show_internal(state, id, commit)
+ })
+ }
- Ok(CommitDetails {
- sha: resp.sha.into(),
- message: resp.message.into(),
- commit_timestamp: resp.commit_timestamp,
- author_email: resp.author_email.into(),
- author_name: resp.author_name.into(),
+ pub fn show_commit(&self, sha: String, cx: &App) -> Task<Result<CommitDetails>> {
+ let id = self.id;
+ let repository_state = self.repository_state.clone();
+ let object_read_limiter = self.object_read_limiter.clone();
+ cx.background_spawn(async move {
+ let _permit = object_read_limiter.acquire_arc().await;
+ let state = repository_state.await.map_err(|err| anyhow::anyhow!(err))?;
+ Self::show_internal(state, id, sha).await
+ })
+ }
+
+ async fn show_internal(
+ state: RepositoryState,
+ id: RepositoryId,
+ commit: String,
+ ) -> Result<CommitDetails> {
+ match state {
+ RepositoryState::Local(LocalRepositoryState { backend, .. }) => {
+ backend.show(commit).await
+ }
+ RepositoryState::Remote(RemoteRepositoryState { project_id, client }) => {
+ let resp = client
+ .request(proto::GitShow {
+ project_id: project_id.0,
+ repository_id: id.to_proto(),
+ commit,
})
- }
+ .await?;
+
+ Ok(CommitDetails {
+ sha: resp.sha.into(),
+ message: resp.message.into(),
+ commit_timestamp: resp.commit_timestamp,
+ author_email: resp.author_email.into(),
+ author_name: resp.author_name.into(),
+ })
}
- })
+ }
}
pub fn load_commit_diff(
- &mut self,
+ &self,
commit: String,
ignore_shallow_boundary: bool,
- ) -> oneshot::Receiver<Result<CommitDiff>> {
+ cx: &App,
+ ) -> Task<Result<CommitDiff>> {
let id = self.id;
- self.send_job("load_commit_diff", None, move |git_repo, cx| async move {
- match git_repo {
+ let repository_state = self.repository_state.clone();
+ let object_read_limiter = self.object_read_limiter.clone();
+ cx.spawn(async move |cx| {
+ let _permit = object_read_limiter.acquire_arc().await;
+ match repository_state.await.map_err(|err| anyhow::anyhow!(err))? {
RepositoryState::Local(LocalRepositoryState { backend, .. }) => backend
- .load_commit(commit, ignore_shallow_boundary, cx)
+ .load_commit(commit, ignore_shallow_boundary, cx.clone())
.await
.map(decode_commit_diff),
RepositoryState::Remote(RemoteRepositoryState {
@@ -10400,9 +10430,9 @@ impl Repository {
fn load_blob_content(&self, oid: Oid, cx: &App) -> Task<Result<String>> {
let repository_id = self.snapshot.id;
let repository_state = self.repository_state.clone();
- let blob_read_limiter = self.blob_read_limiter.clone();
+ let object_read_limiter = self.object_read_limiter.clone();
cx.background_spawn(async move {
- let _permit = blob_read_limiter.acquire_arc().await;
+ let _permit = object_read_limiter.acquire_arc().await;
match repository_state.await.map_err(|err| anyhow::anyhow!(err))? {
RepositoryState::Local(LocalRepositoryState { backend, .. }) => {
decode_git_text(backend.load_blob_content(oid).await?)
@@ -11928,7 +11958,7 @@ mod tests {
async fn test_blob_reads_are_bounded(cx: &mut TestAppContext) {
init_test(cx);
let (gate, repository, oids) =
- setup_gated_blob_reads(cx, MAX_CONCURRENT_BLOB_READS + 4).await;
+ setup_gated_blob_reads(cx, MAX_CONCURRENT_OBJECT_READS + 4).await;
let reads = oids
.iter()
@@ -11938,8 +11968,8 @@ mod tests {
.collect::<Vec<_>>();
cx.run_until_parked();
- assert_eq!(gate.peak_concurrent(), MAX_CONCURRENT_BLOB_READS);
- assert_eq!(gate.waiting(), MAX_CONCURRENT_BLOB_READS);
+ assert_eq!(gate.peak_concurrent(), MAX_CONCURRENT_OBJECT_READS);
+ assert_eq!(gate.waiting(), MAX_CONCURRENT_OBJECT_READS);
gate.open();
cx.run_until_parked();
@@ -11952,19 +11982,19 @@ mod tests {
async fn test_cancelled_blob_read_releases_permit(cx: &mut TestAppContext) {
init_test(cx);
let (gate, repository, oids) =
- setup_gated_blob_reads(cx, MAX_CONCURRENT_BLOB_READS + 1).await;
+ setup_gated_blob_reads(cx, MAX_CONCURRENT_OBJECT_READS + 1).await;
- let mut holding = oids[..MAX_CONCURRENT_BLOB_READS]
+ let mut holding = oids[..MAX_CONCURRENT_OBJECT_READS]
.iter()
.map(|oid| {
repository.update(cx, |repository, cx| repository.load_blob_content(*oid, cx))
})
.collect::<Vec<_>>();
cx.run_until_parked();
- assert_eq!(gate.waiting(), MAX_CONCURRENT_BLOB_READS);
+ assert_eq!(gate.waiting(), MAX_CONCURRENT_OBJECT_READS);
// One more read can't get a permit, so it never reaches the backend.
- let blocked_oid = oids[MAX_CONCURRENT_BLOB_READS];
+ let blocked_oid = oids[MAX_CONCURRENT_OBJECT_READS];
let _blocked = repository.update(cx, |repository, cx| {
repository.load_blob_content(blocked_oid, cx)
});
@@ -11976,8 +12006,89 @@ mod tests {
cx.run_until_parked();
assert!(gate.is_waiting(blocked_oid));
assert!(!gate.is_waiting(cancelled_oid));
- assert_eq!(gate.waiting(), MAX_CONCURRENT_BLOB_READS);
- assert_eq!(gate.peak_concurrent(), MAX_CONCURRENT_BLOB_READS);
+ assert_eq!(gate.waiting(), MAX_CONCURRENT_OBJECT_READS);
+ assert_eq!(gate.peak_concurrent(), MAX_CONCURRENT_OBJECT_READS);
+
+ gate.open();
+ cx.run_until_parked();
+ }
+
+ #[gpui::test]
+ async fn test_commit_reads_do_not_wait_on_job_queue(cx: &mut TestAppContext) {
+ init_test(cx);
+ let (_gate, repository, oids) = setup_gated_blob_reads(cx, 1).await;
+ let sha = oids[0].to_string();
+
+ // Hold the serial job queue the way an in-flight fetch does.
+ let (release_tx, release_rx) = oneshot::channel::<()>();
+ let held = repository.update(cx, |repository, _| {
+ repository.send_job("hold", None, move |_, _| async move {
+ release_rx.await.ok();
+ })
+ });
+
+ let details =
+ repository.update(cx, |repository, cx| repository.show_commit(sha.clone(), cx));
+ let diff = repository.update(cx, |repository, cx| {
+ repository.load_commit_diff(sha.clone(), false, cx)
+ });
+ let mut by_ref = repository.update(cx, |repository, _| repository.show(sha.clone()));
+ cx.run_until_parked();
+
+ let details = details
+ .now_or_never()
+ .expect("show_commit waited on the job queue")
+ .unwrap();
+ assert_eq!(details.sha.as_ref(), sha);
+ diff.now_or_never()
+ .expect("load_commit_diff waited on the job queue")
+ .unwrap();
+ assert!(
+ (&mut by_ref).now_or_never().is_none(),
+ "show skipped the job queue"
+ );
+
+ release_tx.send(()).ok();
+ held.await.unwrap();
+ cx.run_until_parked();
+ assert_eq!(by_ref.await.unwrap().unwrap().sha.as_ref(), sha);
+ }
+
+ #[gpui::test]
+ async fn test_commit_reads_share_object_read_limit(cx: &mut TestAppContext) {
+ init_test(cx);
+ let (gate, repository, oids) =
+ setup_gated_blob_reads(cx, MAX_CONCURRENT_OBJECT_READS).await;
+ let sha = oids[0].to_string();
+
+ let _holding = oids
+ .iter()
+ .map(|oid| {
+ repository.update(cx, |repository, cx| repository.load_blob_content(*oid, cx))
+ })
+ .collect::<Vec<_>>();
+ cx.run_until_parked();
+ assert_eq!(gate.waiting(), MAX_CONCURRENT_OBJECT_READS);
+
+ let mut details =
+ repository.update(cx, |repository, cx| repository.show_commit(sha.clone(), cx));
+ let mut diff = repository.update(cx, |repository, cx| {
+ repository.load_commit_diff(sha, false, cx)
+ });
+ cx.run_until_parked();
+ assert!(
+ (&mut details).now_or_never().is_none(),
+ "show_commit skipped the object read limit"
+ );
+ assert!(
+ (&mut diff).now_or_never().is_none(),
+ "load_commit_diff skipped the object read limit"
+ );
+
+ gate.release(oids[0]);
+ cx.run_until_parked();
+ details.await.unwrap();
+ diff.await.unwrap();
gate.open();
cx.run_until_parked();