From 3dd6dfb829cac28f36a07bb2fa59143fe631095a Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Wed, 5 Feb 2025 11:15:16 -0500 Subject: [PATCH] Fix the worktree's repository_for_path (cherry-pick #24279) (#24283) Cherry-picked Fix the worktree's repository_for_path (#24279) Go back to a less optimized implementation for now since the custom cursor target seems to have some bugs. Release Notes: - Fixed missing git blame and status output in some projects with multiple git repositories Co-authored-by: Cole Miller --- crates/worktree/src/worktree.rs | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rs index 77bc78a0be5ce9da4de871f8f75d753fc9c17300..11599bc1f654392f788422ad8adbc93c5f2a9556 100644 --- a/crates/worktree/src/worktree.rs +++ b/crates/worktree/src/worktree.rs @@ -2670,21 +2670,10 @@ impl Snapshot { /// Get the repository whose work directory contains the given path. pub fn repository_for_path(&self, path: &Path) -> Option<&RepositoryEntry> { - let mut cursor = self.repositories.cursor::(&()); - let mut repository = None; - - // Git repositories may contain other git repositories. As a side effect of - // lexicographic sorting by path, deeper repositories will be after higher repositories - // So, let's loop through every matching repository until we can't find any more to find - // the deepest repository that could contain this path. - while cursor.seek_forward(&PathTarget::Contains(path), Bias::Left, &()) - && cursor.item().is_some() - { - repository = cursor.item(); - cursor.next(&()); - } - - repository + self.repositories + .iter() + .filter(|repo| repo.work_directory.directory_contains(path)) + .last() } /// Given an ordered iterator of entries, returns an iterator of those entries, @@ -5976,7 +5965,6 @@ impl<'a> Iterator for Traversal<'a> { enum PathTarget<'a> { Path(&'a Path), Successor(&'a Path), - Contains(&'a Path), } impl<'a> PathTarget<'a> { @@ -5990,13 +5978,6 @@ impl<'a> PathTarget<'a> { Ordering::Equal } } - PathTarget::Contains(path) => { - if path.starts_with(other) { - Ordering::Equal - } else { - Ordering::Greater - } - } } } }