Skip to content

Commit 65931bc

Browse files
committed
refactor(tree): change signatures of tree printing functions to receive &Workspace
1 parent b729060 commit 65931bc

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/cargo/ops/tree/mod.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::core::dependency::DepKind;
66
use crate::core::resolver::{features::CliFeatures, ForceAllTargets, HasDevUnits};
77
use crate::core::{Package, PackageId, PackageIdSpec, PackageIdSpecQuery, Workspace};
88
use crate::ops::{self, Packages};
9-
use crate::util::{CargoResult, GlobalContext};
9+
use crate::util::CargoResult;
1010
use crate::{drop_print, drop_println};
1111
use anyhow::Context as _;
1212
use graph::Graph;
@@ -228,14 +228,14 @@ pub fn build_and_print(ws: &Workspace<'_>, opts: &TreeOptions) -> CargoResult<()
228228
try to use option `--target all` first, and then narrow your search scope accordingly.",
229229
)?;
230230
} else {
231-
print(ws.gctx(), opts, root_indexes, &pkgs_to_prune, &graph)?;
231+
print(ws, opts, root_indexes, &pkgs_to_prune, &graph)?;
232232
}
233233
Ok(())
234234
}
235235

236236
/// Prints a tree for each given root.
237237
fn print(
238-
gctx: &GlobalContext,
238+
ws: &Workspace<'_>,
239239
opts: &TreeOptions,
240240
roots: Vec<usize>,
241241
pkgs_to_prune: &[PackageIdSpec],
@@ -244,7 +244,7 @@ fn print(
244244
let format = Pattern::new(&opts.format)
245245
.with_context(|| format!("tree format `{}` not valid", opts.format))?;
246246

247-
let symbols = if gctx.shell().out_unicode() {
247+
let symbols = if ws.gctx().shell().out_unicode() {
248248
&UTF8_SYMBOLS
249249
} else {
250250
&ASCII_SYMBOLS
@@ -256,7 +256,7 @@ fn print(
256256

257257
for (i, root_index) in roots.into_iter().enumerate() {
258258
if i != 0 {
259-
drop_println!(gctx);
259+
drop_println!(ws.gctx());
260260
}
261261

262262
// A stack of bools used to determine where | symbols should appear
@@ -267,7 +267,7 @@ fn print(
267267
let mut print_stack = vec![];
268268

269269
print_node(
270-
gctx,
270+
ws,
271271
graph,
272272
root_index,
273273
&format,
@@ -287,7 +287,7 @@ fn print(
287287

288288
/// Prints a package and all of its dependencies.
289289
fn print_node<'a>(
290-
gctx: &GlobalContext,
290+
ws: &Workspace<'_>,
291291
graph: &'a Graph<'_>,
292292
node_index: usize,
293293
format: &Pattern,
@@ -303,20 +303,20 @@ fn print_node<'a>(
303303
let new = no_dedupe || visited_deps.insert(node_index);
304304

305305
match prefix {
306-
Prefix::Depth => drop_print!(gctx, "{}", levels_continue.len()),
306+
Prefix::Depth => drop_print!(ws.gctx(), "{}", levels_continue.len()),
307307
Prefix::Indent => {
308308
if let Some((last_continues, rest)) = levels_continue.split_last() {
309309
for continues in rest {
310310
let c = if *continues { symbols.down } else { " " };
311-
drop_print!(gctx, "{} ", c);
311+
drop_print!(ws.gctx(), "{} ", c);
312312
}
313313

314314
let c = if *last_continues {
315315
symbols.tee
316316
} else {
317317
symbols.ell
318318
};
319-
drop_print!(gctx, "{0}{1}{1} ", c, symbols.right);
319+
drop_print!(ws.gctx(), "{0}{1}{1} ", c, symbols.right);
320320
}
321321
}
322322
Prefix::None => {}
@@ -332,7 +332,7 @@ fn print_node<'a>(
332332
} else {
333333
" (*)"
334334
};
335-
drop_println!(gctx, "{}{}", format.display(graph, node_index), star);
335+
drop_println!(ws.gctx(), "{}{}", format.display(graph, node_index), star);
336336

337337
if !new || in_cycle {
338338
return;
@@ -346,7 +346,7 @@ fn print_node<'a>(
346346
EdgeKind::Feature,
347347
] {
348348
print_dependencies(
349-
gctx,
349+
ws,
350350
graph,
351351
node_index,
352352
format,
@@ -366,7 +366,7 @@ fn print_node<'a>(
366366

367367
/// Prints all the dependencies of a package for the given dependency kind.
368368
fn print_dependencies<'a>(
369-
gctx: &GlobalContext,
369+
ws: &Workspace<'_>,
370370
graph: &'a Graph<'_>,
371371
node_index: usize,
372372
format: &Pattern,
@@ -396,10 +396,10 @@ fn print_dependencies<'a>(
396396
if let Some(name) = name {
397397
for continues in &**levels_continue {
398398
let c = if *continues { symbols.down } else { " " };
399-
drop_print!(gctx, "{} ", c);
399+
drop_print!(ws.gctx(), "{} ", c);
400400
}
401401

402-
drop_println!(gctx, "{}", name);
402+
drop_println!(ws.gctx(), "{}", name);
403403
}
404404
}
405405

@@ -428,7 +428,7 @@ fn print_dependencies<'a>(
428428
while let Some(dependency) = it.next() {
429429
levels_continue.push(it.peek().is_some());
430430
print_node(
431-
gctx,
431+
ws,
432432
graph,
433433
*dependency,
434434
format,

0 commit comments

Comments
 (0)