44//! passes over the tree to remove redundant information.
55
66use crate :: licenses:: { License , LicenseId , LicensesInterner } ;
7- use std:: collections:: { BTreeMap , BTreeSet } ;
7+ use std:: collections:: BTreeMap ;
88use std:: path:: { Path , PathBuf } ;
99
1010#[ derive( serde:: Serialize ) ]
1111#[ serde( rename_all = "kebab-case" , tag = "type" ) ]
1212pub ( crate ) enum Node < L > {
1313 Root { children : Vec < Node < L > > } ,
1414 Directory { name : PathBuf , children : Vec < Node < L > > , license : Option < L > } ,
15- CondensedDirectory { name : PathBuf , licenses : Vec < L > } ,
1615 File { name : PathBuf , license : L } ,
1716 Group { files : Vec < PathBuf > , directories : Vec < PathBuf > , license : L } ,
1817 Empty ,
@@ -59,8 +58,6 @@ impl Node<LicenseId> {
5958 directories. entry ( name) . or_insert_with ( Vec :: new) . append ( & mut children) ;
6059 }
6160 file @ Node :: File { .. } => files. push ( file) ,
62- // Propagate condensed directories as-is.
63- condensed @ Node :: CondensedDirectory { .. } => files. push ( condensed) ,
6461 Node :: Empty => { }
6562 Node :: Root { .. } => {
6663 panic ! ( "can't have a root inside another element" ) ;
@@ -87,7 +84,6 @@ impl Node<LicenseId> {
8784 }
8885 Node :: Empty => { }
8986 Node :: File { .. } => { }
90- Node :: CondensedDirectory { .. } => { }
9187 Node :: Group { .. } => {
9288 panic ! ( "Group should not be present at this stage" ) ;
9389 }
@@ -134,7 +130,6 @@ impl Node<LicenseId> {
134130 }
135131 }
136132 Node :: File { .. } => { }
137- Node :: CondensedDirectory { .. } => { }
138133 Node :: Group { .. } => panic ! ( "group should not be present at this stage" ) ,
139134 Node :: Empty => { }
140135 }
@@ -177,9 +172,6 @@ impl Node<LicenseId> {
177172 Node :: Directory { name : child_child_name, .. } => {
178173 * child_child_name = child_name. join ( & child_child_name) ;
179174 }
180- Node :: CondensedDirectory { name : child_child_name, .. } => {
181- * child_child_name = child_name. join ( & child_child_name) ;
182- }
183175 Node :: File { name : child_child_name, .. } => {
184176 * child_child_name = child_name. join ( & child_child_name) ;
185177 }
@@ -194,7 +186,6 @@ impl Node<LicenseId> {
194186 }
195187 Node :: Empty => { }
196188 Node :: File { .. } => { }
197- Node :: CondensedDirectory { .. } => { }
198189 Node :: Group { .. } => panic ! ( "Group should not be present at this stage" ) ,
199190 }
200191 }
@@ -262,7 +253,6 @@ impl Node<LicenseId> {
262253 }
263254 }
264255 Node :: File { .. } => { }
265- Node :: CondensedDirectory { .. } => { }
266256 Node :: Group { .. } => panic ! ( "FileGroup should not be present at this stage" ) ,
267257 Node :: Empty => { }
268258 }
@@ -278,7 +268,6 @@ impl Node<LicenseId> {
278268 }
279269 children. retain ( |child| !matches ! ( child, Node :: Empty ) ) ;
280270 }
281- Node :: CondensedDirectory { .. } => { }
282271 Node :: Group { .. } => { }
283272 Node :: File { .. } => { }
284273 Node :: Empty => { }
@@ -302,24 +291,7 @@ pub(crate) fn build(mut input: Vec<(PathBuf, LicenseId)>) -> Node<LicenseId> {
302291 // Ensure reproducibility of all future steps.
303292 input. sort ( ) ;
304293
305- let mut condensed_directories = BTreeMap :: new ( ) ;
306- ' outer: for ( path, license) in input {
307- // Files in condensed directories are handled separately.
308- for ( condensed_directory, allowed_file) in super :: CONDENSED_DIRECTORIES {
309- if path. starts_with ( condensed_directory) {
310- if path. as_path ( ) == Path :: new ( allowed_file) {
311- // The licence on our allowed file is used to represent the entire directory
312- condensed_directories
313- . entry ( * condensed_directory)
314- . or_insert_with ( BTreeSet :: new)
315- . insert ( license) ;
316- } else {
317- // don't add the file
318- }
319- continue ' outer;
320- }
321- }
322-
294+ for ( path, license) in input {
323295 let mut node = Node :: File { name : path. file_name ( ) . unwrap ( ) . into ( ) , license } ;
324296 for component in path. parent ( ) . unwrap_or_else ( || Path :: new ( "." ) ) . components ( ) . rev ( ) {
325297 node = Node :: Directory {
@@ -332,22 +304,6 @@ pub(crate) fn build(mut input: Vec<(PathBuf, LicenseId)>) -> Node<LicenseId> {
332304 children. push ( node) ;
333305 }
334306
335- for ( path, licenses) in condensed_directories {
336- let path = Path :: new ( path) ;
337- let mut node = Node :: CondensedDirectory {
338- name : path. file_name ( ) . unwrap ( ) . into ( ) ,
339- licenses : licenses. iter ( ) . copied ( ) . collect ( ) ,
340- } ;
341- for component in path. parent ( ) . unwrap_or_else ( || Path :: new ( "." ) ) . components ( ) . rev ( ) {
342- node = Node :: Directory {
343- name : component. as_os_str ( ) . into ( ) ,
344- children : vec ! [ node] ,
345- license : None ,
346- } ;
347- }
348- children. push ( node) ;
349- }
350-
351307 Node :: Root { children }
352308}
353309
@@ -376,10 +332,6 @@ pub(crate) fn expand_interned_licenses(
376332 Node :: Group { files, directories, license } => {
377333 Node :: Group { files, directories, license : interner. resolve ( license) }
378334 }
379- Node :: CondensedDirectory { name, licenses } => Node :: CondensedDirectory {
380- name,
381- licenses : licenses. into_iter ( ) . map ( |license| interner. resolve ( license) ) . collect ( ) ,
382- } ,
383335 Node :: Empty => Node :: Empty ,
384336 }
385337}
0 commit comments