@@ -117,21 +117,20 @@ impl PackageMapper {
117117}
118118
119119fn remove_nested_packages < ' a > ( packages : & ' a [ & ' a Package ] ) -> Vec < & ' a Package > {
120- packages
121- . iter ( )
122- . filter ( |package| {
123- let package_root = package. package_root ( ) ;
124- !packages. iter ( ) . any ( |another_package| {
125- let another_package_root = another_package. package_root ( ) ;
126- if package_root == another_package_root {
127- false
128- } else {
129- package_root. starts_with ( another_package_root)
130- }
131- } )
132- } )
133- . copied ( )
134- . collect_vec ( )
120+ let mut top_level_packages: Vec < & Package > = Vec :: new ( ) ;
121+
122+ for package in packages. iter ( ) . sorted_by_key ( |package| package. package_root ( ) ) {
123+ if let Some ( last_package) = top_level_packages. last ( ) {
124+ let last_package_root = last_package. package_root ( ) ;
125+ if !package. package_root ( ) . starts_with ( last_package_root) {
126+ top_level_packages. push ( package) ;
127+ }
128+ } else {
129+ top_level_packages. push ( package) ;
130+ }
131+ }
132+
133+ top_level_packages
135134}
136135
137136#[ cfg( test) ]
@@ -149,7 +148,12 @@ mod tests {
149148 owner: "owner_a" . to_owned( ) ,
150149 } ,
151150 Package {
152- path: Path :: new( "packs/a/b/package.yml" ) . to_owned( ) ,
151+ path: Path :: new( "packs/a/b/e/package.yml" ) . to_owned( ) ,
152+ package_type: PackageType :: Ruby ,
153+ owner: "owner_b" . to_owned( ) ,
154+ } ,
155+ Package {
156+ path: Path :: new( "packs/a/b/c/e/d/f/package.yml" ) . to_owned( ) ,
153157 package_type: PackageType :: Ruby ,
154158 owner: "owner_b" . to_owned( ) ,
155159 } ,
0 commit comments