Skip to content

Commit

Permalink
Start status update tasks earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeoneToIgnore committed Feb 12, 2025
1 parent 9a5caf6 commit 4873007
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions crates/worktree/src/worktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4695,14 +4695,17 @@ impl BackgroundScanner {
let child_path: Arc<Path> = job.path.join(child_name).into();

if child_name == *DOT_GIT {
let repo = self.state.lock().insert_git_repository(
child_path.clone(),
self.fs.as_ref(),
self.watcher.as_ref(),
);

if let Some(local_repo) = repo {
git_status_update_jobs.push(self.schedule_git_statuses_update(local_repo));
{
let mut state = self.state.lock();
let repo = state.insert_git_repository(
child_path.clone(),
self.fs.as_ref(),
self.watcher.as_ref(),
);
if let Some(local_repo) = repo {
git_status_update_jobs
.push(self.schedule_git_statuses_update(&mut state, local_repo));
}
}
} else if child_name == *GITIGNORE {
match build_gitignore(&child_abs_path, self.fs.as_ref()).await {
Expand Down Expand Up @@ -5234,7 +5237,7 @@ impl BackgroundScanner {
fn update_git_repositories(&self, dot_git_paths: Vec<PathBuf>) -> Task<()> {
log::debug!("reloading repositories: {dot_git_paths:?}");

let mut repos_to_update = Vec::new();
let mut status_updates = Vec::new();
{
let mut state = self.state.lock();
let scan_id = state.snapshot.scan_id;
Expand Down Expand Up @@ -5301,7 +5304,8 @@ impl BackgroundScanner {
}
};

repos_to_update.push(local_repository);
status_updates
.push(self.schedule_git_statuses_update(&mut state, local_repository));
}

// Remove any git repositories whose .git entry no longer exists.
Expand Down Expand Up @@ -5332,10 +5336,6 @@ impl BackgroundScanner {
});
}

let mut status_updates = Vec::new();
for local_repository in repos_to_update {
status_updates.push(self.schedule_git_statuses_update(local_repository));
}
self.executor.spawn(async move {
let _updates_finished: Vec<Result<(), oneshot::Canceled>> =
join_all(status_updates).await;
Expand All @@ -5345,15 +5345,16 @@ impl BackgroundScanner {
/// Update the git statuses for a given batch of entries.
fn schedule_git_statuses_update(
&self,
state: &mut BackgroundScannerState,
local_repository: LocalRepositoryEntry,
) -> oneshot::Receiver<()> {
let repository_name = local_repository.work_directory.display_name();
let path_key = local_repository.work_directory.path_key();

let state = self.state.clone();
let job_state = self.state.clone();
let (tx, rx) = oneshot::channel();

self.state.lock().repository_scans.insert(
state.repository_scans.insert(
path_key.clone(),
self.executor.spawn(async move {
log::trace!("updating git statuses for repo {repository_name}",);
Expand All @@ -5373,7 +5374,7 @@ impl BackgroundScanner {

let t0 = Instant::now();
let mut changed_paths = Vec::new();
let snapshot = state.lock().snapshot.snapshot.clone();
let snapshot = job_state.lock().snapshot.snapshot.clone();

let Some(mut repository) = snapshot.repository(path_key) else {
// happens when a folder is deleted
Expand Down Expand Up @@ -5407,7 +5408,7 @@ impl BackgroundScanner {
}

repository.statuses_by_path = new_entries_by_path;
let mut state = state.lock();
let mut state = job_state.lock();
state
.snapshot
.repositories
Expand Down

0 comments on commit 4873007

Please sign in to comment.