From f96ff038bd14c23ea4d1dd22d59231e3d1095285 Mon Sep 17 00:00:00 2001 From: dploch Date: Tue, 12 Mar 2024 16:28:47 -0400 Subject: [PATCH] workspace: allow extensions to customize the creation of the .jj directory Some specialized filesystems may need custom behavior here, by synthesizing the directory through another mechanism, or by accepting its prior existence in specific circumstances. --- cli/examples/custom-working-copy/main.rs | 5 ++++- lib/src/workspace.rs | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cli/examples/custom-working-copy/main.rs b/cli/examples/custom-working-copy/main.rs index 40bdcf4b48..b48e031576 100644 --- a/cli/examples/custom-working-copy/main.rs +++ b/cli/examples/custom-working-copy/main.rs @@ -34,7 +34,9 @@ use jj_lib::working_copy::{ CheckoutError, CheckoutStats, LockedWorkingCopy, ResetError, SnapshotError, SnapshotOptions, WorkingCopy, WorkingCopyFactory, WorkingCopyStateError, }; -use jj_lib::workspace::{default_working_copy_factories, Workspace, WorkspaceInitError}; +use jj_lib::workspace::{ + create_jj_dir, default_working_copy_factories, Workspace, WorkspaceInitError, +}; #[derive(clap::Parser, Clone, Debug)] enum CustomCommand { @@ -58,6 +60,7 @@ fn run_custom_command( Workspace::init_with_factories( command_helper.settings(), wc_path, + create_jj_dir, &backend_initializer, Signer::from_settings(command_helper.settings()) .map_err(WorkspaceInitError::SignInit)?, diff --git a/lib/src/workspace.rs b/lib/src/workspace.rs index 49fe714772..067fa4aa14 100644 --- a/lib/src/workspace.rs +++ b/lib/src/workspace.rs @@ -87,7 +87,11 @@ pub struct Workspace { working_copy: Box, } -fn create_jj_dir(workspace_root: &Path) -> Result { +/// Default function to create the .jj directory inside an existing repo +/// directory. +/// +/// Custom extensions can override this to do alternative initialization. +pub fn create_jj_dir(workspace_root: &Path) -> Result { let jj_dir = workspace_root.join(".jj"); match std::fs::create_dir(&jj_dir).context(&jj_dir) { Ok(()) => Ok(jj_dir), @@ -230,6 +234,7 @@ impl Workspace { pub fn init_with_factories( user_settings: &UserSettings, workspace_root: &Path, + jj_dir_creator: impl FnOnce(&Path) -> Result, backend_initializer: &BackendInitializer, signer: Signer, op_store_initializer: &OpStoreInitializer, @@ -239,7 +244,7 @@ impl Workspace { working_copy_factory: &dyn WorkingCopyFactory, workspace_id: WorkspaceId, ) -> Result<(Self, Arc), WorkspaceInitError> { - let jj_dir = create_jj_dir(workspace_root)?; + let jj_dir = jj_dir_creator(workspace_root)?; (|| { let repo_dir = jj_dir.join("repo"); std::fs::create_dir(&repo_dir).context(&repo_dir)?; @@ -284,6 +289,7 @@ impl Workspace { Self::init_with_factories( user_settings, workspace_root, + create_jj_dir, backend_initializer, signer, ReadonlyRepo::default_op_store_initializer(),