forked from mirrors/jj
repo, workspace: remove 'static lifetime bound from initializer functions
This commit is contained in:
parent
48d586cba0
commit
1db033504c
4 changed files with 41 additions and 43 deletions
|
@ -128,7 +128,7 @@ impl ConflictsWorkingCopy {
|
|||
})
|
||||
}
|
||||
|
||||
fn initializer() -> Box<WorkingCopyInitializer> {
|
||||
fn initializer() -> Box<WorkingCopyInitializer<'static>> {
|
||||
Box::new(
|
||||
|store, working_copy_path, state_path, workspace_id, operation_id| {
|
||||
let wc = Self::init(
|
||||
|
|
|
@ -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<Box<dyn Backend>, BackendInitError>;
|
||||
pub type OpStoreInitializer = dyn Fn(&UserSettings, &Path) -> Box<dyn OpStore>;
|
||||
pub type OpHeadsStoreInitializer = dyn Fn(&UserSettings, &Path) -> Box<dyn OpHeadsStore>;
|
||||
pub type IndexStoreInitializer = dyn Fn(&UserSettings, &Path) -> Box<dyn IndexStore>;
|
||||
pub type SubmoduleStoreInitializer = dyn Fn(&UserSettings, &Path) -> Box<dyn SubmoduleStore>;
|
||||
pub type BackendInitializer<'a> =
|
||||
dyn Fn(&UserSettings, &Path) -> Result<Box<dyn Backend>, BackendInitError> + 'a;
|
||||
pub type OpStoreInitializer<'a> = dyn Fn(&UserSettings, &Path) -> Box<dyn OpStore> + 'a;
|
||||
pub type OpHeadsStoreInitializer<'a> = dyn Fn(&UserSettings, &Path) -> Box<dyn OpHeadsStore> + 'a;
|
||||
pub type IndexStoreInitializer<'a> = dyn Fn(&UserSettings, &Path) -> Box<dyn IndexStore> + 'a;
|
||||
pub type SubmoduleStoreInitializer<'a> =
|
||||
dyn Fn(&UserSettings, &Path) -> Box<dyn SubmoduleStore> + 'a;
|
||||
|
||||
type BackendFactory =
|
||||
Box<dyn Fn(&UserSettings, &Path) -> Result<Box<dyn Backend>, BackendLoadError>>;
|
||||
|
|
|
@ -147,7 +147,7 @@ impl Workspace {
|
|||
user_settings: &UserSettings,
|
||||
workspace_root: &Path,
|
||||
) -> Result<(Self, Arc<ReadonlyRepo>), 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<ReadonlyRepo>), 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<ReadonlyRepo>), WorkspaceInitError> {
|
||||
let backend_initializer = {
|
||||
let workspace_root = workspace_root.to_owned();
|
||||
move |settings: &UserSettings, store_path: &Path| -> Result<Box<dyn Backend>, _> {
|
||||
// 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<Box<dyn Backend>, _> {
|
||||
// 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<Store>, 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<String, WorkingCopyFactory> {
|
|||
factories
|
||||
}
|
||||
|
||||
pub type WorkingCopyInitializer = dyn Fn(
|
||||
Arc<Store>,
|
||||
PathBuf,
|
||||
PathBuf,
|
||||
WorkspaceId,
|
||||
OperationId,
|
||||
) -> Result<Box<dyn WorkingCopy>, WorkingCopyStateError>;
|
||||
pub type WorkingCopyInitializer<'a> = dyn Fn(
|
||||
Arc<Store>,
|
||||
PathBuf,
|
||||
PathBuf,
|
||||
WorkspaceId,
|
||||
OperationId,
|
||||
) -> Result<Box<dyn WorkingCopy>, WorkingCopyStateError>
|
||||
+ 'a;
|
||||
pub type WorkingCopyFactory = Box<dyn Fn(&Arc<Store>, &Path, &Path) -> Box<dyn WorkingCopy>>;
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue