From 6a13fa8264168ff65481e7b282f41f416176cb29 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Fri, 13 Oct 2023 22:46:28 -0700 Subject: [PATCH] working copy: add `tree_id()` to backend trait Looks like I missed this earlier. I think it makes sense to have on all working copy implementations. --- cli/src/commands/debug.rs | 2 +- lib/src/local_working_copy.rs | 12 ++++++------ lib/src/working_copy.rs | 3 +++ lib/tests/test_local_working_copy_concurrent.rs | 4 ++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cli/src/commands/debug.rs b/cli/src/commands/debug.rs index e6a9ed026..c0c5867b6 100644 --- a/cli/src/commands/debug.rs +++ b/cli/src/commands/debug.rs @@ -105,7 +105,7 @@ pub fn cmd_debug( let workspace_command = command.workspace_helper(ui)?; let wc = workspace_command.working_copy(); writeln!(ui.stdout(), "Current operation: {:?}", wc.operation_id())?; - writeln!(ui.stdout(), "Current tree: {:?}", wc.current_tree_id()?)?; + writeln!(ui.stdout(), "Current tree: {:?}", wc.tree_id()?)?; for (file, state) in wc.file_states()? { writeln!( ui.stdout(), diff --git a/lib/src/local_working_copy.rs b/lib/src/local_working_copy.rs index d29f7b632..7d1e63a67 100644 --- a/lib/src/local_working_copy.rs +++ b/lib/src/local_working_copy.rs @@ -1304,6 +1304,10 @@ impl WorkingCopy for LocalWorkingCopy { &self.checkout_state().operation_id } + fn tree_id(&self) -> Result<&MergedTreeId, WorkingCopyStateError> { + Ok(self.tree_state()?.current_tree_id()) + } + fn sparse_patterns(&self) -> Result<&[RepoPath], WorkingCopyStateError> { Ok(self.tree_state()?.sparse_patterns()) } @@ -1323,7 +1327,7 @@ impl WorkingCopy for LocalWorkingCopy { tree_state: OnceCell::new(), }; let old_operation_id = wc.operation_id().clone(); - let old_tree_id = wc.current_tree_id()?.clone(); + let old_tree_id = wc.tree_id()?.clone(); Ok(LockedLocalWorkingCopy { wc, lock, @@ -1444,10 +1448,6 @@ impl LocalWorkingCopy { Ok(self.tree_state.get_mut().unwrap()) } - pub fn current_tree_id(&self) -> Result<&MergedTreeId, WorkingCopyStateError> { - Ok(self.tree_state()?.current_tree_id()) - } - pub fn file_states(&self) -> Result<&BTreeMap, WorkingCopyStateError> { Ok(self.tree_state()?.file_states()) } @@ -1564,7 +1564,7 @@ impl LockedWorkingCopy for LockedLocalWorkingCopy { mut self, operation_id: OperationId, ) -> Result { - assert!(self.tree_state_dirty || &self.old_tree_id == self.wc.current_tree_id()?); + assert!(self.tree_state_dirty || &self.old_tree_id == self.wc.tree_id()?); if self.tree_state_dirty { self.wc .tree_state_mut()? diff --git a/lib/src/working_copy.rs b/lib/src/working_copy.rs index dbfced477..0447daa99 100644 --- a/lib/src/working_copy.rs +++ b/lib/src/working_copy.rs @@ -49,6 +49,9 @@ pub trait WorkingCopy { /// The operation this working copy was most recently updated to. fn operation_id(&self) -> &OperationId; + /// The ID of the tree this working copy was most recently updated to. + fn tree_id(&self) -> Result<&MergedTreeId, WorkingCopyStateError>; + /// Patterns that decide which paths from the current tree should be checked /// out in the working copy. An empty list means that no paths should be /// checked out in the working copy. A single `RepoPath::root()` entry means diff --git a/lib/tests/test_local_working_copy_concurrent.rs b/lib/tests/test_local_working_copy_concurrent.rs index 3e00adcda..87398cb15 100644 --- a/lib/tests/test_local_working_copy_concurrent.rs +++ b/lib/tests/test_local_working_copy_concurrent.rs @@ -18,7 +18,7 @@ use std::thread; use assert_matches::assert_matches; use jj_lib::repo::Repo; use jj_lib::repo_path::RepoPath; -use jj_lib::working_copy::{CheckoutError, LockedWorkingCopy, SnapshotOptions}; +use jj_lib::working_copy::{CheckoutError, LockedWorkingCopy, SnapshotOptions, WorkingCopy}; use jj_lib::workspace::Workspace; use testutils::{create_tree, write_working_copy_file, TestRepo, TestWorkspace}; @@ -67,7 +67,7 @@ fn test_concurrent_checkout() { &TestRepo::default_store_factories(), ) .unwrap(); - assert_eq!(*ws3.working_copy().current_tree_id().unwrap(), tree_id2); + assert_eq!(*ws3.working_copy().tree_id().unwrap(), tree_id2); } #[test]