From 5a898b16a8f44989f06864b0626e3f84476f31ed Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Thu, 8 Feb 2024 21:38:29 -0800 Subject: [PATCH] working_copy: handle symlink outside write_path_to_store() The `write_path_to_store()` has almost no overlapping code between the handling of symlinks and regular files, which suggests that we should move out the handling of symlinks to the caller (there's only one). --- lib/src/local_working_copy.rs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/src/local_working_copy.rs b/lib/src/local_working_copy.rs index 4121f0e37..4cfbad781 100644 --- a/lib/src/local_working_copy.rs +++ b/lib/src/local_working_copy.rs @@ -1068,12 +1068,20 @@ impl TreeState { } else { let new_file_type = new_file_state.file_type.clone(); let current_tree_values = current_tree.path_value(repo_path); - let new_tree_values = self.write_path_to_store( - repo_path, - &disk_path, - ¤t_tree_values, - new_file_type, - )?; + let new_tree_values = match new_file_type { + FileType::Normal { executable } => self.write_path_to_store( + repo_path, + &disk_path, + ¤t_tree_values, + executable, + )?, + FileType::Symlink => { + let id = self.write_symlink_to_store(repo_path, &disk_path)?; + Merge::normal(TreeValue::Symlink(id)) + } + FileType::GitSubmodule => panic!("git submodule cannot be written to store"), + }; + if new_tree_values != current_tree_values { Ok(Some(new_tree_values)) } else { @@ -1087,17 +1095,8 @@ impl TreeState { repo_path: &RepoPath, disk_path: &Path, current_tree_values: &MergedTreeValue, - file_type: FileType, + executable: FileExecutableFlag, ) -> Result { - let executable = match file_type { - FileType::Normal { executable } => executable, - FileType::Symlink => { - let id = self.write_symlink_to_store(repo_path, disk_path)?; - return Ok(Merge::normal(TreeValue::Symlink(id))); - } - FileType::GitSubmodule => panic!("git submodule cannot be written to store"), - }; - // 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. if let Some(current_tree_value) = current_tree_values.as_resolved() {