mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
refactor(lockfile): Pull out change printing
This commit is contained in:
parent
29cf016014
commit
f3f1447f66
@ -154,9 +154,26 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
|
||||
true,
|
||||
)?;
|
||||
|
||||
print_lockfile_update(opts.gctx, &previous_resolve, &resolve, &mut registry)?;
|
||||
if opts.dry_run {
|
||||
opts.gctx
|
||||
.shell()
|
||||
.warn("not updating lockfile due to dry run")?;
|
||||
} else {
|
||||
ops::write_pkg_lockfile(ws, &mut resolve)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_lockfile_update(
|
||||
gctx: &GlobalContext,
|
||||
previous_resolve: &Resolve,
|
||||
resolve: &Resolve,
|
||||
registry: &mut PackageRegistry<'_>,
|
||||
) -> CargoResult<()> {
|
||||
// Summarize what is changing for the user.
|
||||
let print_change = |status: &str, msg: String, color: &Style| {
|
||||
opts.gctx.shell().status_with_color(status, msg, color)
|
||||
gctx.shell().status_with_color(status, msg, color)
|
||||
};
|
||||
let mut unchanged_behind = 0;
|
||||
for ResolvedPackageVersions {
|
||||
@ -268,8 +285,8 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
|
||||
|
||||
if let Some(latest) = latest {
|
||||
unchanged_behind += 1;
|
||||
if opts.gctx.shell().verbosity() == Verbosity::Verbose {
|
||||
opts.gctx.shell().status_with_color(
|
||||
if gctx.shell().verbosity() == Verbosity::Verbose {
|
||||
gctx.shell().status_with_color(
|
||||
"Unchanged",
|
||||
format!("{package}{latest}"),
|
||||
&anstyle::Style::new().bold(),
|
||||
@ -278,25 +295,20 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
|
||||
}
|
||||
}
|
||||
}
|
||||
if opts.gctx.shell().verbosity() == Verbosity::Verbose {
|
||||
opts.gctx.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 {
|
||||
opts.gctx.shell().note(format!(
|
||||
gctx.shell().note(format!(
|
||||
"pass `--verbose` to see {unchanged_behind} unchanged dependencies behind latest"
|
||||
))?;
|
||||
}
|
||||
}
|
||||
if opts.dry_run {
|
||||
opts.gctx
|
||||
.shell()
|
||||
.warn("not updating lockfile due to dry run")?;
|
||||
} else {
|
||||
ops::write_pkg_lockfile(ws, &mut resolve)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
return Ok(());
|
||||
|
||||
fn fill_with_deps<'a>(
|
||||
resolve: &'a Resolve,
|
||||
@ -399,4 +411,3 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
|
||||
|
||||
changes.into_iter().map(|(_, v)| v).collect()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user