ok/jj
1
0
Fork 0
forked from mirrors/jj

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.
This commit is contained in:
Martin von Zweigbergk 2023-10-13 22:46:28 -07:00 committed by Martin von Zweigbergk
parent a733fceba9
commit 6a13fa8264
4 changed files with 12 additions and 9 deletions

View file

@ -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(),

View file

@ -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<RepoPath, FileState>, WorkingCopyStateError> {
Ok(self.tree_state()?.file_states())
}
@ -1564,7 +1564,7 @@ impl LockedWorkingCopy for LockedLocalWorkingCopy {
mut self,
operation_id: OperationId,
) -> Result<LocalWorkingCopy, WorkingCopyStateError> {
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()?

View file

@ -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

View file

@ -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]