💄 Reduce nesting in Snapshot::remove_path

This commit is contained in:
Max Brunsfeld 2021-04-19 12:15:24 -07:00
parent 3e93fb9459
commit 0fd3f55730

View file

@ -258,10 +258,12 @@ impl Snapshot {
}
fn remove_path(&mut self, path: &Path) {
if let Some(mut parent_entry) = path.parent().and_then(|p| self.entry_for_path(p).cloned())
{
let mut edits = Vec::new();
let mut parent_entry = match path.parent().and_then(|p| self.entry_for_path(p).cloned()) {
Some(e) => e,
None => return,
};
let mut edits = Vec::new();
let parent_inode = parent_entry.inode();
let mut entry_inode = None;
if let Entry::Dir { children, .. } = &mut parent_entry {
@ -285,7 +287,6 @@ impl Snapshot {
}
if let Some(entry_inode) = entry_inode {
// Recursively remove the orphaned nodes' descendants.
let mut descendant_stack = Vec::new();
descendant_stack.push((entry_inode, parent_inode));
while let Some((inode, parent_inode)) = descendant_stack.pop() {
@ -293,8 +294,7 @@ impl Snapshot {
if entry.parent() == Some(parent_inode) {
edits.push(Edit::Remove(inode));
if let Entry::Dir { children, .. } = entry {
descendant_stack
.extend(children.iter().map(|c| (c.0, entry.inode())));
descendant_stack.extend(children.iter().map(|c| (c.0, entry.inode())));
}
}
}
@ -303,7 +303,6 @@ impl Snapshot {
self.entries.edit(edits);
}
}
fn fmt_entry(
&self,
@ -372,19 +371,19 @@ impl FileHandle {
#[derive(Clone, Debug)]
pub enum Entry {
Dir {
parent: Option<u64>,
inode: u64,
parent: Option<u64>,
is_symlink: bool,
is_ignored: bool,
children: Arc<[(u64, Arc<OsStr>)]>,
pending: bool,
},
File {
parent: Option<u64>,
path: PathEntry,
inode: u64,
parent: Option<u64>,
is_symlink: bool,
is_ignored: bool,
path: PathEntry,
},
}