Skip to content

Commit

Permalink
feat: add purl stats
Browse files Browse the repository at this point in the history
  • Loading branch information
louib committed Mar 24, 2024
1 parent a02d146 commit 698eeb8
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/nix.rs
Expand Up @@ -908,6 +908,8 @@ pub struct PackageGraphStats {

/// Number of derivations which had an associated entry in the package meta dictionnary.
pub package_meta_count: usize,

pub purl_scope_count: BTreeMap<String, usize>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -937,11 +939,45 @@ impl PackageGraph {
.get_longest_path(&root_node, &self.nodes, &mut HashMap::default())
.len(),
);
package_graph_stats.purl_scope_count = self.get_purl_scope_stats();
let longest_path = package_node.get_longest_path(&root_node, &self.nodes, &mut HashMap::default());
}
package_graph_stats
}

pub fn get_purl_scope_stats(&self) -> BTreeMap<String, usize> {
let mut visited_children: HashSet<String> = HashSet::default();

let mut response: BTreeMap<String, usize> = BTreeMap::default();
let mut node_queue = self.root_nodes.clone();

while !node_queue.is_empty() {
let current_node_path = node_queue.pop_first().unwrap();

if visited_children.contains(&current_node_path) {
continue;
}

let current_node = self.nodes.get(&current_node_path).unwrap();
let purl = current_node.get_purl();

if response.contains_key(&purl.scheme) {
let count = response.get_mut(&purl.scheme).unwrap();
*count += 1;
} else {
response.insert(purl.scheme.clone(), 1);
}

// FIXME we should also go through the patches?
for current_node_child in &current_node.children {
node_queue.insert(current_node_child.clone());
}
visited_children.insert(current_node_path.clone());
}

response
}

pub fn print_out_paths(&self) -> String {
let mut response: String = "".to_string();
for derivation_path in &self.root_nodes {
Expand Down

0 comments on commit 698eeb8

Please sign in to comment.