Perform only one git statuses call when reloading a git repo after it changes

Max Brunsfeld created

Change summary

crates/fs/src/repository.rs    | 1 +
crates/project/src/worktree.rs | 9 +++++----
2 files changed, 6 insertions(+), 4 deletions(-)

Detailed changes

crates/fs/src/repository.rs 🔗

@@ -33,6 +33,7 @@ pub trait GitRepository: Send {
     fn statuses(&self) -> Option<TreeMap<RepoPath, GitFileStatus>>;
 
     fn status(&self, path: &RepoPath) -> Result<Option<GitFileStatus>>;
+
     fn branches(&self) -> Result<Vec<Branch>> {
         Ok(vec![])
     }

crates/project/src/worktree.rs 🔗

@@ -2023,6 +2023,9 @@ impl LocalSnapshot {
     ) -> Vec<Arc<Path>> {
         let mut changes = vec![];
         let mut edits = vec![];
+
+        let statuses = repo_ptr.statuses();
+
         for mut entry in self
             .descendent_entries(false, false, &work_directory.0)
             .cloned()
@@ -2030,10 +2033,8 @@ impl LocalSnapshot {
             let Ok(repo_path) = entry.path.strip_prefix(&work_directory.0) else {
                 continue;
             };
-            let git_file_status = repo_ptr
-                .status(&RepoPath(repo_path.into()))
-                .log_err()
-                .flatten();
+            let repo_path = RepoPath(repo_path.to_path_buf());
+            let git_file_status = statuses.as_ref().and_then(|s| s.get(&repo_path).copied());
             if entry.git_status != git_file_status {
                 entry.git_status = git_file_status;
                 changes.push(entry.path.clone());