Mercurial > public > mercurial-scm > hg
diff rust/hg-cpython/src/dirstate/dirstate_map.rs @ 47280:1766130fe9ba
dirstate-v2: Change the on-disk format when the requirement is enabled
For now, the format is the same except with an additional marker at the start.
This marker is redundant: for existing repositories it is `.hg/requires` that
determines which format to use. For new repositories, it is the new
`format.exp-dirstate-v2` config. There is no upgrade or downgrade so far.
Most of the changes are about plumbing a boolean through layers of APIs to
indicate which format should be used.
Differential Revision: https://phab.mercurial-scm.org/D10719
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Wed, 19 May 2021 13:15:00 +0200 |
parents | cd8ca38fccff |
children | 4ee9f419c52e |
line wrap: on
line diff
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs Wed May 19 13:15:00 2021 +0200 +++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs Wed May 19 13:15:00 2021 +0200 @@ -55,13 +55,17 @@ /// Returns a `(dirstate_map, parents)` tuple @staticmethod - def new(use_dirstate_tree: bool, on_disk: PyBytes) -> PyResult<PyObject> { - let dirstate_error = |_: DirstateError| { - PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()) + def new( + use_dirstate_tree: bool, + use_dirstate_v2: bool, + on_disk: PyBytes, + ) -> PyResult<PyObject> { + let dirstate_error = |e: DirstateError| { + PyErr::new::<exc::OSError, _>(py, format!("Dirstate error: {:?}", e)) }; - let (inner, parents) = if use_dirstate_tree { + let (inner, parents) = if use_dirstate_tree || use_dirstate_v2 { let (map, parents) = - OwningDirstateMap::new(py, on_disk) + OwningDirstateMap::new(py, on_disk, use_dirstate_v2) .map_err(dirstate_error)?; (Box::new(map) as _, parents) } else { @@ -288,6 +292,7 @@ def write( &self, + use_dirstate_v2: bool, p1: PyObject, p2: PyObject, now: PyObject @@ -298,7 +303,13 @@ p2: extract_node_id(py, &p2)?, }; - match self.inner(py).borrow_mut().pack(parents, now) { + let mut inner = self.inner(py).borrow_mut(); + let result = if use_dirstate_v2 { + inner.pack_v2(parents, now) + } else { + inner.pack_v1(parents, now) + }; + match result { Ok(packed) => Ok(PyBytes::new(py, &packed)), Err(_) => Err(PyErr::new::<exc::OSError, _>( py,