working copy: start defining a trait for a locked working copy

As with the `WorkingCopy` trait, this just contains some trivial
methods for now.
This commit is contained in:
Martin von Zweigbergk 2023-10-10 23:11:15 -07:00 committed by Martin von Zweigbergk
parent 49637cb0fd
commit 3aa57b1a04
5 changed files with 26 additions and 8 deletions

View file

@ -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,
};

View file

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

View file

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

View file

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

View file

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