Skip to content

Commit

Permalink
Merge pull request #35 from louib/patches-stats
Browse files Browse the repository at this point in the history
feat: implement patch counting
  • Loading branch information
louib authored Jun 9, 2024
2 parents e13b452 + 5124c26 commit 9286a16
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,7 @@ impl PackageGraph {
.insert(root_node.clone(), longest_path.len());
package_graph_stats.longest_path = longest_path;
package_graph_stats.purl_scope_count = self.get_purl_scope_stats();
package_graph_stats.patches_count = self.get_patches_count();
}
package_graph_stats
}
Expand Down Expand Up @@ -1151,10 +1152,44 @@ impl PackageGraph {
response.insert(purl.scheme.clone(), 1);
}

for current_node_child in &current_node.children {
node_queue.insert(current_node_child.clone());
}
for current_node_child in &current_node.build_inputs {
node_queue.insert(current_node_child.clone());
}
for current_node_child in &current_node.patches {
node_queue.insert(current_node_child.clone());
}
visited_children.insert(current_node_path.clone());
}

response
}

pub fn get_patches_count(&self) -> usize {
let mut response = 0;
let mut visited_children: HashSet<String> = HashSet::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();
response += current_node.patches.len();

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

Expand Down

0 comments on commit 9286a16

Please sign in to comment.