forked from mirrors/jj
working copy: add reset()
function to the backend trait
This includes documenting the new function and the other types moved to the `working_copy` module.
This commit is contained in:
parent
0d2247b0df
commit
6457a13260
3 changed files with 42 additions and 35 deletions
|
@ -41,9 +41,7 @@ use jj_lib::git_backend::GitBackend;
|
|||
use jj_lib::gitignore::GitIgnoreFile;
|
||||
use jj_lib::hex_util::to_reverse_hex;
|
||||
use jj_lib::id_prefix::IdPrefixContext;
|
||||
use jj_lib::local_working_copy::{
|
||||
LocalWorkingCopy, LockedLocalWorkingCopy, ResetError, WorkingCopyStateError,
|
||||
};
|
||||
use jj_lib::local_working_copy::{LocalWorkingCopy, LockedLocalWorkingCopy, WorkingCopyStateError};
|
||||
use jj_lib::matchers::{EverythingMatcher, Matcher, PrefixMatcher, Visit};
|
||||
use jj_lib::merged_tree::{MergedTree, MergedTreeBuilder};
|
||||
use jj_lib::op_heads_store::{self, OpHeadResolutionError, OpHeadsStore};
|
||||
|
@ -63,7 +61,7 @@ use jj_lib::settings::{ConfigResultExt as _, UserSettings};
|
|||
use jj_lib::transaction::Transaction;
|
||||
use jj_lib::tree::TreeMergeError;
|
||||
use jj_lib::working_copy::{
|
||||
CheckoutStats, LockedWorkingCopy, SnapshotError, SnapshotOptions, WorkingCopy,
|
||||
CheckoutStats, LockedWorkingCopy, ResetError, SnapshotError, SnapshotOptions, WorkingCopy,
|
||||
};
|
||||
use jj_lib::workspace::{
|
||||
LockedWorkspace, Workspace, WorkspaceInitError, WorkspaceLoadError, WorkspaceLoader,
|
||||
|
|
|
@ -59,7 +59,7 @@ use crate::settings::HumanByteSize;
|
|||
use crate::store::Store;
|
||||
use crate::tree::Tree;
|
||||
use crate::working_copy::{
|
||||
CheckoutError, CheckoutStats, LockedWorkingCopy, SnapshotError, SnapshotOptions,
|
||||
CheckoutError, CheckoutStats, LockedWorkingCopy, ResetError, SnapshotError, SnapshotOptions,
|
||||
SnapshotProgress, WorkingCopy,
|
||||
};
|
||||
|
||||
|
@ -308,24 +308,6 @@ struct FsmonitorMatcher {
|
|||
watchman_clock: Option<crate::protos::working_copy::WatchmanClock>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ResetError {
|
||||
// The current working-copy commit was deleted, maybe by an overly aggressive GC that happened
|
||||
// while the current process was running.
|
||||
#[error("Current working-copy commit not found: {source}")]
|
||||
SourceNotFound {
|
||||
source: Box<dyn std::error::Error + Send + Sync>,
|
||||
},
|
||||
#[error("Internal error: {0}")]
|
||||
InternalBackendError(#[from] BackendError),
|
||||
#[error("{message}: {err:?}")]
|
||||
Other {
|
||||
message: String,
|
||||
#[source]
|
||||
err: Box<dyn std::error::Error + Send + Sync>,
|
||||
},
|
||||
}
|
||||
|
||||
struct DirectoryToVisit {
|
||||
dir: RepoPath,
|
||||
disk_dir: PathBuf,
|
||||
|
@ -1549,6 +1531,18 @@ impl LockedWorkingCopy for LockedLocalWorkingCopy {
|
|||
self.tree_state_dirty = true;
|
||||
Ok(stats)
|
||||
}
|
||||
|
||||
fn reset(&mut self, new_tree: &MergedTree) -> Result<(), ResetError> {
|
||||
self.wc
|
||||
.tree_state_mut()
|
||||
.map_err(|err| ResetError::Other {
|
||||
message: "Failed to read the working copy state".to_string(),
|
||||
err: err.into(),
|
||||
})?
|
||||
.reset(new_tree)?;
|
||||
self.tree_state_dirty = true;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl LockedLocalWorkingCopy {
|
||||
|
@ -1564,18 +1558,6 @@ impl LockedLocalWorkingCopy {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn reset(&mut self, new_tree: &MergedTree) -> Result<(), ResetError> {
|
||||
self.wc
|
||||
.tree_state_mut()
|
||||
.map_err(|err| ResetError::Other {
|
||||
message: "Failed to read the working copy state".to_string(),
|
||||
err: err.into(),
|
||||
})?
|
||||
.reset(new_tree)?;
|
||||
self.tree_state_dirty = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn sparse_patterns(&self) -> Result<&[RepoPath], WorkingCopyStateError> {
|
||||
self.wc.sparse_patterns()
|
||||
}
|
||||
|
|
|
@ -66,6 +66,9 @@ pub trait LockedWorkingCopy {
|
|||
/// Check out the specified tree in the working copy.
|
||||
// TODO: Pass a Commit object here because some implementations need that.
|
||||
fn check_out(&mut self, new_tree: &MergedTree) -> Result<CheckoutStats, CheckoutError>;
|
||||
|
||||
/// Update to another tree without touching the files in the working copy.
|
||||
fn reset(&mut self, new_tree: &MergedTree) -> Result<(), ResetError>;
|
||||
}
|
||||
|
||||
/// An error while snapshotting the working copy.
|
||||
|
@ -193,3 +196,27 @@ pub enum CheckoutError {
|
|||
err: Box<dyn std::error::Error + Send + Sync>,
|
||||
},
|
||||
}
|
||||
|
||||
/// An error while resetting the working copy.
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ResetError {
|
||||
/// The current working-copy commit was deleted, maybe by an overly
|
||||
/// aggressive GC that happened while the current process was running.
|
||||
#[error("Current working-copy commit not found: {source}")]
|
||||
SourceNotFound {
|
||||
/// The underlying error.
|
||||
source: Box<dyn std::error::Error + Send + Sync>,
|
||||
},
|
||||
/// Reading or writing from the commit backend failed.
|
||||
#[error("Internal error: {0}")]
|
||||
InternalBackendError(#[from] BackendError),
|
||||
/// Some other error happened while checking out the working copy.
|
||||
#[error("{message}: {err:?}")]
|
||||
Other {
|
||||
/// Error message.
|
||||
message: String,
|
||||
#[source]
|
||||
/// The underlying error.
|
||||
err: Box<dyn std::error::Error + Send + Sync>,
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue