working_copy: drop optimization for exec-bit-only change

When updating the working copy from one tree to another, if only the
executable bit has changed between the two trees, we set the
executable bit on the file without touching its contents. The
optimization probably gets used quite rarely. Maybe it's even so
rarely that it's a pessimization overall. Perhaps its value lies more
in that we avoid updating the file's mtime unnecessarily. Either way,
I'm about to change this code to use `Merge<Option<TreeValue>>` and
that will make this block more complex. I don't think it's worth the
complexity even it provides some small benefit sometimes.
This commit is contained in:
Martin von Zweigbergk 2023-08-16 23:12:45 -07:00 committed by Martin von Zweigbergk
parent 89b7b0bfe8
commit 2151fd8930

View file

@ -114,13 +114,6 @@ impl FileState {
size: 0,
}
}
#[cfg(unix)]
fn mark_executable(&mut self, executable: bool) {
if let FileType::Normal { .. } = &self.file_type {
self.file_type = FileType::Normal { executable }
}
}
}
pub struct TreeState {
@ -1251,23 +1244,6 @@ impl TreeState {
self.file_states.remove(&path);
stats.removed_files += 1;
}
(
Some(TreeValue::File {
id: old_id,
executable: old_executable,
}),
Some(TreeValue::File { id, executable }),
) if id == old_id => {
// Optimization for when only the executable bit changed
assert_ne!(executable, old_executable);
#[cfg(unix)]
{
self.set_executable(&disk_path, executable)?;
let file_state = self.file_states.get_mut(&path).unwrap();
file_state.mark_executable(executable);
}
stats.updated_files += 1;
}
(before, Some(after)) => {
if before.is_some() {
fs::remove_file(&disk_path).ok();