From 157154121496a3718734846af6f9b68d97df632b Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Wed, 16 Aug 2023 16:22:59 -0700 Subject: [PATCH] working_copy: combine blocks for updating added/modified paths There's a lot of duplication between the blocks of code for updating modified and added paths. This commit combines them. --- lib/src/working_copy.rs | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/lib/src/working_copy.rs b/lib/src/working_copy.rs index 33cacf1f0..90f6778d9 100644 --- a/lib/src/working_copy.rs +++ b/lib/src/working_copy.rs @@ -1241,7 +1241,10 @@ impl TreeState { } stats.updated_files += 1; } - (None, Some(after)) => { + (before, Some(after)) => { + if before.is_some() { + fs::remove_file(&disk_path).ok(); + } let file_state = match after { TreeValue::File { id, executable } => { self.write_file(&disk_path, &path, &id, executable)? @@ -1257,27 +1260,11 @@ impl TreeState { } }; self.file_states.insert(path, file_state); - stats.added_files += 1; - } - (Some(_before), Some(after)) => { - fs::remove_file(&disk_path).ok(); - let file_state = match after { - TreeValue::File { id, executable } => { - self.write_file(&disk_path, &path, &id, executable)? - } - TreeValue::Symlink(id) => self.write_symlink(&disk_path, &path, &id)?, - TreeValue::Conflict(id) => self.write_conflict(&disk_path, &path, &id)?, - TreeValue::GitSubmodule(_id) => { - println!("ignoring git submodule at {path:?}"); - FileState::for_gitsubmodule() - } - TreeValue::Tree(_id) => { - panic!("unexpected tree entry in diff at {path:?}"); - } - }; - - self.file_states.insert(path, file_state); - stats.updated_files += 1; + if before.is_none() { + stats.added_files += 1; + } else { + stats.updated_files += 1; + } } (None, None) => { unreachable!()