mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-26 14:00:51 +00:00
workspace: make capable of loading with out-of-tree backend
This commit is contained in:
parent
87bcee6cf2
commit
3e0d49e847
5 changed files with 35 additions and 12 deletions
|
@ -175,6 +175,7 @@ impl Workspace {
|
|||
pub fn load(
|
||||
user_settings: &UserSettings,
|
||||
workspace_path: &Path,
|
||||
backend_factories: &BackendFactories,
|
||||
) -> Result<Self, WorkspaceLoadError> {
|
||||
let jj_dir = find_jj_dir(workspace_path)
|
||||
.ok_or_else(|| WorkspaceLoadError::NoWorkspaceHere(workspace_path.to_owned()))?;
|
||||
|
@ -192,7 +193,7 @@ impl Workspace {
|
|||
return Err(WorkspaceLoadError::RepoDoesNotExist(repo_dir));
|
||||
}
|
||||
}
|
||||
let repo_loader = RepoLoader::init(user_settings, &repo_dir, &BackendFactories::default());
|
||||
let repo_loader = RepoLoader::init(user_settings, &repo_dir, backend_factories);
|
||||
let working_copy_state_path = jj_dir.join("working_copy");
|
||||
let working_copy = WorkingCopy::load(
|
||||
repo_loader.store().clone(),
|
||||
|
|
|
@ -108,7 +108,12 @@ fn test_bad_locking_children(use_git: bool) {
|
|||
// Simulate a write of a commit that happens on one machine
|
||||
let machine1_root = testutils::new_temp_dir();
|
||||
copy_directory(workspace_root, machine1_root.path());
|
||||
let machine1_workspace = Workspace::load(&settings, machine1_root.path()).unwrap();
|
||||
let machine1_workspace = Workspace::load(
|
||||
&settings,
|
||||
machine1_root.path(),
|
||||
&BackendFactories::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let machine1_repo = machine1_workspace
|
||||
.repo_loader()
|
||||
.load_at_head()
|
||||
|
@ -123,7 +128,12 @@ fn test_bad_locking_children(use_git: bool) {
|
|||
// Simulate a write of a commit that happens on another machine
|
||||
let machine2_root = testutils::new_temp_dir();
|
||||
copy_directory(workspace_root, machine2_root.path());
|
||||
let machine2_workspace = Workspace::load(&settings, machine2_root.path()).unwrap();
|
||||
let machine2_workspace = Workspace::load(
|
||||
&settings,
|
||||
machine2_root.path(),
|
||||
&BackendFactories::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let machine2_repo = machine2_workspace
|
||||
.repo_loader()
|
||||
.load_at_head()
|
||||
|
@ -144,7 +154,8 @@ fn test_bad_locking_children(use_git: bool) {
|
|||
machine2_root.path(),
|
||||
merged_path.path(),
|
||||
);
|
||||
let merged_workspace = Workspace::load(&settings, merged_path.path()).unwrap();
|
||||
let merged_workspace =
|
||||
Workspace::load(&settings, merged_path.path(), &BackendFactories::default()).unwrap();
|
||||
let merged_repo = merged_workspace
|
||||
.repo_loader()
|
||||
.load_at_head()
|
||||
|
|
|
@ -17,6 +17,7 @@ use std::thread;
|
|||
|
||||
use assert_matches::assert_matches;
|
||||
use jujutsu_lib::gitignore::GitIgnoreFile;
|
||||
use jujutsu_lib::repo::BackendFactories;
|
||||
use jujutsu_lib::repo_path::RepoPath;
|
||||
use jujutsu_lib::testutils;
|
||||
use jujutsu_lib::testutils::TestWorkspace;
|
||||
|
@ -57,7 +58,8 @@ fn test_concurrent_checkout(use_git: bool) {
|
|||
|
||||
// Check out tree2 from another process (simulated by another workspace
|
||||
// instance)
|
||||
let mut workspace2 = Workspace::load(&settings, &workspace1_root).unwrap();
|
||||
let mut workspace2 =
|
||||
Workspace::load(&settings, &workspace1_root, &BackendFactories::default()).unwrap();
|
||||
workspace2
|
||||
.working_copy_mut()
|
||||
.check_out(repo1.op_id().clone(), Some(&tree_id1), &tree2)
|
||||
|
@ -70,7 +72,8 @@ fn test_concurrent_checkout(use_git: bool) {
|
|||
);
|
||||
|
||||
// Check that the tree2 is still checked out on disk.
|
||||
let workspace3 = Workspace::load(&settings, &workspace1_root).unwrap();
|
||||
let workspace3 =
|
||||
Workspace::load(&settings, &workspace1_root, &BackendFactories::default()).unwrap();
|
||||
assert_eq!(workspace3.working_copy().current_tree_id(), tree_id2);
|
||||
}
|
||||
|
||||
|
@ -112,7 +115,8 @@ fn test_checkout_parallel(use_git: bool) {
|
|||
let settings = settings.clone();
|
||||
let workspace_root = workspace_root.clone();
|
||||
let handle = thread::spawn(move || {
|
||||
let mut workspace = Workspace::load(&settings, &workspace_root).unwrap();
|
||||
let mut workspace =
|
||||
Workspace::load(&settings, &workspace_root, &BackendFactories::default()).unwrap();
|
||||
let tree = workspace
|
||||
.repo_loader()
|
||||
.store()
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
use jujutsu_lib::op_store::WorkspaceId;
|
||||
use jujutsu_lib::repo::BackendFactories;
|
||||
use jujutsu_lib::testutils;
|
||||
use jujutsu_lib::testutils::TestWorkspace;
|
||||
use jujutsu_lib::workspace::{Workspace, WorkspaceLoadError};
|
||||
|
@ -24,7 +25,7 @@ fn test_load_bad_path() {
|
|||
let temp_dir = testutils::new_temp_dir();
|
||||
let workspace_root = temp_dir.path().to_owned();
|
||||
// We haven't created a repo in the workspace_root, so it should fail to load.
|
||||
let result = Workspace::load(&settings, &workspace_root);
|
||||
let result = Workspace::load(&settings, &workspace_root, &BackendFactories::default());
|
||||
assert_eq!(
|
||||
result.err(),
|
||||
Some(WorkspaceLoadError::NoWorkspaceHere(workspace_root))
|
||||
|
@ -40,7 +41,7 @@ fn test_load_from_subdir(use_git: bool) {
|
|||
|
||||
let subdir = workspace.workspace_root().join("dir").join("subdir");
|
||||
std::fs::create_dir_all(subdir.clone()).unwrap();
|
||||
let same_workspace = Workspace::load(&settings, &subdir);
|
||||
let same_workspace = Workspace::load(&settings, &subdir, &BackendFactories::default());
|
||||
assert!(same_workspace.is_ok());
|
||||
let same_workspace = same_workspace.unwrap();
|
||||
assert_eq!(same_workspace.repo_path(), workspace.repo_path());
|
||||
|
@ -78,7 +79,7 @@ fn test_init_additional_workspace(use_git: bool) {
|
|||
workspace.repo_path().canonicalize().unwrap()
|
||||
);
|
||||
assert_eq!(*ws2.workspace_root(), ws2_root.canonicalize().unwrap());
|
||||
let same_workspace = Workspace::load(&settings, &ws2_root);
|
||||
let same_workspace = Workspace::load(&settings, &ws2_root, &BackendFactories::default());
|
||||
assert!(same_workspace.is_ok());
|
||||
let same_workspace = same_workspace.unwrap();
|
||||
assert_eq!(same_workspace.workspace_id(), ws2_id);
|
||||
|
|
|
@ -30,7 +30,7 @@ use jujutsu_lib::matchers::{EverythingMatcher, Matcher, PrefixMatcher, Visit};
|
|||
use jujutsu_lib::op_heads_store::{OpHeadResolutionError, OpHeads, OpHeadsStore};
|
||||
use jujutsu_lib::op_store::{OpStore, OpStoreError, OperationId, WorkspaceId};
|
||||
use jujutsu_lib::operation::Operation;
|
||||
use jujutsu_lib::repo::{MutableRepo, ReadonlyRepo};
|
||||
use jujutsu_lib::repo::{BackendFactories, MutableRepo, ReadonlyRepo};
|
||||
use jujutsu_lib::repo_path::RepoPath;
|
||||
use jujutsu_lib::revset::{RevsetError, RevsetParseError};
|
||||
use jujutsu_lib::settings::UserSettings;
|
||||
|
@ -171,6 +171,7 @@ pub struct CommandHelper<'help> {
|
|||
app: clap::Command<'help>,
|
||||
string_args: Vec<String>,
|
||||
global_args: GlobalArgs,
|
||||
backend_factories: BackendFactories,
|
||||
}
|
||||
|
||||
impl<'help> CommandHelper<'help> {
|
||||
|
@ -183,6 +184,7 @@ impl<'help> CommandHelper<'help> {
|
|||
app,
|
||||
string_args,
|
||||
global_args,
|
||||
backend_factories: BackendFactories::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,10 +200,14 @@ impl<'help> CommandHelper<'help> {
|
|||
&self.global_args
|
||||
}
|
||||
|
||||
pub fn set_backend_factories(&mut self, backend_factories: BackendFactories) {
|
||||
self.backend_factories = backend_factories;
|
||||
}
|
||||
|
||||
pub fn workspace_helper(&self, ui: &mut Ui) -> Result<WorkspaceCommandHelper, CommandError> {
|
||||
let wc_path_str = self.global_args.repository.as_deref().unwrap_or(".");
|
||||
let wc_path = ui.cwd().join(wc_path_str);
|
||||
let workspace = match Workspace::load(ui.settings(), &wc_path) {
|
||||
let workspace = match Workspace::load(ui.settings(), &wc_path, &self.backend_factories) {
|
||||
Ok(workspace) => workspace,
|
||||
Err(WorkspaceLoadError::NoWorkspaceHere(wc_path)) => {
|
||||
let mut message = format!("There is no jj repo in \"{}\"", wc_path_str);
|
||||
|
|
Loading…
Reference in a new issue