Show More
@@ -1775,20 +1775,6 b' if rustmod is not None:' | |||
|
1775 | 1775 | def get(self, *args, **kwargs): |
|
1776 | 1776 | return self._rustmap.get(*args, **kwargs) |
|
1777 | 1777 | |
|
1778 | @propertycache | |
|
1779 | def _rustmap(self): | |
|
1780 | """ | |
|
1781 | Fills the Dirstatemap when called. | |
|
1782 | """ | |
|
1783 | use_dirstate_tree = self._ui.configbool( | |
|
1784 | b"experimental", | |
|
1785 | b"dirstate-tree.in-memory", | |
|
1786 | False, | |
|
1787 | ) | |
|
1788 | self._rustmap = rustmod.DirstateMap(use_dirstate_tree) | |
|
1789 | self.read() | |
|
1790 | return self._rustmap | |
|
1791 | ||
|
1792 | 1778 | @property |
|
1793 | 1779 | def copymap(self): |
|
1794 | 1780 | return self._rustmap.copymap() |
@@ -1872,7 +1858,11 b' if rustmod is not None:' | |||
|
1872 | 1858 | |
|
1873 | 1859 | return self._parents |
|
1874 | 1860 | |
|
1875 | def read(self): | |
|
1861 | @propertycache | |
|
1862 | def _rustmap(self): | |
|
1863 | """ | |
|
1864 | Fills the Dirstatemap when called. | |
|
1865 | """ | |
|
1876 | 1866 | # ignore HG_PENDING because identity is used only for writing |
|
1877 | 1867 | self.identity = util.filestat.frompath( |
|
1878 | 1868 | self._opener.join(self._filename) |
@@ -1887,18 +1877,24 b' if rustmod is not None:' | |||
|
1887 | 1877 | except IOError as err: |
|
1888 | 1878 | if err.errno != errno.ENOENT: |
|
1889 | 1879 | raise |
|
1890 |
|
|
|
1891 | if not st: | |
|
1892 | return | |
|
1880 | st = b'' | |
|
1893 | 1881 | |
|
1894 |
|
|
|
1895 | parents = parse_dirstate(st) | |
|
1882 | use_dirstate_tree = self._ui.configbool( | |
|
1883 | b"experimental", | |
|
1884 | b"dirstate-tree.in-memory", | |
|
1885 | False, | |
|
1886 | ) | |
|
1887 | self._rustmap, parents = rustmod.DirstateMap.new( | |
|
1888 | use_dirstate_tree, st | |
|
1889 | ) | |
|
1890 | ||
|
1896 | 1891 | if parents and not self._dirtyparents: |
|
1897 | 1892 | self.setparents(*parents) |
|
1898 | 1893 | |
|
1899 | 1894 | self.__contains__ = self._rustmap.__contains__ |
|
1900 | 1895 | self.__getitem__ = self._rustmap.__getitem__ |
|
1901 | 1896 | self.get = self._rustmap.get |
|
1897 | return self._rustmap | |
|
1902 | 1898 | |
|
1903 | 1899 | def write(self, st, now): |
|
1904 | 1900 | parents = self.parents() |
@@ -32,8 +32,9 b' use hg::{' | |||
|
32 | 32 | revlog::Node, |
|
33 | 33 | utils::files::normalize_case, |
|
34 | 34 | utils::hg_path::{HgPath, HgPathBuf}, |
|
35 |
DirsMultiset, DirstateEntry, Dirstate |
|
|
36 | DirstateMapError, DirstateParents, EntryState, StateMapIter, | |
|
35 | DirsMultiset, DirstateEntry, DirstateError, | |
|
36 | DirstateMap as RustDirstateMap, DirstateMapError, DirstateParents, | |
|
37 | EntryState, StateMapIter, | |
|
37 | 38 | }; |
|
38 | 39 | |
|
39 | 40 | // TODO |
@@ -51,13 +52,25 b' use hg::{' | |||
|
51 | 52 | py_class!(pub class DirstateMap |py| { |
|
52 | 53 | @shared data inner: Box<dyn DirstateMapMethods + Send>; |
|
53 | 54 | |
|
54 | def __new__(_cls, use_dirstate_tree: bool) -> PyResult<Self> { | |
|
55 | let inner = if use_dirstate_tree { | |
|
56 | Box::new(hg::dirstate_tree::dirstate_map::DirstateMap::new()) as _ | |
|
55 | /// Returns a `(dirstate_map, parents)` tuple | |
|
56 | @staticmethod | |
|
57 | def new(use_dirstate_tree: bool, on_disk: PyBytes) -> PyResult<PyObject> { | |
|
58 | let dirstate_error = |_: DirstateError| { | |
|
59 | PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string()) | |
|
60 | }; | |
|
61 | let bytes = on_disk.data(py); | |
|
62 | let (inner, parents) = if use_dirstate_tree { | |
|
63 | let mut map = hg::dirstate_tree::dirstate_map::DirstateMap::new(); | |
|
64 | let parents = map.read(bytes).map_err(dirstate_error)?; | |
|
65 | (Box::new(map) as _, parents) | |
|
57 | 66 | } else { |
|
58 |
|
|
|
67 | let mut map = RustDirstateMap::default(); | |
|
68 | let parents = map.read(bytes).map_err(dirstate_error)?; | |
|
69 | (Box::new(map) as _, parents) | |
|
59 | 70 | }; |
|
60 | Self::create_instance(py, inner) | |
|
71 | let map = Self::create_instance(py, inner)?; | |
|
72 | let parents = parents.map(|p| dirstate_parents_to_pytuple(py, &p)); | |
|
73 | Ok((map, parents).to_py_object(py).into_object()) | |
|
61 | 74 | } |
|
62 | 75 | |
|
63 | 76 | def clear(&self) -> PyResult<PyObject> { |
@@ -271,21 +284,6 b' py_class!(pub class DirstateMap |py| {' | |||
|
271 | 284 | .to_py_object(py)) |
|
272 | 285 | } |
|
273 | 286 | |
|
274 | def read(&self, st: PyObject) -> PyResult<Option<PyObject>> { | |
|
275 | match self.inner(py).borrow_mut() | |
|
276 | .read(st.extract::<PyBytes>(py)?.data(py)) | |
|
277 | { | |
|
278 | Ok(Some(parents)) => Ok(Some( | |
|
279 | dirstate_parents_to_pytuple(py, parents) | |
|
280 | .into_object() | |
|
281 | )), | |
|
282 | Ok(None) => Ok(Some(py.None())), | |
|
283 | Err(_) => Err(PyErr::new::<exc::OSError, _>( | |
|
284 | py, | |
|
285 | "Dirstate error".to_string(), | |
|
286 | )), | |
|
287 | } | |
|
288 | } | |
|
289 | 287 | def write( |
|
290 | 288 | &self, |
|
291 | 289 | p1: PyObject, |
General Comments 0
You need to be logged in to leave comments.
Login now