diff options
author | Justin Worthe <justin@jemstep.com> | 2020-03-13 12:44:51 +0200 |
---|---|---|
committer | Justin Worthe <justin@jemstep.com> | 2020-03-13 12:44:51 +0200 |
commit | 6d2311c9497097b34c7b31e8c6721f151597fa79 (patch) | |
tree | bd51f6de3b40bb54ad2ae422c9a18ad542697854 | |
parent | 8254139ed016e77e20d71e6ea173c02d163e3d24 (diff) |
PYKE-11910: Simplified hairy iterator code with a mutable for loop
-rw-r--r-- | src/policies.rs | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/src/policies.rs b/src/policies.rs index 2e0009f..5eed65f 100644 --- a/src/policies.rs +++ b/src/policies.rs @@ -357,28 +357,24 @@ fn verify_rebased<G: Git>( Ok(PolicyResult::Ok) } else if !git.is_descendent_of(*new_commit_id, *old_commit_id)? { info!( - "Rebase verification passed for {0}: Commit Id {0} is not a descendent of Commit Id {1}, it is most likely that a force-push has occurred", - new_commit_id, - old_commit_id - ); + "Rebase verification passed for {0}: Commit Id {0} is not a descendent of Commit Id {1}, it is most likely that a force-push has occurred", + new_commit_id, + old_commit_id + ); Ok(PolicyResult::Ok) } else { - let new_commit_is_rebased = new_commit - .parents - .iter() - .map(|parent_id| { - git.is_descendent_of(*parent_id, *old_commit_id) - .map(|is_descendent| is_descendent || *parent_id == *old_commit_id) - }) - .collect::<Result<Vec<bool>, _>>()? - .iter() - .all(|x| *x); + let mut new_commit_is_rebased = true; + for parent_id in &new_commit.parents { + let parent_is_descendent_of_old_id = parent_id == old_commit_id + || git.is_descendent_of(*parent_id, *old_commit_id)?; + new_commit_is_rebased = new_commit_is_rebased && parent_is_descendent_of_old_id; + } if new_commit_is_rebased { info!( - "Rebase verification passed for {}: Branch is up to date with the mainline it's being merged into", - new_commit_id - ); + "Rebase verification passed for {}: Branch is up to date with the mainline it's being merged into", + new_commit_id + ); Ok(PolicyResult::Ok) } else { error!("Rebase verification failed for {}: branch must be rebased before it can be merged into the mainline", new_commit_id); |