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.
This commit is contained in:
Martin von Zweigbergk 2024-08-27 10:57:09 -07:00 committed by Martin von Zweigbergk
parent bfb16a4c54
commit 0a94dcc5e3
4 changed files with 13 additions and 5 deletions

View file

@ -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/<backend>/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,

View file

@ -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<Workspace, WorkspaceLoadError> {
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)?;

View file

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

View file

@ -270,7 +270,7 @@ impl TestWorkspace {
}
pub fn load_repo_at_head(settings: &UserSettings, repo_path: &Path) -> Arc<ReadonlyRepo> {
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()