ok/jj
1
0
Fork 0
forked from mirrors/jj

working_copy: remove file state for deleted files in only one place

We currently remove the file state for deleted files after walking the
working copy and noticing that the file is not there. However, in the
case of files that have been replaced by special files like Unix
sockets, we delete the file state inside the loop. Let's simplify a
tiny bit by not doing that.
This commit is contained in:
Martin von Zweigbergk 2023-07-31 13:52:09 -07:00 committed by Martin von Zweigbergk
parent 3f23508b5f
commit 035d4bbbae

View file

@ -698,49 +698,43 @@ impl TreeState {
disk_dir: entry.path(),
git_ignore: git_ignore.clone(),
});
} else {
deleted_files.remove(&sub_path);
if matcher.matches(&sub_path) {
if let Some(progress) = progress {
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 metadata =
entry.metadata().map_err(|err| SnapshotError::IoError {
message: format!(
"Failed to stat file {}",
entry.path().display()
),
err,
})?;
if let Some(new_file_state) = file_state(&metadata) {
let update = self.get_updated_file_state(
&sub_path,
entry.path(),
maybe_current_file_state,
&current_tree,
&new_file_state,
)?;
match update {
UpdatedFileState::Unchanged => {
self.file_states.insert(sub_path, new_file_state);
}
UpdatedFileState::Changed(tree_value) => {
self.file_states
.insert(sub_path.clone(), new_file_state);
tree_builder.set(sub_path, tree_value);
}
} else if matcher.matches(&sub_path) {
if let Some(progress) = progress {
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 metadata =
entry.metadata().map_err(|err| SnapshotError::IoError {
message: format!(
"Failed to stat file {}",
entry.path().display()
),
err,
})?;
if let Some(new_file_state) = file_state(&metadata) {
deleted_files.remove(&sub_path);
let update = self.get_updated_file_state(
&sub_path,
entry.path(),
maybe_current_file_state,
&current_tree,
&new_file_state,
)?;
match update {
UpdatedFileState::Unchanged => {
self.file_states.insert(sub_path, new_file_state);
}
UpdatedFileState::Changed(tree_value) => {
self.file_states.insert(sub_path.clone(), new_file_state);
tree_builder.set(sub_path, tree_value);
}
} else {
self.file_states.remove(&sub_path);
tree_builder.remove(sub_path);
}
}
}