mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-27 06:23:18 +00:00
working_copy: convert Diff
into Options
for matching
This just a little refactoring to make the next step of sharing code between `Modified` and `Added` simpler.
This commit is contained in:
parent
5b8c1e013f
commit
8ded5ae03b
1 changed files with 11 additions and 8 deletions
|
@ -1211,8 +1211,8 @@ impl TreeState {
|
||||||
let disk_path = path.to_fs_path(&self.working_copy_path);
|
let disk_path = path.to_fs_path(&self.working_copy_path);
|
||||||
|
|
||||||
// TODO: Check that the file has not changed before overwriting/removing it.
|
// TODO: Check that the file has not changed before overwriting/removing it.
|
||||||
match diff {
|
match diff.into_options() {
|
||||||
Diff::Removed(_before) => {
|
(Some(_before), None) => {
|
||||||
fs::remove_file(&disk_path).ok();
|
fs::remove_file(&disk_path).ok();
|
||||||
let mut parent_dir = disk_path.parent().unwrap();
|
let mut parent_dir = disk_path.parent().unwrap();
|
||||||
loop {
|
loop {
|
||||||
|
@ -1224,7 +1224,7 @@ impl TreeState {
|
||||||
self.file_states.remove(&path);
|
self.file_states.remove(&path);
|
||||||
stats.removed_files += 1;
|
stats.removed_files += 1;
|
||||||
}
|
}
|
||||||
Diff::Added(after) => {
|
(None, Some(after)) => {
|
||||||
let file_state = match after {
|
let file_state = match after {
|
||||||
TreeValue::File { id, executable } => {
|
TreeValue::File { id, executable } => {
|
||||||
self.write_file(&disk_path, &path, &id, executable)?
|
self.write_file(&disk_path, &path, &id, executable)?
|
||||||
|
@ -1242,12 +1242,12 @@ impl TreeState {
|
||||||
self.file_states.insert(path, file_state);
|
self.file_states.insert(path, file_state);
|
||||||
stats.added_files += 1;
|
stats.added_files += 1;
|
||||||
}
|
}
|
||||||
Diff::Modified(
|
(
|
||||||
TreeValue::File {
|
Some(TreeValue::File {
|
||||||
id: old_id,
|
id: old_id,
|
||||||
executable: old_executable,
|
executable: old_executable,
|
||||||
},
|
}),
|
||||||
TreeValue::File { id, executable },
|
Some(TreeValue::File { id, executable }),
|
||||||
) if id == old_id => {
|
) if id == old_id => {
|
||||||
// Optimization for when only the executable bit changed
|
// Optimization for when only the executable bit changed
|
||||||
assert_ne!(executable, old_executable);
|
assert_ne!(executable, old_executable);
|
||||||
|
@ -1259,7 +1259,7 @@ impl TreeState {
|
||||||
}
|
}
|
||||||
stats.updated_files += 1;
|
stats.updated_files += 1;
|
||||||
}
|
}
|
||||||
Diff::Modified(_before, after) => {
|
(Some(_before), Some(after)) => {
|
||||||
fs::remove_file(&disk_path).ok();
|
fs::remove_file(&disk_path).ok();
|
||||||
let file_state = match after {
|
let file_state = match after {
|
||||||
TreeValue::File { id, executable } => {
|
TreeValue::File { id, executable } => {
|
||||||
|
@ -1279,6 +1279,9 @@ impl TreeState {
|
||||||
self.file_states.insert(path, file_state);
|
self.file_states.insert(path, file_state);
|
||||||
stats.updated_files += 1;
|
stats.updated_files += 1;
|
||||||
}
|
}
|
||||||
|
(None, None) => {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue