@@ -5,7 +5,7 @@ use cargo::core::package::PackageSet;
55use cargo:: core:: registry:: PackageRegistry ;
66use cargo:: core:: resolver:: Method ;
77use cargo:: core:: shell:: Shell ;
8- use cargo:: core:: { Package , PackageId , Resolve , Workspace } ;
8+ use cargo:: core:: { Package , PackageId , PackageIdSpec , Resolve , Workspace } ;
99use cargo:: ops;
1010use cargo:: util:: { self , important_paths, CargoResult , Cfg , Rustc } ;
1111use cargo:: { CliResult , Config } ;
@@ -209,9 +209,9 @@ fn real_main(args: Args, config: &mut Config) -> CliResult {
209209 let ids = packages. package_ids ( ) . collect :: < Vec < _ > > ( ) ;
210210 let packages = registry. get ( & ids) ?;
211211
212- let root = match args. package {
213- Some ( ref pkg) => resolve . query ( pkg) ?,
214- None => package. package_id ( ) ,
212+ let roots = match args. package {
213+ Some ( ref pkg) => query_all ( & resolve , pkg) ?,
214+ None => vec ! [ package. package_id( ) ] ,
215215 } ;
216216
217217 let rustc = config. load_global_rustc ( Some ( & workspace) ) ?;
@@ -252,14 +252,20 @@ fn real_main(args: Args, config: &mut Config) -> CliResult {
252252 Prefix :: Indent
253253 } ;
254254
255- if args. duplicates {
256- let dups = find_duplicates ( & graph) ;
257- for dup in & dups {
258- print_tree ( dup, & graph, & format, direction, symbols, prefix, args. all ) ?;
255+ let packages = if args. duplicates {
256+ find_duplicates ( & graph)
257+ } else {
258+ roots
259+ } ;
260+
261+ if packages. len ( ) != 1 {
262+ for package in & packages {
263+ print_tree ( package, & graph, & format, direction, symbols, prefix, args. all ) ?;
259264 println ! ( ) ;
260265 }
261266 } else {
262- print_tree ( & root, & graph, & format, direction, symbols, prefix, args. all ) ?;
267+ let package = & packages[ 0 ] ;
268+ print_tree ( package, & graph, & format, direction, symbols, prefix, args. all ) ?;
263269 }
264270
265271 Ok ( ( ) )
@@ -346,6 +352,17 @@ fn resolve<'a, 'cfg>(
346352 Ok ( ( packages, resolve) )
347353}
348354
355+ fn query_all ( resolve : & Resolve , spec : & str ) -> CargoResult < Vec < PackageId > > {
356+ let spec = PackageIdSpec :: parse ( spec) ?;
357+ let mut result = vec ! [ ] ;
358+ for package in resolve. iter ( ) {
359+ if spec. matches ( package) {
360+ result. push ( package) ;
361+ }
362+ }
363+ Ok ( result)
364+ }
365+
349366struct Node < ' a > {
350367 id : PackageId ,
351368 metadata : & ' a ManifestMetadata ,
0 commit comments