Skip to content

Commit

Permalink
fix(update): Show updates for all relevant packages
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Feb 1, 2024
1 parent 76f3874 commit 195138b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 28 deletions.
78 changes: 52 additions & 26 deletions src/cargo/ops/cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,42 +178,43 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
&& candidate.minor == current.minor
&& candidate.patch == current.patch))
}

let highest_present = [added.iter().rev().next(), unchanged.iter().rev().next()]
let possibilities = if let Some(query) = [added.iter(), unchanged.iter()]
.into_iter()
.flatten()
.max_by_key(|s| s.version());
let latest = if let Some(present) = highest_present.filter(|p| p.source_id().is_registry())
.next()
.filter(|s| s.source_id().is_registry())
{
let query = crate::core::dependency::Dependency::parse(
present.name(),
None,
present.source_id(),
)?;
let possibilities = loop {
let query =
crate::core::dependency::Dependency::parse(query.name(), None, query.source_id())?;
loop {
match registry.query_vec(&query, QueryKind::Exact) {
std::task::Poll::Ready(res) => {
break res?;
}
std::task::Poll::Pending => registry.block_until_ready()?,
}
};
let present_version = present.version();
possibilities
.iter()
.map(|s| s.as_summary())
.filter(|s| is_latest(s.version(), present_version))
.map(|s| s.version().clone())
.max()
.map(format_latest)
}
} else {
None
}
.unwrap_or_default();
vec![]
};

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

let latest = if !possibilities.is_empty() {
possibilities
.iter()
.map(|s| s.as_summary())
.filter(|s| is_latest(s.version(), added.version()))
.map(|s| s.version().clone())
.max()
.map(format_latest)
} else {
None
}
.unwrap_or_default();

let msg = if removed.source_id().is_git() {
format!(
"{removed} -> #{}",
Expand All @@ -237,20 +238,45 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
print_change("Removing", format!("{package}"), &style::ERROR)?;
}
for package in added.iter() {
let latest = if !possibilities.is_empty() {
possibilities
.iter()
.map(|s| s.as_summary())
.filter(|s| is_latest(s.version(), package.version()))
.map(|s| s.version().clone())
.max()
.map(format_latest)
} else {
None
}
.unwrap_or_default();

print_change("Adding", format!("{package}{latest}"), &style::NOTE)?;
}
}
if !latest.is_empty() {
if opts.config.shell().verbosity() == Verbosity::Verbose {
for package in &unchanged {
for package in &unchanged {
let latest = if !possibilities.is_empty() {
possibilities
.iter()
.map(|s| s.as_summary())
.filter(|s| is_latest(s.version(), package.version()))
.map(|s| s.version().clone())
.max()
.map(format_latest)
} else {
None
};

if let Some(latest) = latest {
unchanged_behind += 1;
if opts.config.shell().verbosity() == Verbosity::Verbose {
opts.config.shell().status_with_color(
"Unchanged",
format!("{package}{latest}"),
&anstyle::Style::new().bold(),
)?;
}
}
unchanged_behind += unchanged.len();
}
}
if opts.config.shell().verbosity() == Verbosity::Verbose {
Expand Down
7 changes: 5 additions & 2 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ fn update_precise() {
"\
[UPDATING] `[..]` index
[DOWNGRADING] serde v0.2.1 -> v0.2.0
[NOTE] Pass `--verbose` to see 1 unchanged dependencies behind latest
",
)
.run();
Expand Down Expand Up @@ -1512,7 +1513,7 @@ fn report_behind() {
"\
[UPDATING] `dummy-registry` index
[UPDATING] breaking v0.1.0 -> v0.1.1 (latest: v0.2.0)
[NOTE] Pass `--verbose` to see 1 unchanged dependencies behind latest
[NOTE] Pass `--verbose` to see 2 unchanged dependencies behind latest
[WARNING] not updating lockfile due to dry run
",
)
Expand All @@ -1524,6 +1525,7 @@ fn report_behind() {
[UPDATING] `dummy-registry` index
[UPDATING] breaking v0.1.0 -> v0.1.1 (latest: v0.2.0)
[UNCHANGED] pre v1.0.0-alpha.0 (latest: v1.0.0-alpha.1)
[UNCHANGED] two-ver v0.1.0 (latest: v0.2.0)
[NOTE] To see how you depend on a package, run `cargo tree --invert --package <dep>@<ver>`
[WARNING] not updating lockfile due to dry run
",
Expand All @@ -1536,7 +1538,7 @@ fn report_behind() {
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[NOTE] Pass `--verbose` to see 2 unchanged dependencies behind latest
[NOTE] Pass `--verbose` to see 3 unchanged dependencies behind latest
[WARNING] not updating lockfile due to dry run
",
)
Expand All @@ -1548,6 +1550,7 @@ fn report_behind() {
[UPDATING] `dummy-registry` index
[UNCHANGED] breaking v0.1.1 (latest: v0.2.0)
[UNCHANGED] pre v1.0.0-alpha.0 (latest: v1.0.0-alpha.1)
[UNCHANGED] two-ver v0.1.0 (latest: v0.2.0)
[NOTE] To see how you depend on a package, run `cargo tree --invert --package <dep>@<ver>`
[WARNING] not updating lockfile due to dry run
",
Expand Down

0 comments on commit 195138b

Please sign in to comment.