mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-15 16:53:25 +00:00
working_copy: handle ignored files outside of get_updated_file_state()
I want to replace the `DirEntry` argument to `get_updated_file_state()` by a `PathBuf` and a `Metadata`. To avoid always reading the metadata, we need to check for ignored files outside of `get_updated_file_state()`. I also think that gives the call site a nice symmetry in how we use the `git_ignore` for directories (`.matches_all_files_in()`)) and files (`.matches_file()`).
This commit is contained in:
parent
be8d471e76
commit
37d9aae894
1 changed files with 26 additions and 29 deletions
|
@ -409,7 +409,6 @@ pub enum TreeStateError {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum UpdatedFileState {
|
enum UpdatedFileState {
|
||||||
Ignored,
|
|
||||||
Unchanged(FileState),
|
Unchanged(FileState),
|
||||||
Deleted,
|
Deleted,
|
||||||
Changed(TreeValue, FileState),
|
Changed(TreeValue, FileState),
|
||||||
|
@ -706,14 +705,20 @@ impl TreeState {
|
||||||
if let Some(progress) = progress {
|
if let Some(progress) = progress {
|
||||||
progress(&sub_path);
|
progress(&sub_path);
|
||||||
}
|
}
|
||||||
|
let maybe_current_file_state = self.file_states.get(&sub_path);
|
||||||
|
if maybe_current_file_state.is_none()
|
||||||
|
&& git_ignore.matches_file(&sub_path.to_internal_file_string())
|
||||||
|
{
|
||||||
|
// If it wasn't already tracked and it matches the ignored paths, then
|
||||||
|
// ignore it.
|
||||||
|
} else {
|
||||||
let update = self.get_updated_file_state(
|
let update = self.get_updated_file_state(
|
||||||
&sub_path,
|
&sub_path,
|
||||||
&entry,
|
&entry,
|
||||||
git_ignore.as_ref(),
|
maybe_current_file_state,
|
||||||
¤t_tree,
|
¤t_tree,
|
||||||
)?;
|
)?;
|
||||||
match update {
|
match update {
|
||||||
UpdatedFileState::Ignored => {}
|
|
||||||
UpdatedFileState::Unchanged(file_state) => {
|
UpdatedFileState::Unchanged(file_state) => {
|
||||||
self.file_states.insert(sub_path, file_state);
|
self.file_states.insert(sub_path, file_state);
|
||||||
}
|
}
|
||||||
|
@ -730,6 +735,7 @@ impl TreeState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -800,18 +806,9 @@ impl TreeState {
|
||||||
&self,
|
&self,
|
||||||
repo_path: &RepoPath,
|
repo_path: &RepoPath,
|
||||||
dir_entry: &DirEntry,
|
dir_entry: &DirEntry,
|
||||||
git_ignore: &GitIgnoreFile,
|
maybe_current_file_state: Option<&FileState>,
|
||||||
current_tree: &Tree,
|
current_tree: &Tree,
|
||||||
) -> Result<UpdatedFileState, SnapshotError> {
|
) -> Result<UpdatedFileState, SnapshotError> {
|
||||||
let maybe_current_file_state = self.file_states.get(repo_path);
|
|
||||||
if maybe_current_file_state.is_none()
|
|
||||||
&& git_ignore.matches_file(&repo_path.to_internal_file_string())
|
|
||||||
{
|
|
||||||
// If it wasn't already tracked and it matches the ignored paths, then
|
|
||||||
// ignore it.
|
|
||||||
return Ok(UpdatedFileState::Ignored);
|
|
||||||
}
|
|
||||||
|
|
||||||
let disk_path = dir_entry.path();
|
let disk_path = dir_entry.path();
|
||||||
let metadata = dir_entry.metadata().map_err(|err| SnapshotError::IoError {
|
let metadata = dir_entry.metadata().map_err(|err| SnapshotError::IoError {
|
||||||
message: format!("Failed to stat file {}", disk_path.display()),
|
message: format!("Failed to stat file {}", disk_path.display()),
|
||||||
|
|
Loading…
Reference in a new issue