Skip to content

Commit

Permalink
fix: bump check error
Browse files Browse the repository at this point in the history
  • Loading branch information
LuuuXXX committed Mar 14, 2024
1 parent 7065f0e commit 700a221
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions crates/xtask-bump-check/src/xtask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,8 @@ fn changed<'r, 'ws>(
(relative_pkg_root, pkg)
})
.collect::<Vec<_>>();
let base_tree = base_commit.as_object().peel_to_tree()?;
let head_tree = head.as_object().peel_to_tree()?;
let diff = repo.diff_tree_to_tree(Some(&base_tree), Some(&head_tree), Default::default())?;

let diff = symmetric_diff(repo, base_commit, head).unwrap();
let mut changed_members = HashMap::new();

for delta in diff.deltas() {
Expand All @@ -354,6 +352,27 @@ fn changed<'r, 'ws>(
Ok(changed_members)
}

/// Using a "symmetric difference" between base and head.
fn symmetric_diff<'a>(
repo: &'a git2::Repository,
base: &'a git2::Commit<'a>,
head: &'a git2::Commit<'a>,
) -> CargoResult<git2::Diff<'a>> {
let ancestor_oid = repo.merge_base(base.id(), head.id()).unwrap();
let ancestor_commit = repo.find_commit(ancestor_oid).unwrap();
let ancestor_tree = ancestor_commit.as_object().peel_to_tree()?;
let head_tree = head.as_object().peel_to_tree()?;
let mut diff =
repo.diff_tree_to_tree(Some(&ancestor_tree), Some(&head_tree), Default::default())?;
if ancestor_commit.id() != base.id() {
let base_tree = base.as_object().peel_to_tree()?;
let diff_base =
repo.diff_tree_to_tree(Some(&ancestor_tree), Some(&base_tree), Default::default())?;
diff.merge(&diff_base).unwrap();
}
Ok(diff)
}

/// Compares version against published crates on crates.io.
///
/// Assumption: We always release a version larger than all existing versions.
Expand Down

0 comments on commit 700a221

Please sign in to comment.