From 9d8702b537f7f1b0a89f56fb15cba688746a0a54 Mon Sep 17 00:00:00 2001 From: Waleed Khan Date: Tue, 25 Jul 2023 09:27:56 -0700 Subject: [PATCH] refactor(working_copy): return new file state from `update_file_state` --- lib/src/working_copy.rs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/src/working_copy.rs b/lib/src/working_copy.rs index 499424d1a..a28ccd205 100644 --- a/lib/src/working_copy.rs +++ b/lib/src/working_copy.rs @@ -396,9 +396,10 @@ pub enum TreeStateError { } enum UpdatedFileState { - Unchanged, + Ignored, + Unchanged(FileState), Deleted, - Changed(TreeValue), + Changed(TreeValue, FileState), } impl TreeState { @@ -692,18 +693,23 @@ impl TreeState { if let Some(progress) = progress { progress(&sub_path); } - let update = self.update_file_state( + let update = self.get_updated_file_state( &sub_path, &entry, git_ignore.as_ref(), ¤t_tree, )?; match update { - UpdatedFileState::Unchanged => {} + UpdatedFileState::Ignored => {} + UpdatedFileState::Unchanged(file_state) => { + self.file_states.insert(sub_path, file_state); + } UpdatedFileState::Deleted => { + self.file_states.remove(&sub_path); tree_builder.remove(sub_path); } - UpdatedFileState::Changed(tree_value) => { + UpdatedFileState::Changed(tree_value, file_state) => { + self.file_states.insert(sub_path.clone(), file_state); tree_builder.set(sub_path, tree_value); } } @@ -802,20 +808,20 @@ impl TreeState { } } - fn update_file_state( - &mut self, + fn get_updated_file_state( + &self, repo_path: &RepoPath, dir_entry: &DirEntry, git_ignore: &GitIgnoreFile, current_tree: &Tree, ) -> Result { - let maybe_current_file_state = self.file_states.get_mut(repo_path); + 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::Unchanged); + return Ok(UpdatedFileState::Ignored); } let disk_path = dir_entry.path(); @@ -827,16 +833,13 @@ impl TreeState { let (current_file_state, new_file_state) = match (maybe_current_file_state, maybe_new_file_state) { (_, None) => { - // Tracked file replaced by Unix socket or such - self.file_states.remove(repo_path); return Ok(UpdatedFileState::Deleted); } (None, Some(new_file_state)) => { // untracked let file_type = new_file_state.file_type.clone(); - self.file_states.insert(repo_path.clone(), new_file_state); let file_value = self.write_path_to_store(repo_path, &disk_path, file_type)?; - return Ok(UpdatedFileState::Changed(file_value)); + return Ok(UpdatedFileState::Changed(file_value, new_file_state)); } (Some(current_file_state), Some(new_file_state)) => { (current_file_state, new_file_state) @@ -855,7 +858,6 @@ impl TreeState { // then we don't know if the file was modified before or after this state file. if current_file_state != &new_file_state || current_file_state.mtime >= self.own_mtime { let new_file_type = new_file_state.file_type.clone(); - *current_file_state = new_file_state; let current_tree_value = current_tree.path_value(repo_path); // If the file contained a conflict before and is now a normal file on disk, we // try to parse any conflict markers in the file into a conflict. @@ -867,9 +869,9 @@ impl TreeState { } else { self.write_path_to_store(repo_path, &disk_path, new_file_type)? }; - return Ok(UpdatedFileState::Changed(new_tree_value)); + return Ok(UpdatedFileState::Changed(new_tree_value, new_file_state)); } - Ok(UpdatedFileState::Unchanged) + Ok(UpdatedFileState::Unchanged(new_file_state)) } fn write_conflict_to_store(