comparison 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
comparison
equal deleted inserted replaced
47677:da1c0cd68d53 47678:065e61628980
338 "Dirstate error".to_string(), 338 "Dirstate error".to_string(),
339 )), 339 )),
340 } 340 }
341 } 341 }
342 342
343 /// Returns new data together with whether that data should be appended to
344 /// the existing data file whose content is at `self.on_disk` (True),
345 /// instead of written to a new data file (False).
343 def write_v2( 346 def write_v2(
344 &self, 347 &self,
345 now: PyObject 348 now: PyObject,
346 ) -> PyResult<PyBytes> { 349 can_append: bool,
350 ) -> PyResult<PyObject> {
347 let now = Timestamp(now.extract(py)?); 351 let now = Timestamp(now.extract(py)?);
348 352
349 let mut inner = self.inner(py).borrow_mut(); 353 let mut inner = self.inner(py).borrow_mut();
350 let result = inner.pack_v2(now); 354 let result = inner.pack_v2(now, can_append);
351 match result { 355 match result {
352 Ok(packed) => Ok(PyBytes::new(py, &packed)), 356 Ok((packed, append)) => {
357 let packed = PyBytes::new(py, &packed);
358 Ok((packed, append).to_py_object(py).into_object())
359 },
353 Err(_) => Err(PyErr::new::<exc::OSError, _>( 360 Err(_) => Err(PyErr::new::<exc::OSError, _>(
354 py, 361 py,
355 "Dirstate error".to_string(), 362 "Dirstate error".to_string(),
356 )), 363 )),
357 } 364 }