Patchwork D12527: rust-dirstatemap: inline the last `get_or_insert` call

login
register
mail settings
Submitter phabricator
Date April 12, 2022, 4:05 p.m.
Message ID <differential-rev-PHID-DREV-fpnzfg3sdk5t2d6m3s7h-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50875/
State New
Headers show

Comments

phabricator - April 12, 2022, 4:05 p.m.
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The `get_or_insert` method was dangerous because it did not take the
  `DirstateMap` counters into account. This particular instance does not need
  to update the counters.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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

CHANGE DETAILS




To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

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
@@ -574,20 +574,6 @@ 
         }
     }
 
-    pub(super) fn get_or_insert<'tree, 'path>(
-        &'tree mut self,
-        path: &HgPath,
-    ) -> Result<&'tree mut Node<'on_disk>, DirstateV2ParseError> {
-        Self::get_or_insert_node(
-            self.on_disk,
-            &mut self.unreachable_bytes,
-            &mut self.root,
-            path,
-            WithBasename::to_cow_owned,
-            |_| {},
-        )
-    }
-
     fn get_or_insert_node<'tree, 'path>(
         on_disk: &'on_disk [u8],
         unreachable_bytes: &mut u32,
@@ -1438,7 +1424,14 @@ 
         }
         self.with_dmap_mut(|map| {
             for path in files_with_p2_info.iter() {
-                let node = map.get_or_insert(path)?;
+                let node = DirstateMap::get_or_insert_node(
+                    map.on_disk,
+                    &mut map.unreachable_bytes,
+                    &mut map.root,
+                    path,
+                    WithBasename::to_cow_owned,
+                    |_| {},
+                )?;
                 let entry =
                     node.data.as_entry_mut().expect("entry should exist");
                 entry.drop_merge_data();