From 5b4e58d1de35b92e55931f52283e0c05bac6bca1 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Wed, 3 May 2023 08:40:22 -0700 Subject: [PATCH] Fix repo_for and clean up repository_entries --- crates/project/src/worktree.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index dcece4f484..e197e0ffad 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -1472,9 +1472,20 @@ impl Snapshot { impl LocalSnapshot { pub(crate) fn repo_for(&self, path: &Path) -> Option { - dbg!(&self.repository_entries) - .closest(&RepositoryWorkDirectory(path.into())) - .map(|(_, entry)| entry.to_owned()) + let mut max_len = 0; + let mut current_candidate = None; + for (work_directory, repo) in (&self.repository_entries).iter() { + if work_directory.contains(path) { + if work_directory.0.as_os_str().len() > max_len { + current_candidate = Some(repo); + max_len = work_directory.0.as_os_str().len(); + } else { + break; + } + } + } + + current_candidate.map(|entry| entry.to_owned()) } pub(crate) fn repo_for_metadata( @@ -2373,8 +2384,13 @@ impl BackgroundScanner { git_repositories.retain(|project_entry_id, _| snapshot.contains_entry(*project_entry_id)); snapshot.git_repositories = git_repositories; + let mut git_repository_entries = mem::take(&mut snapshot.snapshot.repository_entries); + git_repository_entries.retain(|_, entry| snapshot.contains_entry(entry.git_dir_entry_id)); + snapshot.snapshot.repository_entries = git_repository_entries; + snapshot.removed_entry_ids.clear(); snapshot.completed_scan_id = snapshot.scan_id; + drop(snapshot); self.send_status_update(false, None);