From e9db051b84ab78236cde77fcde1df4287cb96e85 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Tue, 4 Jun 2024 16:40:04 +0900 Subject: [PATCH] cli: git: split loop that collects push directions and new targets Just a minor code cleanup. --- cli/src/commands/git.rs | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/cli/src/commands/git.rs b/cli/src/commands/git.rs index 0f68ae10e..e04d6874b 100644 --- a/cli/src/commands/git.rs +++ b/cli/src/commands/git.rs @@ -916,29 +916,34 @@ fn cmd_git_push( return Ok(()); } - let mut new_heads = vec![]; let mut branch_push_direction = HashMap::new(); for (branch_name, update) in &branch_updates { - if let Some(new_target) = &update.new_target { - new_heads.push(new_target.clone()); - if let Some(old_target) = &update.old_target { - assert_ne!(old_target, new_target); - branch_push_direction.insert( - branch_name.to_string(), - if repo.index().is_ancestor(old_target, new_target) { - BranchMoveDirection::Forward - } else if repo.index().is_ancestor(new_target, old_target) { - BranchMoveDirection::Backward - } else { - BranchMoveDirection::Sideways - }, - ); - } - } + let BranchPushUpdate { + old_target: Some(old_target), + new_target: Some(new_target), + } = update + else { + continue; + }; + assert_ne!(old_target, new_target); + branch_push_direction.insert( + branch_name.to_string(), + if repo.index().is_ancestor(old_target, new_target) { + BranchMoveDirection::Forward + } else if repo.index().is_ancestor(new_target, old_target) { + BranchMoveDirection::Backward + } else { + BranchMoveDirection::Sideways + }, + ); } // Check if there are conflicts in any commits we're about to push that haven't // already been pushed. + let new_heads = branch_updates + .iter() + .filter_map(|(_, update)| update.new_target.clone()) + .collect_vec(); let mut old_heads = repo .view() .remote_branches(&remote)