WIP, re-doing fs and fake git repos

This commit is contained in:
Mikayla Maki
2022-09-29 13:16:02 -04:00
committed by Julia
parent d5fd531743
commit 71b2126eca
7 changed files with 145 additions and 50 deletions
+10
View File
@@ -1,6 +1,7 @@
use anyhow::{anyhow, Result};
use fsevent::EventStream;
use futures::{future::BoxFuture, Stream, StreamExt};
use git::repository::{FakeGitRepository, GitRepository, RealGitRepository};
use language::LineEnding;
use smol::io::{AsyncReadExt, AsyncWriteExt};
use std::{
@@ -43,6 +44,7 @@ pub trait Fs: Send + Sync {
path: &Path,
latency: Duration,
) -> Pin<Box<dyn Send + Stream<Item = Vec<fsevent::Event>>>>;
async fn open_repo(&self, abs_dot_git: &Path) -> Option<Box<dyn GitRepository>>;
fn is_fake(&self) -> bool;
#[cfg(any(test, feature = "test-support"))]
fn as_fake(&self) -> &FakeFs;
@@ -236,6 +238,10 @@ impl Fs for RealFs {
})))
}
fn open_repo(&self, abs_dot_git: &Path) -> Option<Box<dyn GitRepository>> {
RealGitRepository::open(&abs_dot_git)
}
fn is_fake(&self) -> bool {
false
}
@@ -847,6 +853,10 @@ impl Fs for FakeFs {
}))
}
fn open_repo(&self, abs_dot_git: &Path) -> Option<Box<dyn GitRepository>> {
Some(FakeGitRepository::open(abs_dot_git.into(), 0))
}
fn is_fake(&self) -> bool {
true
}
+2 -6
View File
@@ -4537,7 +4537,6 @@ 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) => {
println!("{updated_repos:#?}");
this.update_local_worktree_buffers_git_repos(updated_repos, cx)
}
})
@@ -4649,7 +4648,7 @@ impl Project {
fn update_local_worktree_buffers_git_repos(
&mut self,
repos: &[GitRepository],
repos: &[Box<dyn GitRepository>],
cx: &mut ModelContext<Self>,
) {
//TODO: Produce protos
@@ -4662,18 +4661,15 @@ impl Project {
};
let path = file.path().clone();
let abs_path = file.abs_path(cx);
println!("got file");
let repo = match repos.iter().find(|repo| repo.manages(&abs_path)) {
Some(repo) => repo.clone(),
Some(repo) => repo.boxed_clone(),
None => return,
};
println!("got repo");
cx.spawn(|_, mut cx| async move {
let head_text = repo.load_head_text(&path).await;
buffer.update(&mut cx, |buffer, cx| {
println!("got calling update");
buffer.update_head_text(head_text, cx);
});
})
+25 -25
View File
@@ -100,7 +100,7 @@ pub struct Snapshot {
pub struct LocalSnapshot {
abs_path: Arc<Path>,
ignores_by_parent_abs_path: HashMap<Arc<Path>, (Arc<Gitignore>, usize)>,
git_repositories: Vec<GitRepository>,
git_repositories: Vec<Box<dyn GitRepository>>,
removed_entry_ids: HashMap<u64, ProjectEntryId>,
next_entry_id: Arc<AtomicUsize>,
snapshot: Snapshot,
@@ -115,7 +115,7 @@ impl Clone for LocalSnapshot {
git_repositories: self
.git_repositories
.iter()
.map(|repo| repo.clone())
.map(|repo| repo.boxed_clone())
.collect(),
removed_entry_ids: self.removed_entry_ids.clone(),
next_entry_id: self.next_entry_id.clone(),
@@ -157,7 +157,7 @@ struct ShareState {
pub enum Event {
UpdatedEntries,
UpdatedGitRepositories(Vec<GitRepository>),
UpdatedGitRepositories(Vec<Box<dyn GitRepository>>),
}
impl Entity for Worktree {
@@ -581,16 +581,13 @@ impl LocalWorktree {
}
fn list_updated_repos(
old_repos: &[GitRepository],
new_repos: &[GitRepository],
) -> Vec<GitRepository> {
println!("old repos: {:#?}", old_repos);
println!("new repos: {:#?}", new_repos);
old_repos: &[Box<dyn GitRepository>],
new_repos: &[Box<dyn GitRepository>],
) -> Vec<Box<dyn GitRepository>> {
fn diff<'a>(
a: &'a [GitRepository],
b: &'a [GitRepository],
updated: &mut HashMap<&'a Path, GitRepository>,
a: &'a [Box<dyn GitRepository>],
b: &'a [Box<dyn GitRepository>],
updated: &mut HashMap<&'a Path, Box<dyn GitRepository>>,
) {
for a_repo in a {
let matched = b.iter().find(|b_repo| {
@@ -599,17 +596,17 @@ impl LocalWorktree {
});
if matched.is_some() {
updated.insert(a_repo.git_dir_path(), a_repo.clone());
updated.insert(a_repo.git_dir_path(), a_repo.boxed_clone());
}
}
}
let mut updated = HashMap::<&Path, GitRepository>::default();
let mut updated = HashMap::<&Path, Box<dyn GitRepository>>::default();
diff(old_repos, new_repos, &mut updated);
diff(new_repos, old_repos, &mut updated);
dbg!(updated.into_values().collect())
updated.into_values().collect()
}
pub fn scan_complete(&self) -> impl Future<Output = ()> {
@@ -1364,23 +1361,22 @@ impl LocalSnapshot {
}
// Gives the most specific git repository for a given path
pub(crate) fn repo_for(&self, path: &Path) -> Option<GitRepository> {
pub(crate) fn repo_for(&self, path: &Path) -> Option<Box<dyn GitRepository>> {
self.git_repositories
.iter()
.rev() //git_repository is ordered lexicographically
.find(|repo| repo.manages(&self.abs_path.join(path)))
.map(|repo| repo.clone())
.map(|repo| repo.boxed_clone())
}
pub(crate) fn in_dot_git(&mut self, path: &Path) -> Option<&mut GitRepository> {
println!("chechking {path:?}");
pub(crate) fn in_dot_git(&mut self, path: &Path) -> Option<&mut Box<dyn GitRepository>> {
self.git_repositories
.iter_mut()
.rev() //git_repository is ordered lexicographically
.find(|repo| repo.in_dot_git(&self.abs_path.join(path)))
}
pub(crate) fn tracks_filepath(&self, repo: &GitRepository, file_path: &Path) -> bool {
pub(crate) fn _tracks_filepath(&self, repo: &dyn GitRepository, file_path: &Path) -> bool {
// Depends on git_repository_for_file_path returning the most specific git repository for a given path
self.repo_for(&self.abs_path.join(file_path))
.map_or(false, |r| r.git_dir_path() == repo.git_dir_path())
@@ -1522,6 +1518,7 @@ impl LocalSnapshot {
parent_path: Arc<Path>,
entries: impl IntoIterator<Item = Entry>,
ignore: Option<Arc<Gitignore>>,
fs: &dyn Fs,
) {
let mut parent_entry = if let Some(parent_entry) =
self.entries_by_path.get(&PathKey(parent_path.clone()), &())
@@ -1553,7 +1550,7 @@ impl LocalSnapshot {
.git_repositories
.binary_search_by_key(&abs_path.as_path(), |repo| repo.git_dir_path())
{
if let Some(repository) = GitRepository::open(&abs_path) {
if let Some(repository) = fs.open_repo(abs_path.as_path()) {
self.git_repositories.insert(ix, repository);
}
}
@@ -2402,9 +2399,12 @@ impl BackgroundScanner {
new_entries.push(child_entry);
}
self.snapshot
.lock()
.populate_dir(job.path.clone(), new_entries, new_ignore);
self.snapshot.lock().populate_dir(
job.path.clone(),
new_entries,
new_ignore,
self.fs.as_ref(),
);
for new_job in new_jobs {
job.scan_queue.send(new_job).await.unwrap();
}
@@ -2602,7 +2602,7 @@ impl BackgroundScanner {
let new_repos = snapshot
.git_repositories
.iter()
.cloned()
.map(|repo| repo.boxed_clone())
.filter(|repo| git::libgit::Repository::open(repo.git_dir_path()).is_ok())
.collect();