From 0a94dcc5e36818639eb7bec26c6c905e9aba52f8 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Tue, 27 Aug 2024 10:57:09 -0700 Subject: [PATCH] repo: rename `RepoLoader::init()` to `init_from_file_system()` `RepoLoader` can be used on a server. You would then call `RepoLoader::new()`. Let's clarify what `init()` does by renaming it and documenting it. I think `WorkspaceLoader`, OTOH, is only useful for loading a workspace from disk. I also documented that. --- lib/src/repo.rs | 7 ++++++- lib/src/workspace.rs | 5 ++++- lib/tests/test_load_repo.rs | 4 ++-- lib/testutils/src/lib.rs | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/src/repo.rs b/lib/src/repo.rs index cfee4b6d3..d64a51e60 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -628,6 +628,8 @@ pub enum RepoLoaderError { OpStore(#[from] OpStoreError), } +/// Helps create `ReadonlyRepoo` instances of a repo at the head operation or at +/// a given operation. #[derive(Clone)] pub struct RepoLoader { repo_path: PathBuf, @@ -660,7 +662,10 @@ impl RepoLoader { } } - pub fn init( + /// Creates a `RepoLoader` for the repo at `repo_path` by reading the + /// various `.jj/repo//type` files and loading the right + /// backends from `store_factories`. + pub fn init_from_file_system( user_settings: &UserSettings, repo_path: &Path, store_factories: &StoreFactories, diff --git a/lib/src/workspace.rs b/lib/src/workspace.rs index 5892e98e0..2f30883fd 100644 --- a/lib/src/workspace.rs +++ b/lib/src/workspace.rs @@ -521,6 +521,8 @@ impl WorkspaceLoaderFactory for DefaultWorkspaceLoaderFactory { } } +/// Helps create a `Workspace` instance by reading `.jj/repo/` and +/// `.jj/working_copy/` from the file system. #[derive(Clone, Debug)] struct DefaultWorkspaceLoader { workspace_root: PathBuf, @@ -577,7 +579,8 @@ impl WorkspaceLoader for DefaultWorkspaceLoader { store_factories: &StoreFactories, working_copy_factories: &WorkingCopyFactories, ) -> Result { - let repo_loader = RepoLoader::init(user_settings, &self.repo_dir, store_factories)?; + let repo_loader = + RepoLoader::init_from_file_system(user_settings, &self.repo_dir, store_factories)?; let working_copy_factory = get_working_copy_factory(self, working_copy_factories)?; let working_copy = self.load_working_copy(repo_loader.store(), working_copy_factory)?; let workspace = Workspace::new(&self.workspace_root, working_copy, repo_loader)?; diff --git a/lib/tests/test_load_repo.rs b/lib/tests/test_load_repo.rs index 63ed13eff..205898003 100644 --- a/lib/tests/test_load_repo.rs +++ b/lib/tests/test_load_repo.rs @@ -32,7 +32,7 @@ fn test_load_at_operation() { // If we load the repo at head, we should not see the commit since it was // removed - let loader = RepoLoader::init( + let loader = RepoLoader::init_from_file_system( &settings, repo.repo_path(), &TestRepo::default_store_factories(), @@ -43,7 +43,7 @@ fn test_load_at_operation() { // 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( + let loader = RepoLoader::init_from_file_system( &settings, repo.repo_path(), &TestRepo::default_store_factories(), diff --git a/lib/testutils/src/lib.rs b/lib/testutils/src/lib.rs index c9952a5a6..7d562c054 100644 --- a/lib/testutils/src/lib.rs +++ b/lib/testutils/src/lib.rs @@ -270,7 +270,7 @@ impl TestWorkspace { } pub fn load_repo_at_head(settings: &UserSettings, repo_path: &Path) -> Arc { - RepoLoader::init(settings, repo_path, &TestRepo::default_store_factories()) + RepoLoader::init_from_file_system(settings, repo_path, &TestRepo::default_store_factories()) .unwrap() .load_at_head(settings) .unwrap()