From 7cbea42a24ba80a5c5faf712c25f597f1a9fba77 Mon Sep 17 00:00:00 2001 From: Daniel Ploch Date: Wed, 14 Dec 2022 13:08:31 -0500 Subject: [PATCH] repo: rename BackendFactories to StoreFactories --- examples/custom-backend/main.rs | 8 +++---- lib/src/repo.rs | 26 +++++++++++------------ lib/src/workspace.rs | 6 +++--- lib/tests/test_bad_locking.rs | 24 +++++++-------------- lib/tests/test_commit_concurrent.rs | 9 ++++---- lib/tests/test_index.rs | 17 ++++++--------- lib/tests/test_load_repo.rs | 6 +++--- lib/tests/test_working_copy_concurrent.rs | 8 +++---- lib/tests/test_workspace.rs | 8 +++---- src/cli_util.rs | 12 +++++------ 10 files changed, 56 insertions(+), 68 deletions(-) diff --git a/examples/custom-backend/main.rs b/examples/custom-backend/main.rs index 03959d06f..94b5d0bb6 100644 --- a/examples/custom-backend/main.rs +++ b/examples/custom-backend/main.rs @@ -24,7 +24,7 @@ use jujutsu_lib::backend::{ Backend, BackendResult, Commit, CommitId, Conflict, ConflictId, FileId, SymlinkId, Tree, TreeId, }; use jujutsu_lib::git_backend::GitBackend; -use jujutsu_lib::repo::BackendFactories; +use jujutsu_lib::repo::StoreFactories; use jujutsu_lib::repo_path::RepoPath; use jujutsu_lib::workspace::Workspace; @@ -37,14 +37,14 @@ enum CustomCommands { fn run(ui: &mut Ui) -> Result<(), CommandError> { let app = CustomCommands::augment_subcommands(default_app()); let (mut command_helper, matches) = parse_args(ui, app, std::env::args_os())?; - let mut backend_factories = BackendFactories::default(); + let mut store_factories = StoreFactories::default(); // Register the backend so it can be loaded when the repo is loaded. The name // must match `Backend::name()`. - backend_factories.add_backend( + store_factories.add_backend( "jit", Box::new(|store_path| Box::new(JitBackend::load(store_path))), ); - command_helper.set_backend_factories(backend_factories); + command_helper.set_store_factories(store_factories); match CustomCommands::from_arg_matches(&matches) { // Handle our custom command Ok(CustomCommands::InitJit) => { diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 85329527f..bfe437cd9 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -163,9 +163,9 @@ impl ReadonlyRepo { pub fn load_at_head( user_settings: &UserSettings, repo_path: &Path, - backend_factories: &BackendFactories, + store_factories: &StoreFactories, ) -> Result, BackendError> { - RepoLoader::init(user_settings, repo_path, backend_factories) + RepoLoader::init(user_settings, repo_path, store_factories) .load_at_head() .resolve(user_settings) } @@ -285,13 +285,13 @@ impl UnresolvedHeadRepo { type BackendFactory = Box Box>; -pub struct BackendFactories { - factories: HashMap, +pub struct StoreFactories { + backend_factories: HashMap, } -impl Default for BackendFactories { +impl Default for StoreFactories { fn default() -> Self { - let mut factories = BackendFactories::empty(); + let mut factories = StoreFactories::empty(); factories.add_backend( "local", Box::new(|store_path| Box::new(LocalBackend::load(store_path))), @@ -304,15 +304,15 @@ impl Default for BackendFactories { } } -impl BackendFactories { +impl StoreFactories { pub fn empty() -> Self { - BackendFactories { - factories: HashMap::new(), + StoreFactories { + backend_factories: HashMap::new(), } } pub fn add_backend(&mut self, name: &str, factory: BackendFactory) { - self.factories.insert(name.to_string(), factory); + self.backend_factories.insert(name.to_string(), factory); } } @@ -330,7 +330,7 @@ impl RepoLoader { pub fn init( user_settings: &UserSettings, repo_path: &Path, - backend_factories: &BackendFactories, + store_factories: &StoreFactories, ) -> Self { let store_path = repo_path.join("store"); let backend_type = match fs::read_to_string(store_path.join("backend")) { @@ -349,8 +349,8 @@ impl RepoLoader { panic!("Failed to read backend type"); } }; - let backend_factory = backend_factories - .factories + let backend_factory = store_factories + .backend_factories .get(&backend_type) .expect("Unexpected backend type"); let store = Store::new(backend_factory(&store_path)); diff --git a/lib/src/workspace.rs b/lib/src/workspace.rs index 999fec74f..379956f3e 100644 --- a/lib/src/workspace.rs +++ b/lib/src/workspace.rs @@ -23,7 +23,7 @@ use crate::backend::Backend; use crate::git_backend::GitBackend; use crate::local_backend::LocalBackend; use crate::op_store::WorkspaceId; -use crate::repo::{BackendFactories, IoResultExt, PathError, ReadonlyRepo, RepoLoader}; +use crate::repo::{IoResultExt, PathError, ReadonlyRepo, RepoLoader, StoreFactories}; use crate::settings::UserSettings; use crate::working_copy::WorkingCopy; @@ -197,7 +197,7 @@ impl Workspace { pub fn load( user_settings: &UserSettings, workspace_path: &Path, - backend_factories: &BackendFactories, + store_factories: &StoreFactories, ) -> Result { let jj_dir = find_jj_dir(workspace_path) .ok_or_else(|| WorkspaceLoadError::NoWorkspaceHere(workspace_path.to_owned()))?; @@ -222,7 +222,7 @@ impl Workspace { return Err(WorkspaceLoadError::RepoDoesNotExist(repo_dir)); } } - let repo_loader = RepoLoader::init(user_settings, &repo_dir, backend_factories); + let repo_loader = RepoLoader::init(user_settings, &repo_dir, store_factories); let working_copy_state_path = jj_dir.join("working_copy"); let working_copy = WorkingCopy::load( repo_loader.store().clone(), diff --git a/lib/tests/test_bad_locking.rs b/lib/tests/test_bad_locking.rs index fa2a37c9f..776527f5c 100644 --- a/lib/tests/test_bad_locking.rs +++ b/lib/tests/test_bad_locking.rs @@ -14,7 +14,7 @@ use std::path::Path; -use jujutsu_lib::repo::{BackendFactories, ReadonlyRepo}; +use jujutsu_lib::repo::{ReadonlyRepo, StoreFactories}; use jujutsu_lib::workspace::Workspace; use test_case::test_case; use testutils::{create_random_commit, TestWorkspace}; @@ -107,12 +107,8 @@ 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(), - &BackendFactories::default(), - ) - .unwrap(); + let machine1_workspace = + Workspace::load(&settings, machine1_root.path(), &StoreFactories::default()).unwrap(); let machine1_repo = machine1_workspace .repo_loader() .load_at_head() @@ -127,12 +123,8 @@ 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(), - &BackendFactories::default(), - ) - .unwrap(); + let machine2_workspace = + Workspace::load(&settings, machine2_root.path(), &StoreFactories::default()).unwrap(); let machine2_repo = machine2_workspace .repo_loader() .load_at_head() @@ -154,7 +146,7 @@ fn test_bad_locking_children(use_git: bool) { merged_path.path(), ); let merged_workspace = - Workspace::load(&settings, merged_path.path(), &BackendFactories::default()).unwrap(); + Workspace::load(&settings, merged_path.path(), &StoreFactories::default()).unwrap(); let merged_repo = merged_workspace .repo_loader() .load_at_head() @@ -199,13 +191,13 @@ fn test_bad_locking_interrupted(use_git: bool) { copy_directory(backup_path.path(), &op_heads_dir); // Reload the repo and check that only the new head is present. let reloaded_repo = - ReadonlyRepo::load_at_head(&settings, repo.repo_path(), &BackendFactories::default()) + ReadonlyRepo::load_at_head(&settings, repo.repo_path(), &StoreFactories::default()) .unwrap(); assert_eq!(reloaded_repo.op_id(), &op_id); // Reload once more to make sure that the .jj/op_heads/ directory was updated // correctly. let reloaded_repo = - ReadonlyRepo::load_at_head(&settings, repo.repo_path(), &BackendFactories::default()) + ReadonlyRepo::load_at_head(&settings, repo.repo_path(), &StoreFactories::default()) .unwrap(); assert_eq!(reloaded_repo.op_id(), &op_id); } diff --git a/lib/tests/test_commit_concurrent.rs b/lib/tests/test_commit_concurrent.rs index 8d144ba16..5beffafe2 100644 --- a/lib/tests/test_commit_concurrent.rs +++ b/lib/tests/test_commit_concurrent.rs @@ -16,7 +16,7 @@ use std::cmp::max; use std::thread; use jujutsu_lib::dag_walk; -use jujutsu_lib::repo::{BackendFactories, ReadonlyRepo}; +use jujutsu_lib::repo::{ReadonlyRepo, StoreFactories}; use test_case::test_case; use testutils::{create_random_commit, TestWorkspace}; @@ -86,7 +86,7 @@ fn test_commit_parallel_instances(use_git: bool) { for _ in 0..num_threads { let settings = settings.clone(); let repo = - ReadonlyRepo::load_at_head(&settings, repo.repo_path(), &BackendFactories::default()) + ReadonlyRepo::load_at_head(&settings, repo.repo_path(), &StoreFactories::default()) .unwrap(); let handle = thread::spawn(move || { let mut tx = repo.start_transaction(&settings, "test"); @@ -100,9 +100,8 @@ fn test_commit_parallel_instances(use_git: bool) { } // One commit per thread plus the commit from the initial checkout on top of the // root commit - let repo = - ReadonlyRepo::load_at_head(&settings, repo.repo_path(), &BackendFactories::default()) - .unwrap(); + let repo = ReadonlyRepo::load_at_head(&settings, repo.repo_path(), &StoreFactories::default()) + .unwrap(); assert_eq!(repo.view().heads().len(), num_threads + 1); // One addition operation for initializing the repo, one for checking out the diff --git a/lib/tests/test_index.rs b/lib/tests/test_index.rs index c03415a7d..4e844c1f9 100644 --- a/lib/tests/test_index.rs +++ b/lib/tests/test_index.rs @@ -18,7 +18,7 @@ use jujutsu_lib::backend::CommitId; use jujutsu_lib::commit::Commit; use jujutsu_lib::commit_builder::CommitBuilder; use jujutsu_lib::index::IndexRef; -use jujutsu_lib::repo::{BackendFactories, ReadonlyRepo}; +use jujutsu_lib::repo::{ReadonlyRepo, StoreFactories}; use jujutsu_lib::settings::UserSettings; use test_case::test_case; use testutils::{create_random_commit, CommitGraphBuilder, TestRepo}; @@ -293,9 +293,8 @@ fn test_index_commits_previous_operations(use_git: bool) { std::fs::remove_dir_all(&index_operations_dir).unwrap(); std::fs::create_dir(&index_operations_dir).unwrap(); - let repo = - ReadonlyRepo::load_at_head(&settings, repo.repo_path(), &BackendFactories::default()) - .unwrap(); + let repo = ReadonlyRepo::load_at_head(&settings, repo.repo_path(), &StoreFactories::default()) + .unwrap(); let index = repo.index(); // There should be the root commit, plus 3 more assert_eq!(index.num_commits(), 1 + 3); @@ -340,9 +339,8 @@ fn test_index_commits_incremental(use_git: bool) { let commit_c = child_commit(&settings, &repo, &commit_b).write_to_repo(tx.mut_repo()); tx.commit(); - let repo = - ReadonlyRepo::load_at_head(&settings, repo.repo_path(), &BackendFactories::default()) - .unwrap(); + let repo = ReadonlyRepo::load_at_head(&settings, repo.repo_path(), &StoreFactories::default()) + .unwrap(); let index = repo.index(); // There should be the root commit, plus 3 more assert_eq!(index.num_commits(), 1 + 3); @@ -385,9 +383,8 @@ fn test_index_commits_incremental_empty_transaction(use_git: bool) { repo.start_transaction(&settings, "test").commit(); - let repo = - ReadonlyRepo::load_at_head(&settings, repo.repo_path(), &BackendFactories::default()) - .unwrap(); + let repo = ReadonlyRepo::load_at_head(&settings, repo.repo_path(), &StoreFactories::default()) + .unwrap(); let index = repo.index(); // There should be the root commit, plus 1 more assert_eq!(index.num_commits(), 1 + 1); diff --git a/lib/tests/test_load_repo.rs b/lib/tests/test_load_repo.rs index e4fd4f88a..eb987c68f 100644 --- a/lib/tests/test_load_repo.rs +++ b/lib/tests/test_load_repo.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use jujutsu_lib::repo::{BackendFactories, RepoLoader}; +use jujutsu_lib::repo::{RepoLoader, StoreFactories}; use test_case::test_case; use testutils::{create_random_commit, TestRepo}; @@ -33,13 +33,13 @@ fn test_load_at_operation(use_git: bool) { // If we load the repo at head, we should not see the commit since it was // removed - let loader = RepoLoader::init(&settings, repo.repo_path(), &BackendFactories::default()); + let loader = RepoLoader::init(&settings, repo.repo_path(), &StoreFactories::default()); let head_repo = loader.load_at_head().resolve(&settings).unwrap(); assert!(!head_repo.view().heads().contains(commit.id())); // If we load the repo at the previous operation, we should see the commit since // it has not been removed yet - let loader = RepoLoader::init(&settings, repo.repo_path(), &BackendFactories::default()); + let loader = RepoLoader::init(&settings, repo.repo_path(), &StoreFactories::default()); let old_repo = loader.load_at(repo.operation()); assert!(old_repo.view().heads().contains(commit.id())); } diff --git a/lib/tests/test_working_copy_concurrent.rs b/lib/tests/test_working_copy_concurrent.rs index 92b38e927..a816bb328 100644 --- a/lib/tests/test_working_copy_concurrent.rs +++ b/lib/tests/test_working_copy_concurrent.rs @@ -17,7 +17,7 @@ use std::thread; use assert_matches::assert_matches; use jujutsu_lib::gitignore::GitIgnoreFile; -use jujutsu_lib::repo::BackendFactories; +use jujutsu_lib::repo::StoreFactories; use jujutsu_lib::repo_path::RepoPath; use jujutsu_lib::working_copy::CheckoutError; use jujutsu_lib::workspace::Workspace; @@ -58,7 +58,7 @@ 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, &BackendFactories::default()).unwrap(); + Workspace::load(&settings, &workspace1_root, &StoreFactories::default()).unwrap(); workspace2 .working_copy_mut() .check_out(repo1.op_id().clone(), Some(&tree_id1), &tree2) @@ -72,7 +72,7 @@ fn test_concurrent_checkout(use_git: bool) { // Check that the tree2 is still checked out on disk. let workspace3 = - Workspace::load(&settings, &workspace1_root, &BackendFactories::default()).unwrap(); + Workspace::load(&settings, &workspace1_root, &StoreFactories::default()).unwrap(); assert_eq!(workspace3.working_copy().current_tree_id(), &tree_id2); } @@ -115,7 +115,7 @@ fn test_checkout_parallel(use_git: bool) { let workspace_root = workspace_root.clone(); let handle = thread::spawn(move || { let mut workspace = - Workspace::load(&settings, &workspace_root, &BackendFactories::default()).unwrap(); + Workspace::load(&settings, &workspace_root, &StoreFactories::default()).unwrap(); let tree = workspace .repo_loader() .store() diff --git a/lib/tests/test_workspace.rs b/lib/tests/test_workspace.rs index 0ce9d4ea8..4a62367b7 100644 --- a/lib/tests/test_workspace.rs +++ b/lib/tests/test_workspace.rs @@ -14,7 +14,7 @@ use assert_matches::assert_matches; use jujutsu_lib::op_store::WorkspaceId; -use jujutsu_lib::repo::BackendFactories; +use jujutsu_lib::repo::StoreFactories; use jujutsu_lib::workspace::{Workspace, WorkspaceLoadError}; use test_case::test_case; use testutils::TestWorkspace; @@ -25,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, &BackendFactories::default()); + let result = Workspace::load(&settings, &workspace_root, &StoreFactories::default()); assert_matches!( result.err(), Some(WorkspaceLoadError::NoWorkspaceHere(root)) if root == workspace_root @@ -41,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, &BackendFactories::default()); + let same_workspace = Workspace::load(&settings, &subdir, &StoreFactories::default()); assert!(same_workspace.is_ok()); let same_workspace = same_workspace.unwrap(); assert_eq!(same_workspace.repo_path(), workspace.repo_path()); @@ -79,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, &BackendFactories::default()); + let same_workspace = Workspace::load(&settings, &ws2_root, &StoreFactories::default()); assert!(same_workspace.is_ok()); let same_workspace = same_workspace.unwrap(); assert_eq!(same_workspace.workspace_id(), &ws2_id); diff --git a/src/cli_util.rs b/src/cli_util.rs index 414ce06e0..5736d4a00 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -36,7 +36,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::{BackendFactories, MutableRepo, ReadonlyRepo, RepoRef, RewriteRootCommit}; +use jujutsu_lib::repo::{MutableRepo, ReadonlyRepo, RepoRef, RewriteRootCommit, StoreFactories}; use jujutsu_lib::repo_path::{FsPathParseError, RepoPath}; use jujutsu_lib::revset::{ Revset, RevsetAliasesMap, RevsetError, RevsetExpression, RevsetParseError, @@ -218,7 +218,7 @@ pub struct CommandHelper { app: clap::Command, string_args: Vec, global_args: GlobalArgs, - backend_factories: BackendFactories, + store_factories: StoreFactories, } impl CommandHelper { @@ -227,7 +227,7 @@ impl CommandHelper { app, string_args, global_args, - backend_factories: BackendFactories::default(), + store_factories: StoreFactories::default(), } } @@ -243,8 +243,8 @@ impl CommandHelper { &self.global_args } - pub fn set_backend_factories(&mut self, backend_factories: BackendFactories) { - self.backend_factories = backend_factories; + pub fn set_store_factories(&mut self, store_factories: StoreFactories) { + self.store_factories = store_factories; } pub fn workspace_helper(&self, ui: &mut Ui) -> Result { @@ -257,7 +257,7 @@ impl CommandHelper { pub fn load_workspace(&self, ui: &Ui) -> Result { let wc_path_str = self.global_args.repository.as_deref().unwrap_or("."); let wc_path = ui.cwd().join(wc_path_str); - Workspace::load(ui.settings(), &wc_path, &self.backend_factories).map_err(|err| match err { + Workspace::load(ui.settings(), &wc_path, &self.store_factories).map_err(|err| match err { WorkspaceLoadError::NoWorkspaceHere(wc_path) => { let message = format!("There is no jj repo in \"{}\"", wc_path_str); let git_dir = wc_path.join(".git");