544 } |
544 } |
545 |
545 |
546 /// Returns a mutable reference to the node at `path` if it exists |
546 /// Returns a mutable reference to the node at `path` if it exists |
547 /// |
547 /// |
548 /// This takes `root` instead of `&mut self` so that callers can mutate |
548 /// This takes `root` instead of `&mut self` so that callers can mutate |
549 /// other fields while the returned borrow is still valid |
549 /// other fields while the returned borrow is still valid. |
|
550 /// |
|
551 /// `each_ancestor` is a callback that is called for each ancestor node |
|
552 /// when descending the tree. It is used to keep the different counters |
|
553 /// of the `DirstateMap` up-to-date. |
550 fn get_node_mut<'tree>( |
554 fn get_node_mut<'tree>( |
551 on_disk: &'on_disk [u8], |
555 on_disk: &'on_disk [u8], |
552 unreachable_bytes: &mut u32, |
556 unreachable_bytes: &mut u32, |
553 root: &'tree mut ChildNodes<'on_disk>, |
557 root: &'tree mut ChildNodes<'on_disk>, |
554 path: &HgPath, |
558 path: &HgPath, |
|
559 mut each_ancestor: impl FnMut(&mut Node), |
555 ) -> Result<Option<&'tree mut Node<'on_disk>>, DirstateV2ParseError> { |
560 ) -> Result<Option<&'tree mut Node<'on_disk>>, DirstateV2ParseError> { |
556 let mut children = root; |
561 let mut children = root; |
557 let mut components = path.components(); |
562 let mut components = path.components(); |
558 let mut component = |
563 let mut component = |
559 components.next().expect("expected at least one components"); |
564 components.next().expect("expected at least one components"); |
561 if let Some(child) = children |
566 if let Some(child) = children |
562 .make_mut(on_disk, unreachable_bytes)? |
567 .make_mut(on_disk, unreachable_bytes)? |
563 .get_mut(component) |
568 .get_mut(component) |
564 { |
569 { |
565 if let Some(next_component) = components.next() { |
570 if let Some(next_component) = components.next() { |
|
571 each_ancestor(child); |
566 component = next_component; |
572 component = next_component; |
567 children = &mut child.children; |
573 children = &mut child.children; |
568 } else { |
574 } else { |
569 return Ok(Some(child)); |
575 return Ok(Some(child)); |
570 } |
576 } |
784 let node = match DirstateMap::get_node_mut( |
790 let node = match DirstateMap::get_node_mut( |
785 self.on_disk, |
791 self.on_disk, |
786 &mut self.unreachable_bytes, |
792 &mut self.unreachable_bytes, |
787 &mut self.root, |
793 &mut self.root, |
788 path, |
794 path, |
|
795 |_ancestor| {}, |
789 )? { |
796 )? { |
790 Some(node) => node, |
797 Some(node) => node, |
791 None => return Ok(()), |
798 None => return Ok(()), |
792 }; |
799 }; |
793 if let NodeData::CachedDirectory { .. } = &node.data { |
800 if let NodeData::CachedDirectory { .. } = &node.data { |