rust: Serializing a DirstateMap does not mutate it anymore
authorSimon Sapin <simon.sapin@octobus.net>
Mon, 29 Nov 2021 17:37:08 +0100
changeset 48416 c1b633db67fc
parent 48415 9ff246cd6200
child 48417 5734b03ecf3e
rust: Serializing a DirstateMap does not mutate it anymore Differential Revision: https://phab.mercurial-scm.org/D11834
rust/hg-core/src/dirstate_tree/dirstate_map.rs
rust/hg-core/src/dirstate_tree/on_disk.rs
rust/hg-cpython/src/dirstate/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Fri Nov 26 15:07:59 2021 +0100
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Mon Nov 29 17:37:08 2021 +0100
@@ -909,10 +909,10 @@
 
     #[timed]
     pub fn pack_v1(
-        &mut self,
+        &self,
         parents: DirstateParents,
     ) -> Result<Vec<u8>, DirstateError> {
-        let map = self.get_map_mut();
+        let map = self.get_map();
         // Optizimation (to be measured?): pre-compute size to avoid `Vec`
         // reallocations
         let mut size = parents.as_bytes().len();
@@ -949,10 +949,10 @@
     /// (false).
     #[timed]
     pub fn pack_v2(
-        &mut self,
+        &self,
         can_append: bool,
     ) -> Result<(Vec<u8>, Vec<u8>, bool), DirstateError> {
-        let map = self.get_map_mut();
+        let map = self.get_map();
         on_disk::write(map, can_append)
     }
 
--- a/rust/hg-core/src/dirstate_tree/on_disk.rs	Fri Nov 26 15:07:59 2021 +0100
+++ b/rust/hg-core/src/dirstate_tree/on_disk.rs	Mon Nov 29 17:37:08 2021 +0100
@@ -553,7 +553,7 @@
 /// `dirstate_map.on_disk` (true), instead of written to a new data file
 /// (false).
 pub(super) fn write(
-    dirstate_map: &mut DirstateMap,
+    dirstate_map: &DirstateMap,
     can_append: bool,
 ) -> Result<(Vec<u8>, Vec<u8>, bool), DirstateError> {
     let append = can_append && dirstate_map.write_should_append();
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs	Fri Nov 26 15:07:59 2021 +0100
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs	Mon Nov 29 17:37:08 2021 +0100
@@ -195,7 +195,7 @@
         p1: PyObject,
         p2: PyObject,
     ) -> PyResult<PyBytes> {
-        let mut inner = self.inner(py).borrow_mut();
+        let inner = self.inner(py).borrow();
         let parents = DirstateParents {
             p1: extract_node_id(py, &p1)?,
             p2: extract_node_id(py, &p2)?,
@@ -217,7 +217,7 @@
         &self,
         can_append: bool,
     ) -> PyResult<PyObject> {
-        let mut inner = self.inner(py).borrow_mut();
+        let inner = self.inner(py).borrow();
         let result = inner.pack_v2(can_append);
         match result {
             Ok((packed, tree_metadata, append)) => {