undo: optimization for restoring/preserving remote branches on undo

This commit is contained in:
Ilya Grigoriev 2023-05-31 22:15:37 -07:00
parent 63fe67bf74
commit 001db5a978

View file

@ -166,19 +166,22 @@ fn view_with_desired_portions_restored(
current_view.git_refs.clone() current_view.git_refs.clone()
}; };
if what.contains(&UndoWhatToRestore::RemoteTracking) == what.contains(&UndoWhatToRestore::Repo)
{
// new_view already contains the correct branches; we can short-curcuit
return new_view;
}
let all_branch_names: BTreeSet<_> = itertools::chain( let all_branch_names: BTreeSet<_> = itertools::chain(
view_being_restored.branches.keys(), view_being_restored.branches.keys(),
current_view.branches.keys(), current_view.branches.keys(),
) )
.collect(); .collect();
let branch_source_view = if what.contains(&UndoWhatToRestore::RemoteTracking) { let branch_source_view = if what.contains(&UndoWhatToRestore::RemoteTracking) {
view_being_restored view_being_restored
} else { } else {
current_view current_view
}; };
// Short-term TODO: we will optimize this to avoid recreating branches if they
// are already correct in `new_view`
let mut new_branches = BTreeMap::default(); let mut new_branches = BTreeMap::default();
for branch_name in all_branch_names { for branch_name in all_branch_names {
let local_target = new_view let local_target = new_view