Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
git_store: Coalesce refresh pathspecs (#56406)
Henrique Ferreirobc823dbbbd62
diff --git a/crates/project/src/git_store.rs b/crates/project/src/git_store.rsindex f5a62baa4c3..5df59cbd182 100644--- a/crates/project/src/git_store.rs+++ b/crates/project/src/git_store.rs@@ -3661,6 +3661,23 @@ impl GitStore {.collect()}+ fn coalesce_repo_paths(mut paths: Vec<RepoPath>) -> Vec<RepoPath> {+ paths.sort();++ let mut coalesced = Vec::with_capacity(paths.len());+ for path in paths {+ if coalesced+ .last()+ .is_some_and(|ancestor: &RepoPath| path.starts_with(ancestor))+ {+ continue;+ }+ coalesced.push(path);+ }++ coalesced+ }+fn process_updated_entries(&self,worktree: &Entity<Worktree>,@@ -3737,6 +3754,10 @@ impl GitStore {}}+ for paths in paths_by_git_repo.values_mut() {+ *paths = Self::coalesce_repo_paths(mem::take(paths));+ }+paths_by_git_repo})}@@ -8915,6 +8936,7 @@ mod tests {use super::*;use crate::Project;use fs::FakeFs;+ use git::repository::{RepoPath, repo_path};use gpui::TestAppContext;use gpui::proptest::prelude::*;use rand::{SeedableRng, rngs::StdRng};@@ -9259,6 +9281,43 @@ mod tests {);});}++ fn repo_paths(paths: &[&str]) -> Vec<RepoPath> {+ paths.iter().map(repo_path).collect()+ }++ #[test]+ fn coalesce_repo_paths_keeps_root_only() {+ let coalesced = GitStore::coalesce_repo_paths(repo_paths(&["", "src", "src/lib.rs"]));++ assert_eq!(coalesced, repo_paths(&[""]));+ }++ #[test]+ fn coalesce_repo_paths_keeps_existing_ancestors() {+ let coalesced = GitStore::coalesce_repo_paths(repo_paths(&[+ "src",+ "src/lib.rs",+ "src/nested/file.rs",+ "tests/test.rs",+ ]));++ assert_eq!(coalesced, repo_paths(&["src", "tests/test.rs"]));+ }++ #[test]+ fn coalesce_repo_paths_does_not_invent_missing_parents() {+ let coalesced = GitStore::coalesce_repo_paths(repo_paths(&[+ "submodule/a.txt",+ "submodule/nested/b.txt",+ "top_level.rs",+ ]));++ assert_eq!(+ coalesced,+ repo_paths(&["submodule/a.txt", "submodule/nested/b.txt", "top_level.rs"])+ );+ }}/// This snapshot computes the repository state on the foreground thread while