Skip to content

Commit

Permalink
repo: rename RepoLoader::init() to init_from_file_system()
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
martinvonz committed Sep 7, 2024
1 parent bfb16a4 commit 0a94dcc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
7 changes: 6 additions & 1 deletion lib/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion lib/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)?;
Expand Down
4 changes: 2 additions & 2 deletions lib/tests/test_load_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion lib/testutils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0a94dcc

Please sign in to comment.