Skip to content

Commit

Permalink
working_copy: use tree rather than file states to detect if directory…
Browse files Browse the repository at this point in the history
… is tracked

This moves us closer towards treating the `file_states` map as purely a cache rather than authoritative state.
  • Loading branch information
arxanas authored and martinvonz committed Jul 28, 2023
1 parent 9d8702b commit 4b635e9
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions lib/src/working_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4b635e9

Please sign in to comment.