From 6f7547d28f131cf1af5ef59b593d9f813c0a6786 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Mon, 3 Oct 2022 17:18:38 -0700 Subject: [PATCH] Fixed a couple bugs in tests and worktree path handling --- crates/git/src/repository.rs | 1 + crates/project/src/fs.rs | 3 +-- crates/project/src/project.rs | 16 ++++++++------ crates/project/src/worktree.rs | 39 ++++++++++++++++------------------ 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/crates/git/src/repository.rs b/crates/git/src/repository.rs index 67e93416aebb2caa8b3b3d6611a8a5637b0e7ba5..38393dc8a8c4b143e87dc27d68e3e87811696f04 100644 --- a/crates/git/src/repository.rs +++ b/crates/git/src/repository.rs @@ -19,6 +19,7 @@ impl GitRepository for LibGitRepository { fn logic(repo: &LibGitRepository, relative_file_path: &Path) -> Result> { const STAGE_NORMAL: i32 = 0; let index = repo.index()?; + dbg!(relative_file_path); let oid = match index.get_path(relative_file_path, STAGE_NORMAL) { Some(entry) => entry.id, None => return Ok(None), diff --git a/crates/project/src/fs.rs b/crates/project/src/fs.rs index a43f18ca640c68da051e1c58008d4861921d1ca6..812842a354c10f9ec4e035edd8ec5c1744a0f6db 100644 --- a/crates/project/src/fs.rs +++ b/crates/project/src/fs.rs @@ -888,8 +888,7 @@ impl Fs for FakeFs { } fn open_repo(&self, abs_dot_git: &Path) -> Option>> { - let executor = self.executor.upgrade().unwrap(); - executor.block(async move { + smol::block_on(async move { let state = self.state.lock().await; let entry = state.read_path(abs_dot_git).await.unwrap(); let mut entry = entry.lock().await; diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 7ce9b4608597a82f0e2c27d86092e0db206aea9e..dc783f181834cb074867c5096f6f818c4ad95f2f 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -4541,7 +4541,7 @@ impl Project { cx.subscribe(worktree, |this, worktree, event, cx| match event { worktree::Event::UpdatedEntries => this.update_local_worktree_buffers(worktree, cx), worktree::Event::UpdatedGitRepositories(updated_repos) => { - this.update_local_worktree_buffers_git_repos(updated_repos, cx) + this.update_local_worktree_buffers_git_repos(worktree, updated_repos, cx) } }) .detach(); @@ -4652,21 +4652,23 @@ impl Project { fn update_local_worktree_buffers_git_repos( &mut self, + worktree: ModelHandle, repos: &[GitRepositoryEntry], cx: &mut ModelContext, ) { - //TODO: Produce protos - for (_, buffer) in &self.opened_buffers { if let Some(buffer) = buffer.upgrade(cx) { - let file = match buffer.read(cx).file().and_then(|file| file.as_local()) { + let file = match File::from_dyn(buffer.read(cx).file()) { Some(file) => file, - None => return, + None => continue, }; + if file.worktree != worktree { + continue; + } + let path = file.path().clone(); - let abs_path = file.abs_path(cx); - let repo = match repos.iter().find(|repo| repo.manages(&abs_path)) { + let repo = match repos.iter().find(|repo| repo.manages(&path)) { Some(repo) => repo.clone(), None => return, }; diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index 1016e58b739805b1e25c853b7c185b1301e366e5..fb07bd837f3ed1ce1e8a2a8cc30c7bf7fa9f537a 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -41,6 +41,7 @@ use std::{ ffi::{OsStr, OsString}, fmt, future::Future, + mem, ops::{Deref, DerefMut}, os::unix::prelude::{OsStrExt, OsStringExt}, path::{Path, PathBuf}, @@ -664,6 +665,13 @@ impl LocalWorktree { let snapshot = self.snapshot(); let settings = cx.global::(); + + // Cut files included because we want to ship! + // TODO: + // - Rename / etc. setting to be show/hide git gutters + // - Unconditionally load index text for all files, + // - then choose at rendering time based on settings + let files_included = settings.git_gutter().files_included(settings); cx.spawn(|this, mut cx| async move { @@ -1379,6 +1387,7 @@ impl LocalSnapshot { // Gives the most specific git repository for a given path pub(crate) fn repo_for(&self, path: &Path) -> Option { + dbg!(&self.git_repositories); self.git_repositories .iter() .rev() //git_repository is ordered lexicographically @@ -1557,7 +1566,7 @@ impl LocalSnapshot { if parent_path.file_name() == Some(&DOT_GIT) { let abs_path = self.abs_path.join(&parent_path); - let content_path: Arc = abs_path.parent().unwrap().into(); + let content_path: Arc = parent_path.parent().unwrap().into(); if let Err(ix) = self .git_repositories .binary_search_by_key(&&content_path, |repo| &repo.content_path) @@ -1716,6 +1725,7 @@ impl LocalSnapshot { impl GitRepositoryEntry { // Note that these paths should be relative to the worktree root. pub(crate) fn manages(&self, path: &Path) -> bool { + dbg!(path, &self.content_path); path.starts_with(self.content_path.as_ref()) } @@ -2566,7 +2576,7 @@ impl BackgroundScanner { self.snapshot.lock().removed_entry_ids.clear(); self.update_ignore_statuses().await; - self.update_git_repositories().await; + self.update_git_repositories(); true } @@ -2632,25 +2642,11 @@ impl BackgroundScanner { .await; } - // TODO: Clarify what is going on here because re-loading every git repository - // on every file system event seems wrong - async fn update_git_repositories(&self) { + fn update_git_repositories(&self) { let mut snapshot = self.snapshot.lock(); - - let new_repos = snapshot - .git_repositories - .iter() - .cloned() - .filter_map(|mut repo_entry| { - let repo = self - .fs - .open_repo(&snapshot.abs_path.join(&repo_entry.git_dir_path))?; - repo_entry.repo = repo; - Some(repo_entry) - }) - .collect(); - - snapshot.git_repositories = new_repos; + let mut git_repositories = mem::take(&mut snapshot.git_repositories); + git_repositories.retain(|repo| snapshot.entry_for_path(&repo.git_dir_path).is_some()); + snapshot.git_repositories = git_repositories; } async fn update_ignore_status(&self, job: UpdateIgnoreStatusJob, snapshot: &LocalSnapshot) { @@ -3245,7 +3241,8 @@ mod tests { "b.txt": "" } }, - "c.txt": "" + "c.txt": "", + })); let http_client = FakeHttpClient::with_404_response();