Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Add depth option #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

mwilliammyers
Copy link

Adds the -D <DEPTH>/--depth <DEPTH> option.

Closes #60

Example:

❯ cargo tree -D 1

cargo-tree v0.27.0 (~/Developer/cargo-tree)
├── cargo v0.39.0
├── env_logger v0.7.0
├── failure v0.1.5
├── petgraph v0.4.13
└── structopt v0.3.2

Things to consider:

  • This PR is technically a breaking change because now dependencies are truncated if they are farther down the dependency tree instead of if they were already printed, i.e. deciding if we should truncate a dependency is breadth first. Technically the dependencies are still actually printed depth first but I thought it was pretty weird to have deps printing out that were deeper than the specified limit, only to have a * printed later on. This might lead to confusing behavior when used with the --duplicate option though?
  • Right now this treats packages specified by --package as the "root" package, i.e. instead of erroring:
     ❯ cargo tree -D1 -p syn:0.15.44
     error: package syn v0.15.44 not found
    
    because syn is a transitive dependency with a depth >1, it prints out the dependencies of syn that have a depth <=1 from syn (not the real package root):
     syn v0.15.44
     ├── proc-macro2 v0.4.30
     ├── quote v0.6.13
     └── unicode-xid v0.1.0
    
    Is this the desired behavior?
  • Should we print out a * when truncating a dependency whose children are not being printed because they are above the --depth limit and is also a duplicate?

Entry::Vacant(e) => {
pending.push(dep_id);
if let Some(depth) = max_depth {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this check doesn't need to happen because it is taken care of in print_tree(), but it speeds up the common case of just printing the tree (not checking duplicates or starting from an arbitrary package) when a depth limit is specified.

@Boscop
Copy link

Boscop commented Oct 1, 2019

Thanks, I'm looking forward to this! :)

@therealbnut
Copy link

therealbnut commented Dec 13, 2019

Thanks for working on this @mwilliammyers! What does it do if you set the --depth=1, and your dependency tree looks like this?

 A
 |- B
    |- C

However, A, B, and C are all in your workspace.

I think the ideal solution to #60 would let you show only dependencies referenced directly in your Cargo.toml files (ie. the things you've specified, local or remote).

@mwilliammyers
Copy link
Author

mwilliammyers commented Dec 13, 2019

Assuming A is your "main" (or lib) crate then it would do:

 A
 |- B

@mwilliammyers
Copy link
Author

@sfackler if I fix the conflicts with master, is this a feature that you would consider adding?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to limit tree depth
3 participants