Skip to content

Commit

Permalink
refactor(lockfile): Pull out dep change detection
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Mar 8, 2024
1 parent 9e18941 commit 619238e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/cargo/ops/cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,7 @@ fn print_lockfile_update(
vec![]
};

if diff.removed.len() == 1 && diff.added.len() == 1 {
let added = diff.added.into_iter().next().unwrap();
let removed = diff.removed.into_iter().next().unwrap();

if let Some((removed, added)) = diff.change() {
let latest = if !possibilities.is_empty() {
possibilities
.iter()
Expand Down Expand Up @@ -400,6 +397,19 @@ impl PackageDiff {
changes.into_iter().map(|(_, v)| v).collect()
}

/// Guess if a package upgraded/downgraded
///
/// All `PackageDiff` knows is that entries were added/removed within [`Resolve`].
/// A package could be added or removed because of dependencies from other packages
/// which makes it hard to definitively say "X was upgrade to N".
pub fn change(&self) -> Option<(&PackageId, &PackageId)> {
if self.removed.len() == 1 && self.added.len() == 1 {
Some((&self.removed[0], &self.added[0]))
} else {
None
}
}

/// For querying [`PackageRegistry`] for alternative versions to report to the user
pub fn alternatives_query(&self) -> Option<crate::core::dependency::Dependency> {
let package_id = [
Expand Down

0 comments on commit 619238e

Please sign in to comment.