Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not borrow shell across registry query #13647

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 35 additions & 21 deletions src/cargo/ops/cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,14 @@ fn print_lockfile_generation(
resolve: &Resolve,
registry: &mut PackageRegistry<'_>,
) -> CargoResult<()> {
let mut shell = gctx.shell();

let diff = PackageDiff::new(&resolve);
let num_pkgs: usize = diff.iter().map(|d| d.added.len()).sum();
if num_pkgs <= 1 {
// just ourself, nothing worth reporting
return Ok(());
}
shell.status("Locking", format!("{num_pkgs} packages"))?;
gctx.shell()
.status("Locking", format!("{num_pkgs} packages"))?;

for diff in diff {
fn format_latest(version: semver::Version) -> String {
Expand Down Expand Up @@ -226,7 +225,11 @@ fn print_lockfile_generation(
};

if let Some(latest) = latest {
shell.status_with_color("Adding", format!("{package}{latest}"), &style::NOTE)?;
gctx.shell().status_with_color(
"Adding",
format!("{package}{latest}"),
&style::NOTE,
)?;
}
}
}
Expand All @@ -240,15 +243,14 @@ fn print_lockfile_sync(
resolve: &Resolve,
registry: &mut PackageRegistry<'_>,
) -> CargoResult<()> {
let mut shell = gctx.shell();

let diff = PackageDiff::diff(&previous_resolve, &resolve);
let num_pkgs: usize = diff.iter().map(|d| d.added.len()).sum();
if num_pkgs == 0 {
return Ok(());
}
let plural = if num_pkgs == 1 { "" } else { "s" };
shell.status("Locking", format!("{num_pkgs} package{plural}"))?;
gctx.shell()
.status("Locking", format!("{num_pkgs} package{plural}"))?;

for diff in diff {
fn format_latest(version: semver::Version) -> String {
Expand Down Expand Up @@ -296,9 +298,11 @@ fn print_lockfile_sync(
// This metadata is often stuff like git commit hashes, which are
// not meaningfully ordered.
if removed.version().cmp_precedence(added.version()) == Ordering::Greater {
shell.status_with_color("Downgrading", msg, &style::WARN)?;
gctx.shell()
.status_with_color("Downgrading", msg, &style::WARN)?;
} else {
shell.status_with_color("Updating", msg, &style::GOOD)?;
gctx.shell()
.status_with_color("Updating", msg, &style::GOOD)?;
}
} else {
for package in diff.added.iter() {
Expand All @@ -315,7 +319,11 @@ fn print_lockfile_sync(
}
.unwrap_or_default();

shell.status_with_color("Adding", format!("{package}{latest}"), &style::NOTE)?;
gctx.shell().status_with_color(
"Adding",
format!("{package}{latest}"),
&style::NOTE,
)?;
}
}
}
Expand All @@ -329,8 +337,6 @@ pub fn print_lockfile_updates(
resolve: &Resolve,
registry: &mut PackageRegistry<'_>,
) -> CargoResult<()> {
let mut shell = gctx.shell();

let mut unchanged_behind = 0;
for diff in PackageDiff::diff(&previous_resolve, &resolve) {
fn format_latest(version: semver::Version) -> String {
Expand Down Expand Up @@ -378,13 +384,16 @@ pub fn print_lockfile_updates(
// This metadata is often stuff like git commit hashes, which are
// not meaningfully ordered.
if removed.version().cmp_precedence(added.version()) == Ordering::Greater {
shell.status_with_color("Downgrading", msg, &style::WARN)?;
gctx.shell()
.status_with_color("Downgrading", msg, &style::WARN)?;
} else {
shell.status_with_color("Updating", msg, &style::GOOD)?;
gctx.shell()
.status_with_color("Updating", msg, &style::GOOD)?;
}
} else {
for package in diff.removed.iter() {
shell.status_with_color("Removing", format!("{package}"), &style::ERROR)?;
gctx.shell()
.status_with_color("Removing", format!("{package}"), &style::ERROR)?;
}
for package in diff.added.iter() {
let latest = if !possibilities.is_empty() {
Expand All @@ -400,7 +409,11 @@ pub fn print_lockfile_updates(
}
.unwrap_or_default();

shell.status_with_color("Adding", format!("{package}{latest}"), &style::NOTE)?;
gctx.shell().status_with_color(
"Adding",
format!("{package}{latest}"),
&style::NOTE,
)?;
}
}
for package in &diff.unchanged {
Expand All @@ -418,8 +431,8 @@ pub fn print_lockfile_updates(

if let Some(latest) = latest {
unchanged_behind += 1;
if shell.verbosity() == Verbosity::Verbose {
shell.status_with_color(
if gctx.shell().verbosity() == Verbosity::Verbose {
gctx.shell().status_with_color(
"Unchanged",
format!("{package}{latest}"),
&anstyle::Style::new().bold(),
Expand All @@ -428,13 +441,14 @@ pub fn print_lockfile_updates(
}
}
}
if shell.verbosity() == Verbosity::Verbose {
shell.note(

if gctx.shell().verbosity() == Verbosity::Verbose {
gctx.shell().note(
"to see how you depend on a package, run `cargo tree --invert --package <dep>@<ver>`",
)?;
} else {
if 0 < unchanged_behind {
shell.note(format!(
gctx.shell().note(format!(
"pass `--verbose` to see {unchanged_behind} unchanged dependencies behind latest"
))?;
}
Expand Down