Skip to content

Commit

Permalink
cli: construct "op restore"-d view by cloning each field
Browse files Browse the repository at this point in the history
This will force us to think about whether new field belongs to "repo" or
"remote".
  • Loading branch information
yuja committed Oct 14, 2023
1 parent b7c7b19 commit af70818
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions cli/src/commands/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit af70818

Please sign in to comment.