diff rust/hg-cpython/src/dirstate/dirstate_map.rs @ 47678:065e61628980

dirstate-v2: Support appending to the same data file For now we’re still writing the entire data every time, so appending is not useful yet. Later we’ll have new nodes pointing to some existing data for nodes and paths that haven’t changed. The decision whether to append is pseudo-random in order to make tests exercise both code paths. This will be replaced by a heuristic based on the amount of unused existing data. Differential Revision: https://phab.mercurial-scm.org/D11094
author Simon Sapin <simon.sapin@octobus.net>
date Tue, 13 Jul 2021 17:18:23 +0200
parents 48aec076b8fb
children 78f7f0d490ee
line wrap: on
line diff
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs	Tue Jul 13 09:44:44 2021 +0200
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs	Tue Jul 13 17:18:23 2021 +0200
@@ -340,16 +340,23 @@
         }
     }
 
+    /// Returns new data together with whether that data should be appended to
+    /// the existing data file whose content is at `self.on_disk` (True),
+    /// instead of written to a new data file (False).
     def write_v2(
         &self,
-        now: PyObject
-    ) -> PyResult<PyBytes> {
+        now: PyObject,
+        can_append: bool,
+    ) -> PyResult<PyObject> {
         let now = Timestamp(now.extract(py)?);
 
         let mut inner = self.inner(py).borrow_mut();
-        let result = inner.pack_v2(now);
+        let result = inner.pack_v2(now, can_append);
         match result {
-            Ok(packed) => Ok(PyBytes::new(py, &packed)),
+            Ok((packed, append)) => {
+                let packed = PyBytes::new(py, &packed);
+                Ok((packed, append).to_py_object(py).into_object())
+            },
             Err(_) => Err(PyErr::new::<exc::OSError, _>(
                 py,
                 "Dirstate error".to_string(),