From 749a284354c4ccd10dd1e0c8fc5dfeba62bf9d23 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Fri, 16 Aug 2024 11:51:13 -0700 Subject: [PATCH] working_copy: delete `path()` method from trait We don't currently use the `path()` method. Not all working copies even have a relevant path. For example, working copies on Google's server don't. --- cli/examples/custom-working-copy/main.rs | 18 ++++++++++-------- lib/src/local_working_copy.rs | 4 ---- lib/src/working_copy.rs | 5 +---- lib/tests/test_local_working_copy_sparse.rs | 2 +- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/cli/examples/custom-working-copy/main.rs b/cli/examples/custom-working-copy/main.rs index eaba135c69..af94a61757 100644 --- a/cli/examples/custom-working-copy/main.rs +++ b/cli/examples/custom-working-copy/main.rs @@ -94,6 +94,7 @@ fn main() -> std::process::ExitCode { /// file to the working copy. struct ConflictsWorkingCopy { inner: Box, + working_copy_path: PathBuf, } impl ConflictsWorkingCopy { @@ -110,20 +111,22 @@ impl ConflictsWorkingCopy { ) -> Result { let inner = LocalWorkingCopy::init( store, - working_copy_path, + working_copy_path.clone(), state_path, operation_id, workspace_id, )?; Ok(ConflictsWorkingCopy { inner: Box::new(inner), + working_copy_path, }) } fn load(store: Arc, working_copy_path: PathBuf, state_path: PathBuf) -> Self { - let inner = LocalWorkingCopy::load(store, working_copy_path, state_path); + let inner = LocalWorkingCopy::load(store, working_copy_path.clone(), state_path); ConflictsWorkingCopy { inner: Box::new(inner), + working_copy_path, } } } @@ -137,10 +140,6 @@ impl WorkingCopy for ConflictsWorkingCopy { Self::name() } - fn path(&self) -> &Path { - self.inner.path() - } - fn workspace_id(&self) -> &WorkspaceId { self.inner.workspace_id() } @@ -160,7 +159,7 @@ impl WorkingCopy for ConflictsWorkingCopy { fn start_mutation(&self) -> Result, WorkingCopyStateError> { let inner = self.inner.start_mutation()?; Ok(Box::new(LockedConflictsWorkingCopy { - wc_path: self.inner.path().to_owned(), + wc_path: self.working_copy_path.clone(), inner, })) } @@ -261,6 +260,9 @@ impl LockedWorkingCopy for LockedConflictsWorkingCopy { operation_id: OperationId, ) -> Result, WorkingCopyStateError> { let inner = self.inner.finish(operation_id)?; - Ok(Box::new(ConflictsWorkingCopy { inner })) + Ok(Box::new(ConflictsWorkingCopy { + inner, + working_copy_path: self.wc_path, + })) } } diff --git a/lib/src/local_working_copy.rs b/lib/src/local_working_copy.rs index 9c5ee09c4d..9111c610d3 100644 --- a/lib/src/local_working_copy.rs +++ b/lib/src/local_working_copy.rs @@ -1543,10 +1543,6 @@ impl WorkingCopy for LocalWorkingCopy { Self::name() } - fn path(&self) -> &Path { - &self.working_copy_path - } - fn workspace_id(&self) -> &WorkspaceId { &self.checkout_state().workspace_id } diff --git a/lib/src/working_copy.rs b/lib/src/working_copy.rs index cb52c0e27d..b09c09eb1b 100644 --- a/lib/src/working_copy.rs +++ b/lib/src/working_copy.rs @@ -17,7 +17,7 @@ use std::any::Any; use std::ffi::OsString; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::sync::Arc; use thiserror::Error; @@ -40,9 +40,6 @@ pub trait WorkingCopy: Send { /// implementation when loading a working copy. fn name(&self) -> &str; - /// The working copy's root directory. - fn path(&self) -> &Path; - /// The working copy's workspace ID. fn workspace_id(&self) -> &WorkspaceId; diff --git a/lib/tests/test_local_working_copy_sparse.rs b/lib/tests/test_local_working_copy_sparse.rs index 06d4ccfe4b..422cf89b56 100644 --- a/lib/tests/test_local_working_copy_sparse.rs +++ b/lib/tests/test_local_working_copy_sparse.rs @@ -103,7 +103,7 @@ fn test_sparse_checkout() { // Reload the state to check that it was persisted let wc = LocalWorkingCopy::load( repo.store().clone(), - wc.path().to_path_buf(), + ws.workspace_root().to_path_buf(), wc.state_path().to_path_buf(), ); assert_eq!(