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
parent 9134630841
commit cf7d639fbc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 6480 additions and 6429 deletions

View file

@ -3,7 +3,7 @@ mod color_extractor;
pub mod connection_manager;
pub mod debounced_delay;
pub mod debugger;
pub mod git;
pub mod git_store;
pub mod image_store;
pub mod lsp_command;
pub mod lsp_store;
@ -24,11 +24,12 @@ mod direnv;
mod environment;
use buffer_diff::BufferDiff;
pub use environment::{EnvironmentErrorMessage, ProjectEnvironmentEvent};
use git::Repository;
use git_store::Repository;
pub mod search_history;
mod yarn;
use crate::git::GitStore;
use crate::git_store::GitStore;
pub use git_store::git_traversal::{ChildEntriesGitIter, GitEntry, GitEntryRef, GitTraversal};
use anyhow::{anyhow, Context as _, Result};
use buffer_store::{BufferStore, BufferStoreEvent};
@ -55,7 +56,7 @@ use futures::{
pub use image_store::{ImageItem, ImageStore};
use image_store::{ImageItemEvent, ImageStoreEvent};
use ::git::{blame::Blame, repository::GitRepository, status::FileStatus};
use ::git::{blame::Blame, status::FileStatus};
use gpui::{
AnyEntity, App, AppContext, AsyncApp, BorrowAppContext, Context, Entity, EventEmitter, Hsla,
SharedString, Task, WeakEntity, Window,
@ -1768,8 +1769,9 @@ impl Project {
project_path: &ProjectPath,
cx: &App,
) -> Option<FileStatus> {
self.worktree_for_id(project_path.worktree_id, cx)
.and_then(|worktree| worktree.read(cx).status_for_file(&project_path.path))
self.git_store
.read(cx)
.project_path_git_status(project_path, cx)
}
pub fn visibility_for_paths(
@ -4049,19 +4051,13 @@ impl Project {
)
}
pub fn get_first_worktree_root_repo(&self, cx: &App) -> Option<Arc<dyn GitRepository>> {
let worktree = self.visible_worktrees(cx).next()?.read(cx).as_local()?;
let root_entry = worktree.root_git_entry()?;
worktree.get_local_repo(&root_entry)?.repo().clone().into()
}
pub fn blame_buffer(
&self,
buffer: &Entity<Buffer>,
version: Option<clock::Global>,
cx: &App,
) -> Task<Result<Option<Blame>>> {
self.buffer_store.read(cx).blame_buffer(buffer, version, cx)
self.git_store.read(cx).blame_buffer(buffer, version, cx)
}
pub fn get_permalink_to_line(
@ -4070,7 +4066,7 @@ impl Project {
selection: Range<u32>,
cx: &App,
) -> Task<Result<url::Url>> {
self.buffer_store
self.git_store
.read(cx)
.get_permalink_to_line(buffer, selection, cx)
}