Move buffer diff storage from BufferStore to GitStore (#26795)

Release Notes:

- N/A

---------

Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
Co-authored-by: max <max@zed.dev>
This commit is contained in:
João Marcos
2025-03-17 17:02:32 +00:00
committed by GitHub
co-authored by Max Brunsfeld max
parent 3d1ae68f83
commit 011f823f33
13 changed files with 1395 additions and 1279 deletions
File diff suppressed because it is too large Load Diff
+996 -78
View File
File diff suppressed because it is too large Load Diff
+22 -13
View File
@@ -665,6 +665,7 @@ impl Hover {
enum EntitySubscription {
Project(PendingEntitySubscription<Project>),
BufferStore(PendingEntitySubscription<BufferStore>),
GitStore(PendingEntitySubscription<GitStore>),
WorktreeStore(PendingEntitySubscription<WorktreeStore>),
LspStore(PendingEntitySubscription<LspStore>),
SettingsObserver(PendingEntitySubscription<SettingsObserver>),
@@ -863,7 +864,6 @@ impl Project {
buffer_store.clone(),
environment.clone(),
fs.clone(),
client.clone().into(),
cx,
)
});
@@ -992,7 +992,6 @@ impl Project {
buffer_store.clone(),
environment.clone(),
ssh_proto.clone(),
ProjectId(SSH_PROJECT_ID),
cx,
)
});
@@ -1109,6 +1108,7 @@ impl Project {
let subscriptions = [
EntitySubscription::Project(client.subscribe_to_entity::<Self>(remote_id)?),
EntitySubscription::BufferStore(client.subscribe_to_entity::<BufferStore>(remote_id)?),
EntitySubscription::GitStore(client.subscribe_to_entity::<GitStore>(remote_id)?),
EntitySubscription::WorktreeStore(
client.subscribe_to_entity::<WorktreeStore>(remote_id)?,
),
@@ -1137,7 +1137,7 @@ impl Project {
async fn from_join_project_response(
response: TypedEnvelope<proto::JoinProjectResponse>,
subscriptions: [EntitySubscription; 5],
subscriptions: [EntitySubscription; 6],
client: Arc<Client>,
run_tasks: bool,
user_store: Entity<UserStore>,
@@ -1254,7 +1254,7 @@ impl Project {
remote_id,
replica_id,
},
git_store,
git_store: git_store.clone(),
buffers_needing_diff: Default::default(),
git_diff_debouncer: DebouncedDelay::new(),
terminals: Terminals {
@@ -1284,6 +1284,9 @@ impl Project {
EntitySubscription::WorktreeStore(subscription) => {
subscription.set_entity(&worktree_store, &mut cx)
}
EntitySubscription::GitStore(subscription) => {
subscription.set_entity(&git_store, &mut cx)
}
EntitySubscription::SettingsObserver(subscription) => {
subscription.set_entity(&settings_observer, &mut cx)
}
@@ -1874,6 +1877,9 @@ impl Project {
self.settings_observer.update(cx, |settings_observer, cx| {
settings_observer.shared(project_id, self.client.clone().into(), cx)
});
self.git_store.update(cx, |git_store, cx| {
git_store.shared(project_id, self.client.clone().into(), cx)
});
self.client_state = ProjectClientState::Shared {
remote_id: project_id,
@@ -1955,6 +1961,9 @@ impl Project {
self.settings_observer.update(cx, |settings_observer, cx| {
settings_observer.unshared(cx);
});
self.git_store.update(cx, |git_store, cx| {
git_store.unshared(cx);
});
self.client
.send(proto::UnshareProject {
@@ -2180,10 +2189,8 @@ impl Project {
if self.is_disconnected(cx) {
return Task::ready(Err(anyhow!(ErrorCode::Disconnected)));
}
self.buffer_store.update(cx, |buffer_store, cx| {
buffer_store.open_unstaged_diff(buffer, cx)
})
self.git_store
.update(cx, |git_store, cx| git_store.open_unstaged_diff(buffer, cx))
}
pub fn open_uncommitted_diff(
@@ -2194,9 +2201,8 @@ impl Project {
if self.is_disconnected(cx) {
return Task::ready(Err(anyhow!(ErrorCode::Disconnected)));
}
self.buffer_store.update(cx, |buffer_store, cx| {
buffer_store.open_uncommitted_diff(buffer, cx)
self.git_store.update(cx, |git_store, cx| {
git_store.open_uncommitted_diff(buffer, cx)
})
}
@@ -2755,8 +2761,8 @@ impl Project {
if buffers.is_empty() {
None
} else {
Some(this.buffer_store.update(cx, |buffer_store, cx| {
buffer_store.recalculate_buffer_diffs(buffers, cx)
Some(this.git_store.update(cx, |git_store, cx| {
git_store.recalculate_buffer_diffs(buffers, cx)
}))
}
})
@@ -4008,6 +4014,9 @@ impl Project {
buffer.update(cx, |buffer, cx| buffer.remove_peer(replica_id, cx));
}
});
this.git_store.update(cx, |git_store, _| {
git_store.forget_shared_diffs_for(&peer_id);
});
cx.emit(Event::CollaboratorLeft(peer_id));
Ok(())
+2 -8
View File
@@ -6414,8 +6414,6 @@ async fn test_staging_lots_of_hunks_fast(cx: &mut gpui::TestAppContext) {
.await
.unwrap();
let range = Anchor::MIN..snapshot.anchor_after(snapshot.max_point());
let mut expected_hunks: Vec<(Range<u32>, String, String, DiffHunkStatus)> = (0..500)
.step_by(5)
.map(|i| {
@@ -6444,9 +6442,7 @@ async fn test_staging_lots_of_hunks_fast(cx: &mut gpui::TestAppContext) {
// Stage every hunk with a different call
uncommitted_diff.update(cx, |diff, cx| {
let hunks = diff
.hunks_intersecting_range(range.clone(), &snapshot, cx)
.collect::<Vec<_>>();
let hunks = diff.hunks(&snapshot, cx).collect::<Vec<_>>();
for hunk in hunks {
diff.stage_or_unstage_hunks(true, &[hunk], &snapshot, true, cx);
}
@@ -6480,9 +6476,7 @@ async fn test_staging_lots_of_hunks_fast(cx: &mut gpui::TestAppContext) {
// Unstage every hunk with a different call
uncommitted_diff.update(cx, |diff, cx| {
let hunks = diff
.hunks_intersecting_range(range, &snapshot, cx)
.collect::<Vec<_>>();
let hunks = diff.hunks(&snapshot, cx).collect::<Vec<_>>();
for hunk in hunks {
diff.stage_or_unstage_hunks(false, &[hunk], &snapshot, true, cx);
}