Show More
@@ -1775,20 +1775,6 b' if rustmod is not None:' | |||||
1775 | def get(self, *args, **kwargs): |
|
1775 | def get(self, *args, **kwargs): | |
1776 | return self._rustmap.get(*args, **kwargs) |
|
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 | @property |
|
1778 | @property | |
1793 | def copymap(self): |
|
1779 | def copymap(self): | |
1794 | return self._rustmap.copymap() |
|
1780 | return self._rustmap.copymap() | |
@@ -1872,7 +1858,11 b' if rustmod is not None:' | |||||
1872 |
|
1858 | |||
1873 | return self._parents |
|
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 | # ignore HG_PENDING because identity is used only for writing |
|
1866 | # ignore HG_PENDING because identity is used only for writing | |
1877 | self.identity = util.filestat.frompath( |
|
1867 | self.identity = util.filestat.frompath( | |
1878 | self._opener.join(self._filename) |
|
1868 | self._opener.join(self._filename) | |
@@ -1887,18 +1877,24 b' if rustmod is not None:' | |||||
1887 | except IOError as err: |
|
1877 | except IOError as err: | |
1888 | if err.errno != errno.ENOENT: |
|
1878 | if err.errno != errno.ENOENT: | |
1889 | raise |
|
1879 | raise | |
1890 |
|
|
1880 | st = b'' | |
1891 | if not st: |
|
|||
1892 | return |
|
|||
1893 |
|
1881 | |||
1894 |
|
|
1882 | use_dirstate_tree = self._ui.configbool( | |
1895 | parents = parse_dirstate(st) |
|
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 | if parents and not self._dirtyparents: |
|
1891 | if parents and not self._dirtyparents: | |
1897 | self.setparents(*parents) |
|
1892 | self.setparents(*parents) | |
1898 |
|
1893 | |||
1899 | self.__contains__ = self._rustmap.__contains__ |
|
1894 | self.__contains__ = self._rustmap.__contains__ | |
1900 | self.__getitem__ = self._rustmap.__getitem__ |
|
1895 | self.__getitem__ = self._rustmap.__getitem__ | |
1901 | self.get = self._rustmap.get |
|
1896 | self.get = self._rustmap.get | |
|
1897 | return self._rustmap | |||
1902 |
|
1898 | |||
1903 | def write(self, st, now): |
|
1899 | def write(self, st, now): | |
1904 | parents = self.parents() |
|
1900 | parents = self.parents() |
@@ -32,8 +32,9 b' use hg::{' | |||||
32 | revlog::Node, |
|
32 | revlog::Node, | |
33 | utils::files::normalize_case, |
|
33 | utils::files::normalize_case, | |
34 | utils::hg_path::{HgPath, HgPathBuf}, |
|
34 | utils::hg_path::{HgPath, HgPathBuf}, | |
35 |
DirsMultiset, DirstateEntry, Dirstate |
|
35 | DirsMultiset, DirstateEntry, DirstateError, | |
36 | DirstateMapError, DirstateParents, EntryState, StateMapIter, |
|
36 | DirstateMap as RustDirstateMap, DirstateMapError, DirstateParents, | |
|
37 | EntryState, StateMapIter, | |||
37 | }; |
|
38 | }; | |
38 |
|
39 | |||
39 | // TODO |
|
40 | // TODO | |
@@ -51,13 +52,25 b' use hg::{' | |||||
51 | py_class!(pub class DirstateMap |py| { |
|
52 | py_class!(pub class DirstateMap |py| { | |
52 | @shared data inner: Box<dyn DirstateMapMethods + Send>; |
|
53 | @shared data inner: Box<dyn DirstateMapMethods + Send>; | |
53 |
|
54 | |||
54 | def __new__(_cls, use_dirstate_tree: bool) -> PyResult<Self> { |
|
55 | /// Returns a `(dirstate_map, parents)` tuple | |
55 | let inner = if use_dirstate_tree { |
|
56 | @staticmethod | |
56 | Box::new(hg::dirstate_tree::dirstate_map::DirstateMap::new()) as _ |
|
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 | } else { |
|
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 | def clear(&self) -> PyResult<PyObject> { |
|
76 | def clear(&self) -> PyResult<PyObject> { | |
@@ -271,21 +284,6 b' py_class!(pub class DirstateMap |py| {' | |||||
271 | .to_py_object(py)) |
|
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 | def write( |
|
287 | def write( | |
290 | &self, |
|
288 | &self, | |
291 | p1: PyObject, |
|
289 | p1: PyObject, |
General Comments 0
You need to be logged in to leave comments.
Login now