Refactor Repository::status_for_path to return FileStatus instead of StatusEntry

This commit is contained in:
Michael Sloan 2025-08-25 22:01:36 -06:00
parent b696a32518
commit b40794d413
No known key found for this signature in database
5 changed files with 24 additions and 40 deletions

View file

@ -3072,12 +3072,7 @@ async fn test_git_status_sync(
.collect::<Vec<_>>(); .collect::<Vec<_>>();
assert_eq!(repos.len(), 1); assert_eq!(repos.len(), 1);
let repo = repos.into_iter().next().unwrap(); let repo = repos.into_iter().next().unwrap();
assert_eq!( assert_eq!(repo.read(cx).status_for_path(&file.into()), status);
repo.read(cx)
.status_for_path(&file.into())
.map(|entry| entry.status),
status
);
} }
project_local.read_with(cx_a, |project, cx| { project_local.read_with(cx_a, |project, cx| {

View file

@ -685,7 +685,7 @@ impl Item for Editor {
.git_store() .git_store()
.read(cx) .read(cx)
.repository_and_path_for_buffer_id(buffer_id, cx)?; .repository_and_path_for_buffer_id(buffer_id, cx)?;
let status = repo.read(cx).status_for_path(&repo_path)?.status; let status = repo.read(cx).status_for_path(&repo_path)?;
Some(entry_git_aware_label_color( Some(entry_git_aware_label_color(
status.summary(), status.summary(),

View file

@ -2693,9 +2693,7 @@ impl OutlinePanel {
let status = git_store let status = git_store
.read(cx) .read(cx)
.repository_and_path_for_buffer_id(buffer_id, cx) .repository_and_path_for_buffer_id(buffer_id, cx)
.and_then(|(repo, path)| { .and_then(|(repo, path)| Some(repo.read(cx).status_for_path(&path)?));
Some(repo.read(cx).status_for_path(&path)?.status)
});
buffer_excerpts buffer_excerpts
.entry(buffer_id) .entry(buffer_id)
.or_insert_with(|| { .or_insert_with(|| {

View file

@ -809,7 +809,7 @@ impl GitStore {
cx: &App, cx: &App,
) -> Option<FileStatus> { ) -> Option<FileStatus> {
let (repo, repo_path) = self.repository_and_path_for_project_path(project_path, cx)?; let (repo, repo_path) = self.repository_and_path_for_project_path(project_path, cx)?;
Some(repo.read(cx).status_for_path(&repo_path)?.status) Some(repo.read(cx).status_for_path(&repo_path)?)
} }
pub fn checkpoint(&self, cx: &mut App) -> Task<Result<GitStoreCheckpoint>> { pub fn checkpoint(&self, cx: &mut App) -> Task<Result<GitStoreCheckpoint>> {
@ -1391,8 +1391,7 @@ impl GitStore {
pub fn status_for_buffer_id(&self, buffer_id: BufferId, cx: &App) -> Option<FileStatus> { pub fn status_for_buffer_id(&self, buffer_id: BufferId, cx: &App) -> Option<FileStatus> {
let (repo, path) = self.repository_and_path_for_buffer_id(buffer_id, cx)?; let (repo, path) = self.repository_and_path_for_buffer_id(buffer_id, cx)?;
let status = repo.read(cx).snapshot.status_for_path(&path)?; repo.read(cx).snapshot.status_for_path(&path)
Some(status.status)
} }
pub fn repository_and_path_for_buffer_id( pub fn repository_and_path_for_buffer_id(
@ -2844,10 +2843,10 @@ impl RepositorySnapshot {
self.statuses_by_path.summary().item_summary self.statuses_by_path.summary().item_summary
} }
pub fn status_for_path(&self, path: &RepoPath) -> Option<StatusEntry> { pub fn status_for_path(&self, path: &RepoPath) -> Option<FileStatus> {
self.statuses_by_path self.statuses_by_path
.get(&PathKey(path.0.clone()), &()) .get(&PathKey(path.0.clone()), &())
.cloned() .map(|entry| entry.status.clone())
} }
pub fn abs_path_to_repo_path(&self, abs_path: &Path) -> Option<RepoPath> { pub fn abs_path_to_repo_path(&self, abs_path: &Path) -> Option<RepoPath> {
@ -2874,7 +2873,7 @@ impl RepositorySnapshot {
self.merge.conflicted_paths.contains(repo_path); self.merge.conflicted_paths.contains(repo_path);
let has_conflict_currently = self let has_conflict_currently = self
.status_for_path(repo_path) .status_for_path(repo_path)
.is_some_and(|entry| entry.status.is_conflicted()); .is_some_and(|status| status.is_conflicted());
had_conflict_on_last_merge_head_change || has_conflict_currently had_conflict_on_last_merge_head_change || has_conflict_currently
} }

View file

@ -8246,7 +8246,7 @@ async fn test_repository_subfolder_git_status(
assert_eq!(repository.status_for_path(&C_TXT.into()), None); assert_eq!(repository.status_for_path(&C_TXT.into()), None);
assert_eq!( assert_eq!(
repository.status_for_path(&E_TXT.into()).unwrap().status, repository.status_for_path(&E_TXT.into()).unwrap(),
FileStatus::Untracked FileStatus::Untracked
); );
}); });
@ -8459,15 +8459,11 @@ async fn test_rename_work_directory(cx: &mut gpui::TestAppContext) {
root_path.join("projects/project1").as_path() root_path.join("projects/project1").as_path()
); );
assert_eq!( assert_eq!(
repository repository.status_for_path(&"a".into()),
.status_for_path(&"a".into())
.map(|entry| entry.status),
Some(StatusCode::Modified.worktree()), Some(StatusCode::Modified.worktree()),
); );
assert_eq!( assert_eq!(
repository repository.status_for_path(&"b".into()),
.status_for_path(&"b".into())
.map(|entry| entry.status),
Some(FileStatus::Untracked), Some(FileStatus::Untracked),
); );
}); });
@ -8485,11 +8481,11 @@ async fn test_rename_work_directory(cx: &mut gpui::TestAppContext) {
root_path.join("projects/project2").as_path() root_path.join("projects/project2").as_path()
); );
assert_eq!( assert_eq!(
repository.status_for_path(&"a".into()).unwrap().status, repository.status_for_path(&"a".into()).unwrap(),
StatusCode::Modified.worktree(), StatusCode::Modified.worktree(),
); );
assert_eq!( assert_eq!(
repository.status_for_path(&"b".into()).unwrap().status, repository.status_for_path(&"b".into()).unwrap(),
FileStatus::Untracked, FileStatus::Untracked,
); );
}); });
@ -8562,11 +8558,11 @@ async fn test_file_status(cx: &mut gpui::TestAppContext) {
); );
assert_eq!( assert_eq!(
repository.status_for_path(&B_TXT.into()).unwrap().status, repository.status_for_path(&B_TXT.into()).unwrap(),
FileStatus::Untracked, FileStatus::Untracked,
); );
assert_eq!( assert_eq!(
repository.status_for_path(&F_TXT.into()).unwrap().status, repository.status_for_path(&F_TXT.into()).unwrap(),
FileStatus::Untracked, FileStatus::Untracked,
); );
}); });
@ -8582,7 +8578,7 @@ async fn test_file_status(cx: &mut gpui::TestAppContext) {
// The worktree detects that the file's git status has changed. // The worktree detects that the file's git status has changed.
repository.read_with(cx, |repository, _| { repository.read_with(cx, |repository, _| {
assert_eq!( assert_eq!(
repository.status_for_path(&A_TXT.into()).unwrap().status, repository.status_for_path(&A_TXT.into()).unwrap(),
StatusCode::Modified.worktree(), StatusCode::Modified.worktree(),
); );
}); });
@ -8600,7 +8596,7 @@ async fn test_file_status(cx: &mut gpui::TestAppContext) {
// The worktree detects that the files' git status have changed. // The worktree detects that the files' git status have changed.
repository.read_with(cx, |repository, _cx| { repository.read_with(cx, |repository, _cx| {
assert_eq!( assert_eq!(
repository.status_for_path(&F_TXT.into()).unwrap().status, repository.status_for_path(&F_TXT.into()).unwrap(),
FileStatus::Untracked, FileStatus::Untracked,
); );
assert_eq!(repository.status_for_path(&B_TXT.into()), None); assert_eq!(repository.status_for_path(&B_TXT.into()), None);
@ -8623,11 +8619,11 @@ async fn test_file_status(cx: &mut gpui::TestAppContext) {
repository.read_with(cx, |repository, _cx| { repository.read_with(cx, |repository, _cx| {
assert_eq!(repository.status_for_path(&A_TXT.into()), None); assert_eq!(repository.status_for_path(&A_TXT.into()), None);
assert_eq!( assert_eq!(
repository.status_for_path(&B_TXT.into()).unwrap().status, repository.status_for_path(&B_TXT.into()).unwrap(),
FileStatus::Untracked, FileStatus::Untracked,
); );
assert_eq!( assert_eq!(
repository.status_for_path(&E_TXT.into()).unwrap().status, repository.status_for_path(&E_TXT.into()).unwrap(),
StatusCode::Modified.worktree(), StatusCode::Modified.worktree(),
); );
}); });
@ -8666,8 +8662,7 @@ async fn test_file_status(cx: &mut gpui::TestAppContext) {
assert_eq!( assert_eq!(
repository repository
.status_for_path(&Path::new(renamed_dir_name).join(RENAMED_FILE).into()) .status_for_path(&Path::new(renamed_dir_name).join(RENAMED_FILE).into())
.unwrap() .unwrap(),
.status,
FileStatus::Untracked, FileStatus::Untracked,
); );
}); });
@ -8690,8 +8685,7 @@ async fn test_file_status(cx: &mut gpui::TestAppContext) {
assert_eq!( assert_eq!(
repository repository
.status_for_path(&Path::new(renamed_dir_name).join(RENAMED_FILE).into()) .status_for_path(&Path::new(renamed_dir_name).join(RENAMED_FILE).into())
.unwrap() .unwrap(),
.status,
FileStatus::Untracked, FileStatus::Untracked,
); );
}); });
@ -9000,7 +8994,7 @@ async fn test_git_worktrees_and_submodules(cx: &mut gpui::TestAppContext) {
barrier.await.unwrap(); barrier.await.unwrap();
worktree_repo.update(cx, |repo, _| { worktree_repo.update(cx, |repo, _| {
pretty_assertions::assert_eq!( pretty_assertions::assert_eq!(
repo.status_for_path(&"src/b.txt".into()).unwrap().status, repo.status_for_path(&"src/b.txt".into()).unwrap(),
StatusCode::Modified.worktree(), StatusCode::Modified.worktree(),
); );
}); });
@ -9039,7 +9033,7 @@ async fn test_git_worktrees_and_submodules(cx: &mut gpui::TestAppContext) {
barrier.await.unwrap(); barrier.await.unwrap();
submodule_repo.update(cx, |repo, _| { submodule_repo.update(cx, |repo, _| {
pretty_assertions::assert_eq!( pretty_assertions::assert_eq!(
repo.status_for_path(&"c.txt".into()).unwrap().status, repo.status_for_path(&"c.txt".into()).unwrap(),
StatusCode::Modified.worktree(), StatusCode::Modified.worktree(),
); );
}); });
@ -9300,9 +9294,7 @@ fn assert_entry_git_state(
let entry = tree let entry = tree
.entry_for_path(path) .entry_for_path(path)
.unwrap_or_else(|| panic!("entry {path} not found")); .unwrap_or_else(|| panic!("entry {path} not found"));
let status = repository let status = repository.status_for_path(&path.into()).map(|entry| entry);
.status_for_path(&path.into())
.map(|entry| entry.status);
let expected = index_status.map(|index_status| { let expected = index_status.map(|index_status| {
TrackedStatus { TrackedStatus {
index_status, index_status,