From b2a0a7fa3c9fbfc393692fe81c830603c2370a7d Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Tue, 25 Jun 2024 10:03:29 -0700 Subject: [PATCH] Fix a bug introduced by #13479 (#13516) Fixes a bug introduced by https://github.com/zed-industries/zed/pull/13479 where dot files might not be processed in the correct order. Release Notes: - N/A --- crates/worktree/src/worktree.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rs index 056e00585d..1672d9f8da 100644 --- a/crates/worktree/src/worktree.rs +++ b/crates/worktree/src/worktree.rs @@ -3826,7 +3826,8 @@ impl BackgroundScanner { .await; // Ensure that .git and .gitignore are processed first. - child_paths.sort_unstable(); + swap_to_front(&mut child_paths, *GITIGNORE); + swap_to_front(&mut child_paths, *DOT_GIT); for child_abs_path in child_paths { let child_abs_path: Arc = child_abs_path.into(); @@ -4620,6 +4621,16 @@ impl BackgroundScanner { } } +fn swap_to_front(child_paths: &mut Vec, file: &OsStr) { + let position = child_paths + .iter() + .position(|path| path.file_name().unwrap() == file); + if let Some(position) = position { + let temp = child_paths.remove(position); + child_paths.insert(0, temp); + } +} + fn char_bag_for_path(root_char_bag: CharBag, path: &Path) -> CharBag { let mut result = root_char_bag; result.extend(