Migrate most callers of git-related worktree APIs to use the GitStore (#27225)

This is a pure refactoring PR that goes through all the git-related APIs
exposed by the worktree crate and minimizes their use outside that
crate, migrating callers of those APIs to read from the GitStore
instead. This is to prepare for evacuating git repository state from
worktrees and making the GitStore the new source of truth.

Other drive-by changes:

- `project::git` is now `project::git_store`, for consistency with the
other project stores
- the project panel's test module has been split into its own file

Release Notes:

- N/A

---------

Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
Cole Miller
2025-03-21 00:10:17 -04:00
committed by GitHub
co-authored by Max Brunsfeld
parent 9134630841
commit cf7d639fbc
26 changed files with 6480 additions and 6429 deletions
+9 -7
View File
@@ -629,18 +629,20 @@ impl Item for Editor {
self.buffer()
.read(cx)
.as_singleton()
.and_then(|buffer| buffer.read(cx).project_path(cx))
.and_then(|path| {
.and_then(|buffer| {
let buffer = buffer.read(cx);
let path = buffer.project_path(cx)?;
let buffer_id = buffer.remote_id();
let project = self.project.as_ref()?.read(cx);
let entry = project.entry_for_path(&path, cx)?;
let git_status = project
.worktree_for_id(path.worktree_id, cx)?
let (repo, repo_path) = project
.git_store()
.read(cx)
.snapshot()
.status_for_file(path.path)?;
.repository_and_path_for_buffer_id(buffer_id, cx)?;
let status = repo.read(cx).status_for_path(&repo_path)?.status;
Some(entry_git_aware_label_color(
git_status.summary(),
status.summary(),
entry.is_ignored,
params.selected,
))
+9 -6
View File
@@ -137,9 +137,9 @@ pub fn deploy_context_menu(
menu
} else {
// Don't show the context menu if there isn't a project associated with this editor
if editor.project.is_none() {
let Some(project) = editor.project.clone() else {
return;
}
};
let display_map = editor.selections.display_map(cx);
let buffer = &editor.snapshot(window, cx).buffer_snapshot;
@@ -159,10 +159,13 @@ pub fn deploy_context_menu(
.all::<PointUtf16>(cx)
.into_iter()
.any(|s| !s.is_empty());
let has_git_repo = editor.project.as_ref().map_or(false, |project| {
project.update(cx, |project, cx| {
project.get_first_worktree_root_repo(cx).is_some()
})
let has_git_repo = anchor.buffer_id.is_some_and(|buffer_id| {
project
.read(cx)
.git_store()
.read(cx)
.repository_and_path_for_buffer_id(buffer_id, cx)
.is_some()
});
ui::ContextMenu::build(window, cx, |menu, _window, _cx| {