From 55f75278bccb415b0dafa014b0d0949077c0ff32 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 26 Nov 2023 12:10:23 +0900 Subject: [PATCH] repo_path: make to_internal_file_string() return &str, rename accordingly --- cli/examples/custom-working-copy/main.rs | 2 +- cli/src/diff_util.rs | 2 +- lib/src/local_working_copy.rs | 6 +++--- lib/src/repo_path.rs | 12 ++++++------ lib/tests/test_local_working_copy.rs | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cli/examples/custom-working-copy/main.rs b/cli/examples/custom-working-copy/main.rs index 68c2f1937..2eedc414a 100644 --- a/cli/examples/custom-working-copy/main.rs +++ b/cli/examples/custom-working-copy/main.rs @@ -215,7 +215,7 @@ impl LockedWorkingCopy for LockedConflictsWorkingCopy { let conflicts = commit .tree()? .conflicts() - .map(|(path, _value)| format!("{}\n", path.to_internal_file_string())) + .map(|(path, _value)| format!("{}\n", path.as_internal_file_string())) .join(""); std::fs::write(self.wc_path.join(".conflicts"), conflicts).unwrap(); self.inner.check_out(commit) diff --git a/cli/src/diff_util.rs b/cli/src/diff_util.rs index e77e0de46..79485b1a3 100644 --- a/cli/src/diff_util.rs +++ b/cli/src/diff_util.rs @@ -686,7 +686,7 @@ pub fn show_git_diff( formatter.push_label("diff")?; async { while let Some((path, diff)) = tree_diff.next().await { - let path_string = path.to_internal_file_string(); + let path_string = path.as_internal_file_string(); let (left_value, right_value) = diff?; let left_value = materialize_tree_value(store, &path, left_value).block_on()?; let right_value = materialize_tree_value(store, &path, right_value).block_on()?; diff --git a/lib/src/local_working_copy.rs b/lib/src/local_working_copy.rs index 4f24756e7..5723cc7d8 100644 --- a/lib/src/local_working_copy.rs +++ b/lib/src/local_working_copy.rs @@ -265,7 +265,7 @@ fn file_states_to_proto( .iter() .map( |(path, state)| crate::protos::working_copy::FileStateEntry { - path: path.to_internal_file_string(), + path: path.as_internal_file_string().to_owned(), state: Some(file_state_to_proto(state)), }, ) @@ -538,7 +538,7 @@ impl TreeState { for path in &self.sparse_patterns { sparse_patterns .prefixes - .push(path.to_internal_file_string()); + .push(path.as_internal_file_string().to_owned()); } proto.sparse_patterns = Some(sparse_patterns); proto.watchman_clock = self.watchman_clock.clone(); @@ -862,7 +862,7 @@ impl TreeState { } let maybe_current_file_state = file_states.get(&path); if maybe_current_file_state.is_none() - && git_ignore.matches(&path.to_internal_file_string()) + && git_ignore.matches(path.as_internal_file_string()) { // If it wasn't already tracked and it matches // the ignored paths, then diff --git a/lib/src/repo_path.rs b/lib/src/repo_path.rs index 04dd0332a..cf4fd162a 100644 --- a/lib/src/repo_path.rs +++ b/lib/src/repo_path.rs @@ -246,8 +246,8 @@ impl RepoPath { /// The full string form used internally, not for presenting to users (where /// we may want to use the platform's separator). - pub fn to_internal_file_string(&self) -> String { - self.value.to_owned() + pub fn as_internal_file_string(&self) -> &str { + &self.value } pub fn to_fs_path(&self, base: &Path) -> PathBuf { @@ -362,10 +362,10 @@ mod tests { } #[test] - fn test_to_internal_string() { - assert_eq!(RepoPath::root().to_internal_file_string(), ""); - assert_eq!(repo_path("dir").to_internal_file_string(), "dir"); - assert_eq!(repo_path("dir/file").to_internal_file_string(), "dir/file"); + fn test_as_internal_file_string() { + assert_eq!(RepoPath::root().as_internal_file_string(), ""); + assert_eq!(repo_path("dir").as_internal_file_string(), "dir"); + assert_eq!(repo_path("dir/file").as_internal_file_string(), "dir/file"); } #[test] diff --git a/lib/tests/test_local_working_copy.rs b/lib/tests/test_local_working_copy.rs index 7b4cac267..70b3318e9 100644 --- a/lib/tests/test_local_working_copy.rs +++ b/lib/tests/test_local_working_copy.rs @@ -204,7 +204,7 @@ fn test_checkout_file_transitions(backend: TestRepoBackend) { assert_eq!(new_tree.id(), right_tree_id); for (_left_kind, right_kind, path) in &files { - let wc_path = workspace_root.join(path.to_internal_file_string()); + let wc_path = workspace_root.join(path.as_internal_file_string()); let maybe_metadata = wc_path.symlink_metadata(); match right_kind { Kind::Missing => {