Skip to content

Commit

Permalink
working_copy: delete path() method from trait
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
martinvonz committed Aug 16, 2024
1 parent 237b41e commit 749a284
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
18 changes: 10 additions & 8 deletions cli/examples/custom-working-copy/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ fn main() -> std::process::ExitCode {
/// file to the working copy.
struct ConflictsWorkingCopy {
inner: Box<dyn WorkingCopy>,
working_copy_path: PathBuf,
}

impl ConflictsWorkingCopy {
Expand All @@ -110,20 +111,22 @@ impl ConflictsWorkingCopy {
) -> Result<Self, WorkingCopyStateError> {
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<Store>, 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,
}
}
}
Expand All @@ -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()
}
Expand All @@ -160,7 +159,7 @@ impl WorkingCopy for ConflictsWorkingCopy {
fn start_mutation(&self) -> Result<Box<dyn LockedWorkingCopy>, 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,
}))
}
Expand Down Expand Up @@ -261,6 +260,9 @@ impl LockedWorkingCopy for LockedConflictsWorkingCopy {
operation_id: OperationId,
) -> Result<Box<dyn WorkingCopy>, WorkingCopyStateError> {
let inner = self.inner.finish(operation_id)?;
Ok(Box::new(ConflictsWorkingCopy { inner }))
Ok(Box::new(ConflictsWorkingCopy {
inner,
working_copy_path: self.wc_path,
}))
}
}
4 changes: 0 additions & 4 deletions lib/src/local_working_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 1 addition & 4 deletions lib/src/working_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion lib/tests/test_local_working_copy_sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down

0 comments on commit 749a284

Please sign in to comment.