cli: git: split loop that collects push directions and new targets

Just a minor code cleanup.
This commit is contained in:
Yuya Nishihara 2024-06-04 16:40:04 +09:00
parent 3050685ff3
commit e9db051b84

View file

@ -916,12 +916,15 @@ fn cmd_git_push(
return Ok(()); return Ok(());
} }
let mut new_heads = vec![];
let mut branch_push_direction = HashMap::new(); let mut branch_push_direction = HashMap::new();
for (branch_name, update) in &branch_updates { for (branch_name, update) in &branch_updates {
if let Some(new_target) = &update.new_target { let BranchPushUpdate {
new_heads.push(new_target.clone()); old_target: Some(old_target),
if let Some(old_target) = &update.old_target { new_target: Some(new_target),
} = update
else {
continue;
};
assert_ne!(old_target, new_target); assert_ne!(old_target, new_target);
branch_push_direction.insert( branch_push_direction.insert(
branch_name.to_string(), branch_name.to_string(),
@ -934,11 +937,13 @@ fn cmd_git_push(
}, },
); );
} }
}
}
// Check if there are conflicts in any commits we're about to push that haven't // Check if there are conflicts in any commits we're about to push that haven't
// already been pushed. // already been pushed.
let new_heads = branch_updates
.iter()
.filter_map(|(_, update)| update.new_target.clone())
.collect_vec();
let mut old_heads = repo let mut old_heads = repo
.view() .view()
.remote_branches(&remote) .remote_branches(&remote)