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:
parent
1e8b50f471
commit
6924720b35
22 changed files with 1387 additions and 1399 deletions
|
@ -3,10 +3,7 @@ use gpui::{
|
|||
};
|
||||
use itertools::Itertools;
|
||||
use picker::{Picker, PickerDelegate};
|
||||
use project::{
|
||||
git_store::{GitStore, Repository},
|
||||
Project,
|
||||
};
|
||||
use project::{git_store::Repository, Project};
|
||||
use std::sync::Arc;
|
||||
use ui::{prelude::*, ListItem, ListItemSpacing};
|
||||
use workspace::{ModalView, Workspace};
|
||||
|
@ -40,21 +37,23 @@ impl RepositorySelector {
|
|||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
let git_store = project_handle.read(cx).git_store().clone();
|
||||
let repository_entries = git_store.update(cx, |git_store, cx| {
|
||||
filtered_repository_entries(git_store, cx)
|
||||
let repository_entries = git_store.update(cx, |git_store, _cx| {
|
||||
git_store
|
||||
.repositories()
|
||||
.values()
|
||||
.cloned()
|
||||
.collect::<Vec<_>>()
|
||||
});
|
||||
let project = project_handle.read(cx);
|
||||
let filtered_repositories = repository_entries.clone();
|
||||
|
||||
let widest_item_ix = repository_entries.iter().position_max_by(|a, b| {
|
||||
a.read(cx)
|
||||
.display_name(project, cx)
|
||||
.display_name()
|
||||
.len()
|
||||
.cmp(&b.read(cx).display_name(project, cx).len())
|
||||
.cmp(&b.read(cx).display_name().len())
|
||||
});
|
||||
|
||||
let delegate = RepositorySelectorDelegate {
|
||||
project: project_handle.downgrade(),
|
||||
repository_selector: cx.entity().downgrade(),
|
||||
repository_entries,
|
||||
filtered_repositories,
|
||||
|
@ -71,36 +70,36 @@ impl RepositorySelector {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn filtered_repository_entries(
|
||||
git_store: &GitStore,
|
||||
cx: &App,
|
||||
) -> Vec<Entity<Repository>> {
|
||||
let repositories = git_store
|
||||
.repositories()
|
||||
.values()
|
||||
.sorted_by_key(|repo| {
|
||||
let repo = repo.read(cx);
|
||||
(
|
||||
repo.dot_git_abs_path.clone(),
|
||||
repo.worktree_abs_path.clone(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<&Entity<Repository>>>();
|
||||
|
||||
repositories
|
||||
.chunk_by(|a, b| a.read(cx).dot_git_abs_path == b.read(cx).dot_git_abs_path)
|
||||
.flat_map(|chunk| {
|
||||
let has_non_single_file_worktree = chunk
|
||||
.iter()
|
||||
.any(|repo| !repo.read(cx).is_from_single_file_worktree);
|
||||
chunk.iter().filter(move |repo| {
|
||||
// Remove any entry that comes from a single file worktree and represents a repository that is also represented by a non-single-file worktree.
|
||||
!repo.read(cx).is_from_single_file_worktree || !has_non_single_file_worktree
|
||||
})
|
||||
})
|
||||
.map(|&repo| repo.clone())
|
||||
.collect()
|
||||
}
|
||||
//pub(crate) fn filtered_repository_entries(
|
||||
// git_store: &GitStore,
|
||||
// cx: &App,
|
||||
//) -> Vec<Entity<Repository>> {
|
||||
// let repositories = git_store
|
||||
// .repositories()
|
||||
// .values()
|
||||
// .sorted_by_key(|repo| {
|
||||
// let repo = repo.read(cx);
|
||||
// (
|
||||
// repo.dot_git_abs_path.clone(),
|
||||
// repo.worktree_abs_path.clone(),
|
||||
// )
|
||||
// })
|
||||
// .collect::<Vec<&Entity<Repository>>>();
|
||||
//
|
||||
// repositories
|
||||
// .chunk_by(|a, b| a.read(cx).dot_git_abs_path == b.read(cx).dot_git_abs_path)
|
||||
// .flat_map(|chunk| {
|
||||
// let has_non_single_file_worktree = chunk
|
||||
// .iter()
|
||||
// .any(|repo| !repo.read(cx).is_from_single_file_worktree);
|
||||
// chunk.iter().filter(move |repo| {
|
||||
// // Remove any entry that comes from a single file worktree and represents a repository that is also represented by a non-single-file worktree.
|
||||
// !repo.read(cx).is_from_single_file_worktree || !has_non_single_file_worktree
|
||||
// })
|
||||
// })
|
||||
// .map(|&repo| repo.clone())
|
||||
// .collect()
|
||||
//}
|
||||
|
||||
impl EventEmitter<DismissEvent> for RepositorySelector {}
|
||||
|
||||
|
@ -119,7 +118,6 @@ impl Render for RepositorySelector {
|
|||
impl ModalView for RepositorySelector {}
|
||||
|
||||
pub struct RepositorySelectorDelegate {
|
||||
project: WeakEntity<Project>,
|
||||
repository_selector: WeakEntity<RepositorySelector>,
|
||||
repository_entries: Vec<Entity<Repository>>,
|
||||
filtered_repositories: Vec<Entity<Repository>>,
|
||||
|
@ -225,9 +223,8 @@ impl PickerDelegate for RepositorySelectorDelegate {
|
|||
_window: &mut Window,
|
||||
cx: &mut Context<Picker<Self>>,
|
||||
) -> Option<Self::ListItem> {
|
||||
let project = self.project.upgrade()?;
|
||||
let repo_info = self.filtered_repositories.get(ix)?;
|
||||
let display_name = repo_info.read(cx).display_name(project.read(cx), cx);
|
||||
let display_name = repo_info.read(cx).display_name();
|
||||
Some(
|
||||
ListItem::new(ix)
|
||||
.inset(true)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue