From 700a22168724b250fc75b6772b0942e9399ddcf1 Mon Sep 17 00:00:00 2001 From: LuuuX Date: Thu, 14 Mar 2024 17:58:46 +0800 Subject: [PATCH] fix: bump check error --- crates/xtask-bump-check/src/xtask.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/crates/xtask-bump-check/src/xtask.rs b/crates/xtask-bump-check/src/xtask.rs index 2ae97b2f7df4..8ccb460787fb 100644 --- a/crates/xtask-bump-check/src/xtask.rs +++ b/crates/xtask-bump-check/src/xtask.rs @@ -333,10 +333,8 @@ fn changed<'r, 'ws>( (relative_pkg_root, pkg) }) .collect::>(); - 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() { @@ -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> { + 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.