diff --git a/cli/examples/custom-working-copy/main.rs b/cli/examples/custom-working-copy/main.rs index 85041475a..fb31f19fe 100644 --- a/cli/examples/custom-working-copy/main.rs +++ b/cli/examples/custom-working-copy/main.rs @@ -128,7 +128,7 @@ impl ConflictsWorkingCopy { }) } - fn initializer() -> Box { + fn initializer() -> Box> { Box::new( |store, working_copy_path, state_path, workspace_id, operation_id| { let wc = Self::init( diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 135927b04..76810dc2f 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -122,22 +122,22 @@ pub enum RepoInitError { } impl ReadonlyRepo { - pub fn default_op_store_initializer() -> &'static OpStoreInitializer { + pub fn default_op_store_initializer() -> &'static OpStoreInitializer<'static> { &|_settings, store_path| Box::new(SimpleOpStore::init(store_path)) } - pub fn default_op_heads_store_initializer() -> &'static OpHeadsStoreInitializer { + pub fn default_op_heads_store_initializer() -> &'static OpHeadsStoreInitializer<'static> { &|_settings, store_path| { let store = SimpleOpHeadsStore::init(store_path); Box::new(store) } } - pub fn default_index_store_initializer() -> &'static IndexStoreInitializer { + pub fn default_index_store_initializer() -> &'static IndexStoreInitializer<'static> { &|_settings, store_path| Box::new(DefaultIndexStore::init(store_path)) } - pub fn default_submodule_store_initializer() -> &'static SubmoduleStoreInitializer { + pub fn default_submodule_store_initializer() -> &'static SubmoduleStoreInitializer<'static> { &|_settings, store_path| Box::new(DefaultSubmoduleStore::init(store_path)) } @@ -343,12 +343,13 @@ impl Repo for ReadonlyRepo { } } -pub type BackendInitializer = - dyn Fn(&UserSettings, &Path) -> Result, BackendInitError>; -pub type OpStoreInitializer = dyn Fn(&UserSettings, &Path) -> Box; -pub type OpHeadsStoreInitializer = dyn Fn(&UserSettings, &Path) -> Box; -pub type IndexStoreInitializer = dyn Fn(&UserSettings, &Path) -> Box; -pub type SubmoduleStoreInitializer = dyn Fn(&UserSettings, &Path) -> Box; +pub type BackendInitializer<'a> = + dyn Fn(&UserSettings, &Path) -> Result, BackendInitError> + 'a; +pub type OpStoreInitializer<'a> = dyn Fn(&UserSettings, &Path) -> Box + 'a; +pub type OpHeadsStoreInitializer<'a> = dyn Fn(&UserSettings, &Path) -> Box + 'a; +pub type IndexStoreInitializer<'a> = dyn Fn(&UserSettings, &Path) -> Box + 'a; +pub type SubmoduleStoreInitializer<'a> = + dyn Fn(&UserSettings, &Path) -> Box + 'a; type BackendFactory = Box Result, BackendLoadError>>; diff --git a/lib/src/workspace.rs b/lib/src/workspace.rs index adfb70037..56e98bdde 100644 --- a/lib/src/workspace.rs +++ b/lib/src/workspace.rs @@ -147,7 +147,7 @@ impl Workspace { user_settings: &UserSettings, workspace_root: &Path, ) -> Result<(Self, Arc), WorkspaceInitError> { - let backend_initializer: &'static BackendInitializer = + let backend_initializer: &BackendInitializer = &|_settings, store_path| Ok(Box::new(LocalBackend::init(store_path))); let signer = Signer::from_settings(user_settings)?; Self::init_with_backend(user_settings, workspace_root, backend_initializer, signer) @@ -159,7 +159,7 @@ impl Workspace { user_settings: &UserSettings, workspace_root: &Path, ) -> Result<(Self, Arc), WorkspaceInitError> { - let backend_initializer: &'static BackendInitializer = + let backend_initializer: &BackendInitializer = &|settings, store_path| Ok(Box::new(GitBackend::init_internal(settings, store_path)?)); let signer = Signer::from_settings(user_settings)?; Self::init_with_backend(user_settings, workspace_root, backend_initializer, signer) @@ -171,25 +171,21 @@ impl Workspace { user_settings: &UserSettings, workspace_root: &Path, ) -> Result<(Self, Arc), WorkspaceInitError> { - let backend_initializer = { - let workspace_root = workspace_root.to_owned(); - move |settings: &UserSettings, store_path: &Path| -> Result, _> { - // TODO: Clean up path normalization. store_path is canonicalized by - // ReadonlyRepo::init(). workspace_root will be canonicalized by - // Workspace::new(), but it's not yet here. - let store_relative_workspace_root = - if let Ok(workspace_root) = workspace_root.canonicalize() { - file_util::relative_path(store_path, &workspace_root) - } else { - workspace_root.to_owned() - }; - let backend = GitBackend::init_colocated( - settings, - store_path, - &store_relative_workspace_root, - )?; - Ok(Box::new(backend)) - } + let backend_initializer = |settings: &UserSettings, + store_path: &Path| + -> Result, _> { + // TODO: Clean up path normalization. store_path is canonicalized by + // ReadonlyRepo::init(). workspace_root will be canonicalized by + // Workspace::new(), but it's not yet here. + let store_relative_workspace_root = + if let Ok(workspace_root) = workspace_root.canonicalize() { + file_util::relative_path(store_path, &workspace_root) + } else { + workspace_root.to_owned() + }; + let backend = + GitBackend::init_colocated(settings, store_path, &store_relative_workspace_root)?; + Ok(Box::new(backend)) }; let signer = Signer::from_settings(user_settings)?; Self::init_with_backend(user_settings, workspace_root, &backend_initializer, signer) @@ -502,7 +498,7 @@ impl WorkspaceLoader { } } -pub fn default_working_copy_initializer() -> &'static WorkingCopyInitializer { +pub fn default_working_copy_initializer() -> &'static WorkingCopyInitializer<'static> { &|store: Arc, working_copy_path, state_path, workspace_id, operation_id| { let wc = LocalWorkingCopy::init( store, @@ -530,11 +526,12 @@ pub fn default_working_copy_factories() -> HashMap { factories } -pub type WorkingCopyInitializer = dyn Fn( - Arc, - PathBuf, - PathBuf, - WorkspaceId, - OperationId, -) -> Result, WorkingCopyStateError>; +pub type WorkingCopyInitializer<'a> = dyn Fn( + Arc, + PathBuf, + PathBuf, + WorkspaceId, + OperationId, + ) -> Result, WorkingCopyStateError> + + 'a; pub type WorkingCopyFactory = Box, &Path, &Path) -> Box>; diff --git a/lib/tests/test_git.rs b/lib/tests/test_git.rs index 516c782f0..cc8ff62da 100644 --- a/lib/tests/test_git.rs +++ b/lib/tests/test_git.rs @@ -1119,7 +1119,7 @@ impl GitRepoData { let repo = ReadonlyRepo::init( &settings, &jj_repo_dir, - &move |settings, store_path| { + &|settings, store_path| { Ok(Box::new(GitBackend::init_external( settings, store_path, @@ -1985,7 +1985,7 @@ fn test_init() { let repo = &ReadonlyRepo::init( &settings, &jj_repo_dir, - &move |settings, store_path| { + &|settings, store_path| { Ok(Box::new(GitBackend::init_external( settings, store_path, @@ -2311,7 +2311,7 @@ fn set_up_push_repos(settings: &UserSettings, temp_dir: &TempDir) -> PushTestSet let jj_repo = ReadonlyRepo::init( settings, &jj_repo_dir, - &move |settings, store_path| { + &|settings, store_path| { Ok(Box::new(GitBackend::init_external( settings, store_path,