[Updated] D12529: rust-dirstatemap: add `each_ancestor` argument to `get_node_mut`

Alphare (Raphaël Gomès) phabricator at mercurial-scm.org
Tue Apr 19 21:55:57 UTC 2022


Closed by commit rHGfcf6f943a142: rust-dirstatemap: add `each_ancestor` argument to `get_node_mut` (authored by Alphare).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D12529?vs=33092&id=33283

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D12529/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D12529

AFFECTED FILES
  rust/hg-core/src/dirstate_tree/dirstate_map.rs

CHANGE DETAILS

diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -546,12 +546,17 @@
     /// Returns a mutable reference to the node at `path` if it exists
     ///
     /// This takes `root` instead of `&mut self` so that callers can mutate
-    /// other fields while the returned borrow is still valid
+    /// other fields while the returned borrow is still valid.
+    ///
+    /// `each_ancestor` is a callback that is called for each ancestor node
+    /// when descending the tree. It is used to keep the different counters
+    /// of the `DirstateMap` up-to-date.
     fn get_node_mut<'tree>(
         on_disk: &'on_disk [u8],
         unreachable_bytes: &mut u32,
         root: &'tree mut ChildNodes<'on_disk>,
         path: &HgPath,
+        mut each_ancestor: impl FnMut(&mut Node),
     ) -> Result<Option<&'tree mut Node<'on_disk>>, DirstateV2ParseError> {
         let mut children = root;
         let mut components = path.components();
@@ -563,6 +568,7 @@
                 .get_mut(component)
             {
                 if let Some(next_component) = components.next() {
+                    each_ancestor(child);
                     component = next_component;
                     children = &mut child.children;
                 } else {
@@ -786,6 +792,7 @@
             &mut self.unreachable_bytes,
             &mut self.root,
             path,
+            |_ancestor| {},
         )? {
             Some(node) => node,
             None => return Ok(()),
@@ -807,6 +814,7 @@
             &mut self.unreachable_bytes,
             &mut self.root,
             path,
+            |_ancestor| {},
         )? {
             Some(node) => node,
             None => return Ok(()),
@@ -1294,6 +1302,7 @@
                 unreachable_bytes,
                 &mut map.root,
                 key,
+                |_ancestor| {},
             )?
             .and_then(|node| {
                 if let Some(source) = &node.copy_source {



To: Alphare, #hg-reviewers
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20220419/d84af194/attachment-0002.html>


More information about the Mercurial-patches mailing list