Move repository state RPC handlers to the GitStore (#27391)

This is another in the series of PRs to make the GitStore own all
repository state and enable better concurrency control for git
repository scans.

After this PR, the `RepositoryEntry`s stored in worktree snapshots are
used only as a staging ground for local GitStores to pull from after
git-related events; non-local worktrees don't store them at all,
although this is not reflected in the types. GitTraversal and other
places that need information about repositories get it from the
GitStore. The GitStore also takes over handling of the new
UpdateRepository and RemoveRepository messages. However, repositories
are still discovered and scanned on a per-worktree basis, and we're
still identifying them by the (worktree-specific) project entry ID of
their working directory.

- [x] Remove WorkDirectory from RepositoryEntry
- [x] Remove worktree IDs from repository-related RPC messages
- [x] Handle UpdateRepository and RemoveRepository RPCs from the
GitStore

Release Notes:

- N/A

---------

Co-authored-by: Max <max@zed.dev>
Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
Cole Miller 2025-03-26 18:23:44 -04:00 committed by GitHub
parent 1e8b50f471
commit 6924720b35
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 1387 additions and 1399 deletions

View file

@ -2240,7 +2240,7 @@ message OpenUncommittedDiffResponse {
message SetIndexText {
uint64 project_id = 1;
uint64 worktree_id = 2;
reserved 2;
uint64 work_directory_id = 3;
string path = 4;
optional string text = 5;
@ -3350,7 +3350,7 @@ message GetPanicFiles {
message GitShow {
uint64 project_id = 1;
uint64 worktree_id = 2;
reserved 2;
uint64 work_directory_id = 3;
string commit = 4;
}
@ -3365,7 +3365,7 @@ message GitCommitDetails {
message GitReset {
uint64 project_id = 1;
uint64 worktree_id = 2;
reserved 2;
uint64 work_directory_id = 3;
string commit = 4;
ResetMode mode = 5;
@ -3377,7 +3377,7 @@ message GitReset {
message GitCheckoutFiles {
uint64 project_id = 1;
uint64 worktree_id = 2;
reserved 2;
uint64 work_directory_id = 3;
string commit = 4;
repeated string paths = 5;
@ -3432,21 +3432,21 @@ message RegisterBufferWithLanguageServers{
message Stage {
uint64 project_id = 1;
uint64 worktree_id = 2;
reserved 2;
uint64 work_directory_id = 3;
repeated string paths = 4;
}
message Unstage {
uint64 project_id = 1;
uint64 worktree_id = 2;
reserved 2;
uint64 work_directory_id = 3;
repeated string paths = 4;
}
message Commit {
uint64 project_id = 1;
uint64 worktree_id = 2;
reserved 2;
uint64 work_directory_id = 3;
optional string name = 4;
optional string email = 5;
@ -3455,13 +3455,13 @@ message Commit {
message OpenCommitMessageBuffer {
uint64 project_id = 1;
uint64 worktree_id = 2;
reserved 2;
uint64 work_directory_id = 3;
}
message Push {
uint64 project_id = 1;
uint64 worktree_id = 2;
reserved 2;
uint64 work_directory_id = 3;
string remote_name = 4;
string branch_name = 5;
@ -3476,14 +3476,14 @@ message Push {
message Fetch {
uint64 project_id = 1;
uint64 worktree_id = 2;
reserved 2;
uint64 work_directory_id = 3;
uint64 askpass_id = 4;
}
message GetRemotes {
uint64 project_id = 1;
uint64 worktree_id = 2;
reserved 2;
uint64 work_directory_id = 3;
optional string branch_name = 4;
}
@ -3498,7 +3498,7 @@ message GetRemotesResponse {
message Pull {
uint64 project_id = 1;
uint64 worktree_id = 2;
reserved 2;
uint64 work_directory_id = 3;
string remote_name = 4;
string branch_name = 5;
@ -3512,7 +3512,7 @@ message RemoteMessageResponse {
message AskPassRequest {
uint64 project_id = 1;
uint64 worktree_id = 2;
reserved 2;
uint64 work_directory_id = 3;
uint64 askpass_id = 4;
string prompt = 5;
@ -3524,27 +3524,27 @@ message AskPassResponse {
message GitGetBranches {
uint64 project_id = 1;
uint64 worktree_id = 2;
reserved 2;
uint64 work_directory_id = 3;
}
message GitCreateBranch {
uint64 project_id = 1;
uint64 worktree_id = 2;
reserved 2;
uint64 work_directory_id = 3;
string branch_name = 4;
}
message GitChangeBranch {
uint64 project_id = 1;
uint64 worktree_id = 2;
reserved 2;
uint64 work_directory_id = 3;
string branch_name = 4;
}
message CheckForPushedCommits {
uint64 project_id = 1;
uint64 worktree_id = 2;
reserved 2;
uint64 work_directory_id = 3;
}
@ -3554,7 +3554,7 @@ message CheckForPushedCommitsResponse {
message GitDiff {
uint64 project_id = 1;
uint64 worktree_id = 2;
reserved 2;
uint64 work_directory_id = 3;
DiffType diff_type = 4;

View file

@ -793,31 +793,6 @@ pub const MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE: usize = 2;
#[cfg(not(any(test, feature = "test-support")))]
pub const MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE: usize = 256;
#[derive(Clone, Debug)]
pub enum WorktreeRelatedMessage {
UpdateWorktree(UpdateWorktree),
UpdateRepository(UpdateRepository),
RemoveRepository(RemoveRepository),
}
impl From<UpdateWorktree> for WorktreeRelatedMessage {
fn from(value: UpdateWorktree) -> Self {
Self::UpdateWorktree(value)
}
}
impl From<UpdateRepository> for WorktreeRelatedMessage {
fn from(value: UpdateRepository) -> Self {
Self::UpdateRepository(value)
}
}
impl From<RemoveRepository> for WorktreeRelatedMessage {
fn from(value: RemoveRepository) -> Self {
Self::RemoveRepository(value)
}
}
pub fn split_worktree_update(mut message: UpdateWorktree) -> impl Iterator<Item = UpdateWorktree> {
let mut done = false;
@ -924,20 +899,6 @@ pub fn split_repository_update(
})
}
pub fn split_worktree_related_message(
message: WorktreeRelatedMessage,
) -> Box<dyn Iterator<Item = WorktreeRelatedMessage> + Send> {
match message {
WorktreeRelatedMessage::UpdateWorktree(message) => {
Box::new(split_worktree_update(message).map(WorktreeRelatedMessage::UpdateWorktree))
}
WorktreeRelatedMessage::UpdateRepository(message) => {
Box::new(split_repository_update(message).map(WorktreeRelatedMessage::UpdateRepository))
}
WorktreeRelatedMessage::RemoveRepository(update) => Box::new([update.into()].into_iter()),
}
}
#[cfg(test)]
mod tests {
use super::*;