Skip to content

Commit ebf6538

Browse files
authored
Combine nested otherwise empty directories in objects view (#137)
1 parent 424434e commit ebf6538

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

objdiff-gui/src/config.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ pub enum ProjectObjectNode {
1212
Dir(String, Vec<ProjectObjectNode>),
1313
}
1414

15+
fn join_single_dir_entries(nodes: &mut Vec<ProjectObjectNode>) {
16+
for node in nodes {
17+
if let ProjectObjectNode::Dir(my_name, my_nodes) = node {
18+
join_single_dir_entries(my_nodes);
19+
// If this directory consists of a single sub-directory...
20+
if let [ProjectObjectNode::Dir(sub_name, sub_nodes)] = &mut my_nodes[..] {
21+
// ... join the two names with a path separator and eliminate the layer
22+
*my_name += "/";
23+
*my_name += sub_name;
24+
*my_nodes = std::mem::take(sub_nodes);
25+
}
26+
}
27+
}
28+
}
29+
1530
fn find_dir<'a>(
1631
name: &str,
1732
nodes: &'a mut Vec<ProjectObjectNode>,
@@ -60,6 +75,14 @@ fn build_nodes(
6075
let filename = path.file_name().unwrap().to_str().unwrap().to_string();
6176
out_nodes.push(ProjectObjectNode::Unit(filename, idx));
6277
}
78+
// Within the top-level module directories, join paths. Leave the
79+
// top-level name intact though since it's the module name.
80+
for node in &mut nodes {
81+
if let ProjectObjectNode::Dir(_, sub_nodes) = node {
82+
join_single_dir_entries(sub_nodes);
83+
}
84+
}
85+
6386
nodes
6487
}
6588

0 commit comments

Comments
 (0)