Fixed a couple bugs in tests and worktree path handling
This commit is contained in:
parent
6f6d72890a
commit
6f7547d28f
4 changed files with 30 additions and 31 deletions
|
@ -19,6 +19,7 @@ impl GitRepository for LibGitRepository {
|
||||||
fn logic(repo: &LibGitRepository, relative_file_path: &Path) -> Result<Option<String>> {
|
fn logic(repo: &LibGitRepository, relative_file_path: &Path) -> Result<Option<String>> {
|
||||||
const STAGE_NORMAL: i32 = 0;
|
const STAGE_NORMAL: i32 = 0;
|
||||||
let index = repo.index()?;
|
let index = repo.index()?;
|
||||||
|
dbg!(relative_file_path);
|
||||||
let oid = match index.get_path(relative_file_path, STAGE_NORMAL) {
|
let oid = match index.get_path(relative_file_path, STAGE_NORMAL) {
|
||||||
Some(entry) => entry.id,
|
Some(entry) => entry.id,
|
||||||
None => return Ok(None),
|
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>>> {
|
fn open_repo(&self, abs_dot_git: &Path) -> Option<Arc<SyncMutex<dyn GitRepository>>> {
|
||||||
let executor = self.executor.upgrade().unwrap();
|
smol::block_on(async move {
|
||||||
executor.block(async move {
|
|
||||||
let state = self.state.lock().await;
|
let state = self.state.lock().await;
|
||||||
let entry = state.read_path(abs_dot_git).await.unwrap();
|
let entry = state.read_path(abs_dot_git).await.unwrap();
|
||||||
let mut entry = entry.lock().await;
|
let mut entry = entry.lock().await;
|
||||||
|
|
|
@ -4541,7 +4541,7 @@ impl Project {
|
||||||
cx.subscribe(worktree, |this, worktree, event, cx| match event {
|
cx.subscribe(worktree, |this, worktree, event, cx| match event {
|
||||||
worktree::Event::UpdatedEntries => this.update_local_worktree_buffers(worktree, cx),
|
worktree::Event::UpdatedEntries => this.update_local_worktree_buffers(worktree, cx),
|
||||||
worktree::Event::UpdatedGitRepositories(updated_repos) => {
|
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();
|
.detach();
|
||||||
|
@ -4652,21 +4652,23 @@ impl Project {
|
||||||
|
|
||||||
fn update_local_worktree_buffers_git_repos(
|
fn update_local_worktree_buffers_git_repos(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
worktree: ModelHandle<Worktree>,
|
||||||
repos: &[GitRepositoryEntry],
|
repos: &[GitRepositoryEntry],
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) {
|
) {
|
||||||
//TODO: Produce protos
|
|
||||||
|
|
||||||
for (_, buffer) in &self.opened_buffers {
|
for (_, buffer) in &self.opened_buffers {
|
||||||
if let Some(buffer) = buffer.upgrade(cx) {
|
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,
|
Some(file) => file,
|
||||||
None => return,
|
None => continue,
|
||||||
};
|
};
|
||||||
let path = file.path().clone();
|
if file.worktree != worktree {
|
||||||
let abs_path = file.abs_path(cx);
|
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(),
|
Some(repo) => repo.clone(),
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,6 +41,7 @@ use std::{
|
||||||
ffi::{OsStr, OsString},
|
ffi::{OsStr, OsString},
|
||||||
fmt,
|
fmt,
|
||||||
future::Future,
|
future::Future,
|
||||||
|
mem,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
os::unix::prelude::{OsStrExt, OsStringExt},
|
os::unix::prelude::{OsStrExt, OsStringExt},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
@ -664,6 +665,13 @@ impl LocalWorktree {
|
||||||
let snapshot = self.snapshot();
|
let snapshot = self.snapshot();
|
||||||
|
|
||||||
let settings = cx.global::<Settings>();
|
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);
|
let files_included = settings.git_gutter().files_included(settings);
|
||||||
|
|
||||||
cx.spawn(|this, mut cx| async move {
|
cx.spawn(|this, mut cx| async move {
|
||||||
|
@ -1379,6 +1387,7 @@ impl LocalSnapshot {
|
||||||
|
|
||||||
// Gives the most specific git repository for a given path
|
// Gives the most specific git repository for a given path
|
||||||
pub(crate) fn repo_for(&self, path: &Path) -> Option<GitRepositoryEntry> {
|
pub(crate) fn repo_for(&self, path: &Path) -> Option<GitRepositoryEntry> {
|
||||||
|
dbg!(&self.git_repositories);
|
||||||
self.git_repositories
|
self.git_repositories
|
||||||
.iter()
|
.iter()
|
||||||
.rev() //git_repository is ordered lexicographically
|
.rev() //git_repository is ordered lexicographically
|
||||||
|
@ -1557,7 +1566,7 @@ impl LocalSnapshot {
|
||||||
|
|
||||||
if parent_path.file_name() == Some(&DOT_GIT) {
|
if parent_path.file_name() == Some(&DOT_GIT) {
|
||||||
let abs_path = self.abs_path.join(&parent_path);
|
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
|
if let Err(ix) = self
|
||||||
.git_repositories
|
.git_repositories
|
||||||
.binary_search_by_key(&&content_path, |repo| &repo.content_path)
|
.binary_search_by_key(&&content_path, |repo| &repo.content_path)
|
||||||
|
@ -1716,6 +1725,7 @@ impl LocalSnapshot {
|
||||||
impl GitRepositoryEntry {
|
impl GitRepositoryEntry {
|
||||||
// Note that these paths should be relative to the worktree root.
|
// Note that these paths should be relative to the worktree root.
|
||||||
pub(crate) fn manages(&self, path: &Path) -> bool {
|
pub(crate) fn manages(&self, path: &Path) -> bool {
|
||||||
|
dbg!(path, &self.content_path);
|
||||||
path.starts_with(self.content_path.as_ref())
|
path.starts_with(self.content_path.as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2566,7 +2576,7 @@ impl BackgroundScanner {
|
||||||
self.snapshot.lock().removed_entry_ids.clear();
|
self.snapshot.lock().removed_entry_ids.clear();
|
||||||
|
|
||||||
self.update_ignore_statuses().await;
|
self.update_ignore_statuses().await;
|
||||||
self.update_git_repositories().await;
|
self.update_git_repositories();
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2632,25 +2642,11 @@ impl BackgroundScanner {
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Clarify what is going on here because re-loading every git repository
|
fn update_git_repositories(&self) {
|
||||||
// on every file system event seems wrong
|
|
||||||
async fn update_git_repositories(&self) {
|
|
||||||
let mut snapshot = self.snapshot.lock();
|
let mut snapshot = self.snapshot.lock();
|
||||||
|
let mut git_repositories = mem::take(&mut snapshot.git_repositories);
|
||||||
let new_repos = snapshot
|
git_repositories.retain(|repo| snapshot.entry_for_path(&repo.git_dir_path).is_some());
|
||||||
.git_repositories
|
snapshot.git_repositories = 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update_ignore_status(&self, job: UpdateIgnoreStatusJob, snapshot: &LocalSnapshot) {
|
async fn update_ignore_status(&self, job: UpdateIgnoreStatusJob, snapshot: &LocalSnapshot) {
|
||||||
|
@ -3245,7 +3241,8 @@ mod tests {
|
||||||
"b.txt": ""
|
"b.txt": ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"c.txt": ""
|
"c.txt": "",
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let http_client = FakeHttpClient::with_404_response();
|
let http_client = FakeHttpClient::with_404_response();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue