@@ -10,7 +10,6 @@ use crate::util::cache_lock::CacheLockMode;
10
10
use crate :: util:: context:: GlobalContext ;
11
11
use crate :: util:: style;
12
12
use crate :: util:: CargoResult ;
13
- use anstyle:: Style ;
14
13
use std:: cmp:: Ordering ;
15
14
use std:: collections:: { BTreeMap , HashSet } ;
16
15
use tracing:: debug;
@@ -154,7 +153,7 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
154
153
true ,
155
154
) ?;
156
155
157
- print_lockfile_update ( opts. gctx , & previous_resolve, & resolve, & mut registry) ?;
156
+ print_lockfile_updates ( opts. gctx , & previous_resolve, & resolve, & mut registry) ?;
158
157
if opts. dry_run {
159
158
opts. gctx
160
159
. shell ( )
@@ -165,16 +164,14 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
165
164
Ok ( ( ) )
166
165
}
167
166
168
- fn print_lockfile_update (
167
+ fn print_lockfile_updates (
169
168
gctx : & GlobalContext ,
170
169
previous_resolve : & Resolve ,
171
170
resolve : & Resolve ,
172
171
registry : & mut PackageRegistry < ' _ > ,
173
172
) -> CargoResult < ( ) > {
174
- // Summarize what is changing for the user.
175
- let print_change = |status : & str , msg : String , color : & Style | {
176
- gctx. shell ( ) . status_with_color ( status, msg, color)
177
- } ;
173
+ let mut shell = gctx. shell ( ) ;
174
+
178
175
let mut unchanged_behind = 0 ;
179
176
for diff in PackageDiff :: diff ( & previous_resolve, & resolve) {
180
177
fn format_latest ( version : semver:: Version ) -> String {
@@ -222,13 +219,13 @@ fn print_lockfile_update(
222
219
// This metadata is often stuff like git commit hashes, which are
223
220
// not meaningfully ordered.
224
221
if removed. version ( ) . cmp_precedence ( added. version ( ) ) == Ordering :: Greater {
225
- print_change ( "Downgrading" , msg, & style:: WARN ) ?;
222
+ shell . status_with_color ( "Downgrading" , msg, & style:: WARN ) ?;
226
223
} else {
227
- print_change ( "Updating" , msg, & style:: GOOD ) ?;
224
+ shell . status_with_color ( "Updating" , msg, & style:: GOOD ) ?;
228
225
}
229
226
} else {
230
227
for package in diff. removed . iter ( ) {
231
- print_change ( "Removing" , format ! ( "{package}" ) , & style:: ERROR ) ?;
228
+ shell . status_with_color ( "Removing" , format ! ( "{package}" ) , & style:: ERROR ) ?;
232
229
}
233
230
for package in diff. added . iter ( ) {
234
231
let latest = if !possibilities. is_empty ( ) {
@@ -244,7 +241,7 @@ fn print_lockfile_update(
244
241
}
245
242
. unwrap_or_default ( ) ;
246
243
247
- print_change ( "Adding" , format ! ( "{package}{latest}" ) , & style:: NOTE ) ?;
244
+ shell . status_with_color ( "Adding" , format ! ( "{package}{latest}" ) , & style:: NOTE ) ?;
248
245
}
249
246
}
250
247
for package in & diff. unchanged {
@@ -262,8 +259,8 @@ fn print_lockfile_update(
262
259
263
260
if let Some ( latest) = latest {
264
261
unchanged_behind += 1 ;
265
- if gctx . shell ( ) . verbosity ( ) == Verbosity :: Verbose {
266
- gctx . shell ( ) . status_with_color (
262
+ if shell. verbosity ( ) == Verbosity :: Verbose {
263
+ shell. status_with_color (
267
264
"Unchanged" ,
268
265
format ! ( "{package}{latest}" ) ,
269
266
& anstyle:: Style :: new ( ) . bold ( ) ,
@@ -272,13 +269,13 @@ fn print_lockfile_update(
272
269
}
273
270
}
274
271
}
275
- if gctx . shell ( ) . verbosity ( ) == Verbosity :: Verbose {
276
- gctx . shell ( ) . note (
272
+ if shell. verbosity ( ) == Verbosity :: Verbose {
273
+ shell. note (
277
274
"to see how you depend on a package, run `cargo tree --invert --package <dep>@<ver>`" ,
278
275
) ?;
279
276
} else {
280
277
if 0 < unchanged_behind {
281
- gctx . shell ( ) . note ( format ! (
278
+ shell. note ( format ! (
282
279
"pass `--verbose` to see {unchanged_behind} unchanged dependencies behind latest"
283
280
) ) ?;
284
281
}
0 commit comments