diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index b5d5fcec8..6af1c754b 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -63,7 +63,7 @@ use jj_lib::revset::{ use jj_lib::settings::{ConfigResultExt as _, UserSettings}; use jj_lib::transaction::Transaction; use jj_lib::tree::TreeMergeError; -use jj_lib::working_copy::WorkingCopy; +use jj_lib::working_copy::{LockedWorkingCopy, WorkingCopy}; use jj_lib::workspace::{ LockedWorkspace, Workspace, WorkspaceInitError, WorkspaceLoadError, WorkspaceLoader, }; diff --git a/cli/src/commands/mod.rs b/cli/src/commands/mod.rs index b54bb5c04..0d95b056a 100644 --- a/cli/src/commands/mod.rs +++ b/cli/src/commands/mod.rs @@ -48,6 +48,7 @@ use jj_lib::revset_graph::{ }; use jj_lib::rewrite::{back_out_commit, merge_commit_trees, rebase_commit, DescendantRebaser}; use jj_lib::settings::UserSettings; +use jj_lib::working_copy::LockedWorkingCopy; use jj_lib::workspace::Workspace; use jj_lib::{conflicts, file_util, revset}; use maplit::{hashmap, hashset}; diff --git a/lib/src/local_working_copy.rs b/lib/src/local_working_copy.rs index 4c50a3be7..61da157f0 100644 --- a/lib/src/local_working_copy.rs +++ b/lib/src/local_working_copy.rs @@ -59,7 +59,7 @@ use crate::repo_path::{FsPathParseError, RepoPath, RepoPathComponent, RepoPathJo use crate::settings::HumanByteSize; use crate::store::Store; use crate::tree::Tree; -use crate::working_copy::WorkingCopy; +use crate::working_copy::{LockedWorkingCopy, WorkingCopy}; #[cfg(unix)] type FileExecutableFlag = bool; @@ -1580,17 +1580,21 @@ pub struct LockedLocalWorkingCopy { tree_state_dirty: bool, } -impl LockedLocalWorkingCopy { - /// The operation at the time the lock was taken - pub fn old_operation_id(&self) -> &OperationId { +impl LockedWorkingCopy for LockedLocalWorkingCopy { + fn as_any(&self) -> &dyn Any { + self + } + + fn old_operation_id(&self) -> &OperationId { &self.old_operation_id } - /// The tree at the time the lock was taken - pub fn old_tree_id(&self) -> &MergedTreeId { + fn old_tree_id(&self) -> &MergedTreeId { &self.old_tree_id } +} +impl LockedLocalWorkingCopy { pub fn reset_watchman(&mut self) -> Result<(), SnapshotError> { self.wc .tree_state_mut() diff --git a/lib/src/working_copy.rs b/lib/src/working_copy.rs index 918f7ef6c..bb7b3e98d 100644 --- a/lib/src/working_copy.rs +++ b/lib/src/working_copy.rs @@ -18,6 +18,7 @@ use std::any::Any; use std::path::Path; +use crate::backend::MergedTreeId; use crate::op_store::{OperationId, WorkspaceId}; /// The trait all working-copy implementations must implement. @@ -38,3 +39,15 @@ pub trait WorkingCopy { /// The operation this working copy was most recently updated to. fn operation_id(&self) -> &OperationId; } + +/// A working copy that's being modified. +pub trait LockedWorkingCopy { + /// Should return `self`. For down-casting purposes. + fn as_any(&self) -> &dyn Any; + + /// The operation at the time the lock was taken + fn old_operation_id(&self) -> &OperationId; + + /// The tree at the time the lock was taken + fn old_tree_id(&self) -> &MergedTreeId; +} diff --git a/lib/src/workspace.rs b/lib/src/workspace.rs index a609b2386..a41132825 100644 --- a/lib/src/workspace.rs +++ b/lib/src/workspace.rs @@ -39,7 +39,7 @@ use crate::repo::{ }; use crate::settings::UserSettings; use crate::submodule_store::SubmoduleStore; -use crate::working_copy::WorkingCopy; +use crate::working_copy::{LockedWorkingCopy, WorkingCopy}; #[derive(Error, Debug)] pub enum WorkspaceInitError {