From 4b635e9713b920837cfa0d3bfa919b95504ae9fd Mon Sep 17 00:00:00 2001 From: Waleed Khan Date: Fri, 23 Jun 2023 12:40:41 -0700 Subject: [PATCH] working_copy: use tree rather than file states to detect if directory is tracked This moves us closer towards treating the `file_states` map as purely a cache rather than authoritative state. --- lib/src/working_copy.rs | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/lib/src/working_copy.rs b/lib/src/working_copy.rs index a28ccd205..8a80c2f41 100644 --- a/lib/src/working_copy.rs +++ b/lib/src/working_copy.rs @@ -20,7 +20,6 @@ use std::ffi::OsString; use std::fs; use std::fs::{DirEntry, File, Metadata, OpenOptions}; use std::io::{Read, Write}; -use std::ops::Bound; #[cfg(unix)] use std::os::unix::fs::symlink; #[cfg(unix)] @@ -677,7 +676,7 @@ impl TreeState { // If the whole directory is ignored, skip it unless we're already tracking // some file in it. if git_ignore.matches_all_files_in(&sub_path.to_internal_dir_string()) - && !self.has_files_under(&sub_path) + && current_tree.path_value(&sub_path).is_none() { continue; } @@ -789,25 +788,6 @@ impl TreeState { }) } - fn has_files_under(&self, dir: &RepoPath) -> bool { - // TODO: This is pretty ugly... Also, we should - // optimize it to check exactly the already-tracked files (we know that - // we won't have to consider new files in the directory). - let first_file_in_dir = dir.join(&RepoPathComponent::from("\0")); - match self - .file_states - .range((Bound::Included(&first_file_in_dir), Bound::Unbounded)) - .next() - { - Some((subdir_file, _)) => dir.contains(subdir_file), - None => { - // There are no tracked paths at all after `dir/` in alphabetical order, so - // there are no paths under `dir/`. - false - } - } - } - fn get_updated_file_state( &self, repo_path: &RepoPath,