From af70818128d7fcc8aca10e4654a177fa2be4a2d0 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sat, 7 Oct 2023 03:50:19 +0900 Subject: [PATCH] cli: construct "op restore"-d view by cloning each field This will force us to think about whether new field belongs to "repo" or "remote". --- cli/src/commands/operation.rs | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/cli/src/commands/operation.rs b/cli/src/commands/operation.rs index 532ea69be..7575e6989 100644 --- a/cli/src/commands/operation.rs +++ b/cli/src/commands/operation.rs @@ -161,27 +161,26 @@ fn view_with_desired_portions_restored( current_view: &jj_lib::op_store::View, what: &[UndoWhatToRestore], ) -> jj_lib::op_store::View { - let mut new_view = if what.contains(&UndoWhatToRestore::Repo) { - view_being_restored.clone() + let repo_source = if what.contains(&UndoWhatToRestore::Repo) { + view_being_restored } else { - current_view.clone() + current_view }; - - new_view.git_refs = current_view.git_refs.clone(); - new_view.git_head = current_view.git_head.clone(); - - if what.contains(&UndoWhatToRestore::RemoteTracking) == what.contains(&UndoWhatToRestore::Repo) - { - // new_view already contains the correct branches; we can short-curcuit - return new_view; - } - - if what.contains(&UndoWhatToRestore::RemoteTracking) { - new_view.remote_views = view_being_restored.remote_views.clone(); + let remote_source = if what.contains(&UndoWhatToRestore::RemoteTracking) { + view_being_restored } else { - new_view.remote_views = current_view.remote_views.clone(); + current_view + }; + jj_lib::op_store::View { + head_ids: repo_source.head_ids.clone(), + public_head_ids: repo_source.public_head_ids.clone(), + local_branches: repo_source.local_branches.clone(), + tags: repo_source.tags.clone(), + remote_views: remote_source.remote_views.clone(), + git_refs: current_view.git_refs.clone(), + git_head: current_view.git_head.clone(), + wc_commit_ids: repo_source.wc_commit_ids.clone(), } - new_view } pub fn cmd_op_undo(