Skip to content

Commit

Permalink
fix: do not borrow shell across registry query
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Mar 26, 2024
1 parent fa619a9 commit 8bb5ce6
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 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 All @@ -212,6 +211,8 @@ fn print_lockfile_generation(
vec![]
};

let mut shell = gctx.shell();

for package in diff.added.iter() {
let latest = if !possibilities.is_empty() {
possibilities
Expand Down Expand Up @@ -240,15 +241,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 All @@ -268,6 +268,7 @@ fn print_lockfile_sync(
vec![]
};

let mut shell = gctx.shell();
if let Some((removed, added)) = diff.change() {
let latest = if !possibilities.is_empty() {
possibilities
Expand Down Expand Up @@ -329,8 +330,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 All @@ -350,6 +349,7 @@ pub fn print_lockfile_updates(
vec![]
};

let mut shell = gctx.shell();
if let Some((removed, added)) = diff.change() {
let latest = if !possibilities.is_empty() {
possibilities
Expand Down Expand Up @@ -428,6 +428,8 @@ pub fn print_lockfile_updates(
}
}
}

let mut shell = gctx.shell();
if shell.verbosity() == Verbosity::Verbose {
shell.note(
"to see how you depend on a package, run `cargo tree --invert --package <dep>@<ver>`",
Expand Down

0 comments on commit 8bb5ce6

Please sign in to comment.