Fixed a couple bugs in tests and worktree path handling
This commit is contained in:
@@ -19,6 +19,7 @@ impl GitRepository for LibGitRepository {
|
||||
fn logic(repo: &LibGitRepository, relative_file_path: &Path) -> Result<Option<String>> {
|
||||
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),
|
||||
|
||||
@@ -888,8 +888,7 @@ impl Fs for FakeFs {
|
||||
}
|
||||
|
||||
fn open_repo(&self, abs_dot_git: &Path) -> Option<Arc<SyncMutex<dyn GitRepository>>> {
|
||||
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;
|
||||
|
||||
@@ -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<Worktree>,
|
||||
repos: &[GitRepositoryEntry],
|
||||
cx: &mut ModelContext<Self>,
|
||||
) {
|
||||
//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,
|
||||
};
|
||||
let path = file.path().clone();
|
||||
let abs_path = file.abs_path(cx);
|
||||
if file.worktree != worktree {
|
||||
continue;
|
||||
}
|
||||
|
||||
let repo = match repos.iter().find(|repo| repo.manages(&abs_path)) {
|
||||
let path = file.path().clone();
|
||||
|
||||
let repo = match repos.iter().find(|repo| repo.manages(&path)) {
|
||||
Some(repo) => repo.clone(),
|
||||
None => return,
|
||||
};
|
||||
|
||||
@@ -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::<Settings>();
|
||||
|
||||
// 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<GitRepositoryEntry> {
|
||||
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<Path> = abs_path.parent().unwrap().into();
|
||||
let content_path: Arc<Path> = 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();
|
||||
|
||||
Reference in New Issue
Block a user