mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-12 07:24:11 +00:00
workspace: one less cloning of workspace_root in init_external_git()
Just a trivial code cleanup.
This commit is contained in:
parent
c866b4a42d
commit
dce640aaf1
1 changed files with 23 additions and 20 deletions
|
@ -166,26 +166,29 @@ impl Workspace {
|
|||
workspace_root: &Path,
|
||||
git_repo_path: &Path,
|
||||
) -> Result<(Self, Arc<ReadonlyRepo>), WorkspaceInitError> {
|
||||
let workspace_root = workspace_root.to_owned();
|
||||
let git_repo_path = git_repo_path.to_owned();
|
||||
Self::init_with_backend(user_settings, &workspace_root.clone(), &move |store_path| {
|
||||
// If the git repo is inside the workspace, use a relative path to it so the
|
||||
// whole workspace can be moved without breaking.
|
||||
// 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_git_repo_path =
|
||||
match (workspace_root.canonicalize(), git_repo_path.canonicalize()) {
|
||||
(Ok(workspace_root), Ok(git_repo_path))
|
||||
if git_repo_path.starts_with(&workspace_root) =>
|
||||
{
|
||||
file_util::relative_path(store_path, &git_repo_path)
|
||||
}
|
||||
_ => git_repo_path.to_owned(),
|
||||
};
|
||||
let backend = GitBackend::init_external(store_path, &store_relative_git_repo_path)?;
|
||||
Ok(Box::new(backend) as Box<dyn Backend>)
|
||||
})
|
||||
let backend_initializer = {
|
||||
let workspace_root = workspace_root.to_owned();
|
||||
let git_repo_path = git_repo_path.to_owned();
|
||||
move |store_path: &Path| -> Result<Box<dyn Backend>, BackendInitError> {
|
||||
// If the git repo is inside the workspace, use a relative path to it so the
|
||||
// whole workspace can be moved without breaking.
|
||||
// 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_git_repo_path =
|
||||
match (workspace_root.canonicalize(), git_repo_path.canonicalize()) {
|
||||
(Ok(workspace_root), Ok(git_repo_path))
|
||||
if git_repo_path.starts_with(&workspace_root) =>
|
||||
{
|
||||
file_util::relative_path(store_path, &git_repo_path)
|
||||
}
|
||||
_ => git_repo_path.to_owned(),
|
||||
};
|
||||
let backend = GitBackend::init_external(store_path, &store_relative_git_repo_path)?;
|
||||
Ok(Box::new(backend))
|
||||
}
|
||||
};
|
||||
Self::init_with_backend(user_settings, workspace_root, &backend_initializer)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
|
|
Loading…
Reference in a new issue