Show More
@@ -1750,6 +1750,7 b' if rustmod is not None:' | |||
|
1750 | 1750 | self._opener = opener |
|
1751 | 1751 | self._root = root |
|
1752 | 1752 | self._filename = b'dirstate' |
|
1753 | self._nodelen = 20 | |
|
1753 | 1754 | self._parents = None |
|
1754 | 1755 | self._dirtyparents = False |
|
1755 | 1756 | |
@@ -1778,25 +1779,15 b' if rustmod is not None:' | |||
|
1778 | 1779 | def _rustmap(self): |
|
1779 | 1780 | """ |
|
1780 | 1781 | Fills the Dirstatemap when called. |
|
1781 | Use `self._inner_rustmap` if reading the dirstate is not necessary. | |
|
1782 | """ | |
|
1783 | self._rustmap = self._inner_rustmap | |
|
1784 | self.read() | |
|
1785 | return self._rustmap | |
|
1786 | ||
|
1787 | @propertycache | |
|
1788 | def _inner_rustmap(self): | |
|
1789 | """ | |
|
1790 | Does not fill the Dirstatemap when called. This allows for | |
|
1791 | optimizations where only setting/getting the parents is needed. | |
|
1792 | 1782 | """ |
|
1793 | 1783 | use_dirstate_tree = self._ui.configbool( |
|
1794 | 1784 | b"experimental", |
|
1795 | 1785 | b"dirstate-tree.in-memory", |
|
1796 | 1786 | False, |
|
1797 | 1787 | ) |
|
1798 |
self. |
|
|
1799 |
|
|
|
1788 | self._rustmap = rustmod.DirstateMap(use_dirstate_tree) | |
|
1789 | self.read() | |
|
1790 | return self._rustmap | |
|
1800 | 1791 | |
|
1801 | 1792 | @property |
|
1802 | 1793 | def copymap(self): |
@@ -1807,7 +1798,6 b' if rustmod is not None:' | |||
|
1807 | 1798 | |
|
1808 | 1799 | def clear(self): |
|
1809 | 1800 | self._rustmap.clear() |
|
1810 | self._inner_rustmap.clear() | |
|
1811 | 1801 | self.setparents( |
|
1812 | 1802 | self._nodeconstants.nullid, self._nodeconstants.nullid |
|
1813 | 1803 | ) |
@@ -1849,7 +1839,6 b' if rustmod is not None:' | |||
|
1849 | 1839 | return fp |
|
1850 | 1840 | |
|
1851 | 1841 | def setparents(self, p1, p2): |
|
1852 | self._rustmap.setparents(p1, p2) | |
|
1853 | 1842 | self._parents = (p1, p2) |
|
1854 | 1843 | self._dirtyparents = True |
|
1855 | 1844 | |
@@ -1865,9 +1854,18 b' if rustmod is not None:' | |||
|
1865 | 1854 | # File doesn't exist, so the current state is empty |
|
1866 | 1855 | st = b'' |
|
1867 | 1856 | |
|
1868 |
|
|
|
1869 | self._parents = self._inner_rustmap.parents(st) | |
|
1870 | except ValueError: | |
|
1857 | l = len(st) | |
|
1858 | if l == self._nodelen * 2: | |
|
1859 | self._parents = ( | |
|
1860 | st[: self._nodelen], | |
|
1861 | st[self._nodelen : 2 * self._nodelen], | |
|
1862 | ) | |
|
1863 | elif l == 0: | |
|
1864 | self._parents = ( | |
|
1865 | self._nodeconstants.nullid, | |
|
1866 | self._nodeconstants.nullid, | |
|
1867 | ) | |
|
1868 | else: | |
|
1871 | 1869 | raise error.Abort( |
|
1872 | 1870 | _(b'working directory state appears damaged!') |
|
1873 | 1871 | ) |
@@ -7,10 +7,8 b'' | |||
|
7 | 7 | |
|
8 | 8 | use crate::dirstate::parsers::clear_ambiguous_mtime; |
|
9 | 9 | use crate::dirstate::parsers::Timestamp; |
|
10 | use crate::errors::HgError; | |
|
11 | use crate::revlog::node::NULL_NODE; | |
|
12 | 10 | use crate::{ |
|
13 |
dirstate |
|
|
11 | dirstate::EntryState, | |
|
14 | 12 | pack_dirstate, parse_dirstate, |
|
15 | 13 | utils::hg_path::{HgPath, HgPathBuf}, |
|
16 | 14 | CopyMap, DirsMultiset, DirstateEntry, DirstateError, DirstateMapError, |
@@ -18,7 +16,6 b' use crate::{' | |||
|
18 | 16 | }; |
|
19 | 17 | use micro_timer::timed; |
|
20 | 18 | use std::collections::HashSet; |
|
21 | use std::convert::TryInto; | |
|
22 | 19 | use std::iter::FromIterator; |
|
23 | 20 | use std::ops::Deref; |
|
24 | 21 | |
@@ -30,8 +27,6 b' pub struct DirstateMap {' | |||
|
30 | 27 | pub all_dirs: Option<DirsMultiset>, |
|
31 | 28 | non_normal_set: Option<HashSet<HgPathBuf>>, |
|
32 | 29 | other_parent_set: Option<HashSet<HgPathBuf>>, |
|
33 | parents: Option<DirstateParents>, | |
|
34 | dirty_parents: bool, | |
|
35 | 30 | } |
|
36 | 31 | |
|
37 | 32 | /// Should only really be used in python interface code, for clarity |
@@ -64,10 +59,6 b' impl DirstateMap {' | |||
|
64 | 59 | self.copy_map.clear(); |
|
65 | 60 | self.non_normal_set = None; |
|
66 | 61 | self.other_parent_set = None; |
|
67 | self.set_parents(&DirstateParents { | |
|
68 | p1: NULL_NODE, | |
|
69 | p2: NULL_NODE, | |
|
70 | }) | |
|
71 | 62 | } |
|
72 | 63 | |
|
73 | 64 | /// Add a tracked file to the dirstate |
@@ -292,41 +283,6 b' impl DirstateMap {' | |||
|
292 | 283 | Ok(self.all_dirs.as_ref().unwrap().contains(directory)) |
|
293 | 284 | } |
|
294 | 285 | |
|
295 | pub fn parents( | |
|
296 | &mut self, | |
|
297 | file_contents: &[u8], | |
|
298 | ) -> Result<&DirstateParents, DirstateError> { | |
|
299 | if let Some(ref parents) = self.parents { | |
|
300 | return Ok(parents); | |
|
301 | } | |
|
302 | let parents; | |
|
303 | if file_contents.len() == PARENT_SIZE * 2 { | |
|
304 | parents = DirstateParents { | |
|
305 | p1: file_contents[..PARENT_SIZE].try_into().unwrap(), | |
|
306 | p2: file_contents[PARENT_SIZE..PARENT_SIZE * 2] | |
|
307 | .try_into() | |
|
308 | .unwrap(), | |
|
309 | }; | |
|
310 | } else if file_contents.is_empty() { | |
|
311 | parents = DirstateParents { | |
|
312 | p1: NULL_NODE, | |
|
313 | p2: NULL_NODE, | |
|
314 | }; | |
|
315 | } else { | |
|
316 | return Err( | |
|
317 | HgError::corrupted("Dirstate appears to be damaged").into() | |
|
318 | ); | |
|
319 | } | |
|
320 | ||
|
321 | self.parents = Some(parents); | |
|
322 | Ok(self.parents.as_ref().unwrap()) | |
|
323 | } | |
|
324 | ||
|
325 | pub fn set_parents(&mut self, parents: &DirstateParents) { | |
|
326 | self.parents = Some(parents.clone()); | |
|
327 | self.dirty_parents = true; | |
|
328 | } | |
|
329 | ||
|
330 | 286 | #[timed] |
|
331 | 287 | pub fn read<'a>( |
|
332 | 288 | &mut self, |
@@ -347,11 +303,6 b' impl DirstateMap {' | |||
|
347 | 303 | .into_iter() |
|
348 | 304 | .map(|(path, copy)| (path.to_owned(), copy.to_owned())), |
|
349 | 305 | ); |
|
350 | ||
|
351 | if !self.dirty_parents { | |
|
352 | self.set_parents(&parents); | |
|
353 | } | |
|
354 | ||
|
355 | 306 | Ok(Some(parents)) |
|
356 | 307 | } |
|
357 | 308 | |
@@ -363,8 +314,6 b' impl DirstateMap {' | |||
|
363 | 314 | let packed = |
|
364 | 315 | pack_dirstate(&mut self.state_map, &self.copy_map, parents, now)?; |
|
365 | 316 | |
|
366 | self.dirty_parents = false; | |
|
367 | ||
|
368 | 317 | self.set_non_normal_other_parent_entries(true); |
|
369 | 318 | Ok(packed) |
|
370 | 319 | } |
@@ -8,10 +8,8 b' use crate::dirstate::parsers::clear_ambi' | |||
|
8 | 8 | use crate::dirstate::parsers::pack_entry; |
|
9 | 9 | use crate::dirstate::parsers::packed_entry_size; |
|
10 | 10 | use crate::dirstate::parsers::parse_dirstate_entries; |
|
11 | use crate::dirstate::parsers::parse_dirstate_parents; | |
|
12 | 11 | use crate::dirstate::parsers::Timestamp; |
|
13 | 12 | use crate::matchers::Matcher; |
|
14 | use crate::revlog::node::NULL_NODE; | |
|
15 | 13 | use crate::utils::hg_path::{HgPath, HgPathBuf}; |
|
16 | 14 | use crate::CopyMapIter; |
|
17 | 15 | use crate::DirstateEntry; |
@@ -27,8 +25,6 b' use crate::StatusError;' | |||
|
27 | 25 | use crate::StatusOptions; |
|
28 | 26 | |
|
29 | 27 | pub struct DirstateMap { |
|
30 | parents: Option<DirstateParents>, | |
|
31 | dirty_parents: bool, | |
|
32 | 28 | pub(super) root: ChildNodes, |
|
33 | 29 | |
|
34 | 30 | /// Number of nodes anywhere in the tree that have `.entry.is_some()`. |
@@ -76,8 +72,6 b" type NodeDataMut<'a> = (" | |||
|
76 | 72 | impl DirstateMap { |
|
77 | 73 | pub fn new() -> Self { |
|
78 | 74 | Self { |
|
79 | parents: None, | |
|
80 | dirty_parents: false, | |
|
81 | 75 | root: ChildNodes::default(), |
|
82 | 76 | nodes_with_entry_count: 0, |
|
83 | 77 | nodes_with_copy_source_count: 0, |
@@ -288,10 +282,6 b' impl DirstateMap {' | |||
|
288 | 282 | |
|
289 | 283 | impl super::dispatch::DirstateMapMethods for DirstateMap { |
|
290 | 284 | fn clear(&mut self) { |
|
291 | self.set_parents(&DirstateParents { | |
|
292 | p1: NULL_NODE, | |
|
293 | p2: NULL_NODE, | |
|
294 | }); | |
|
295 | 285 | self.root.clear(); |
|
296 | 286 | self.nodes_with_entry_count = 0; |
|
297 | 287 | self.nodes_with_copy_source_count = 0; |
@@ -453,29 +443,6 b' impl super::dispatch::DirstateMapMethods' | |||
|
453 | 443 | } |
|
454 | 444 | } |
|
455 | 445 | |
|
456 | fn parents( | |
|
457 | &mut self, | |
|
458 | file_contents: &[u8], | |
|
459 | ) -> Result<&DirstateParents, DirstateError> { | |
|
460 | if self.parents.is_none() { | |
|
461 | let parents = if !file_contents.is_empty() { | |
|
462 | parse_dirstate_parents(file_contents)?.clone() | |
|
463 | } else { | |
|
464 | DirstateParents { | |
|
465 | p1: NULL_NODE, | |
|
466 | p2: NULL_NODE, | |
|
467 | } | |
|
468 | }; | |
|
469 | self.parents = Some(parents); | |
|
470 | } | |
|
471 | Ok(self.parents.as_ref().unwrap()) | |
|
472 | } | |
|
473 | ||
|
474 | fn set_parents(&mut self, parents: &DirstateParents) { | |
|
475 | self.parents = Some(parents.clone()); | |
|
476 | self.dirty_parents = true; | |
|
477 | } | |
|
478 | ||
|
479 | 446 | #[timed] |
|
480 | 447 | fn read<'a>( |
|
481 | 448 | &mut self, |
@@ -515,10 +482,6 b' impl super::dispatch::DirstateMapMethods' | |||
|
515 | 482 | }, |
|
516 | 483 | )?; |
|
517 | 484 | |
|
518 | if !self.dirty_parents { | |
|
519 | self.set_parents(parents); | |
|
520 | } | |
|
521 | ||
|
522 | 485 | Ok(Some(parents)) |
|
523 | 486 | } |
|
524 | 487 | |
@@ -554,7 +517,6 b' impl super::dispatch::DirstateMapMethods' | |||
|
554 | 517 | ); |
|
555 | 518 | } |
|
556 | 519 | } |
|
557 | self.dirty_parents = false; | |
|
558 | 520 | Ok(packed) |
|
559 | 521 | } |
|
560 | 522 |
@@ -73,13 +73,6 b' pub trait DirstateMapMethods {' | |||
|
73 | 73 | directory: &HgPath, |
|
74 | 74 | ) -> Result<bool, DirstateMapError>; |
|
75 | 75 | |
|
76 | fn parents( | |
|
77 | &mut self, | |
|
78 | file_contents: &[u8], | |
|
79 | ) -> Result<&DirstateParents, DirstateError>; | |
|
80 | ||
|
81 | fn set_parents(&mut self, parents: &DirstateParents); | |
|
82 | ||
|
83 | 76 | fn read<'a>( |
|
84 | 77 | &mut self, |
|
85 | 78 | file_contents: &'a [u8], |
@@ -223,17 +216,6 b' impl DirstateMapMethods for DirstateMap ' | |||
|
223 | 216 | self.has_dir(directory) |
|
224 | 217 | } |
|
225 | 218 | |
|
226 | fn parents( | |
|
227 | &mut self, | |
|
228 | file_contents: &[u8], | |
|
229 | ) -> Result<&DirstateParents, DirstateError> { | |
|
230 | self.parents(file_contents) | |
|
231 | } | |
|
232 | ||
|
233 | fn set_parents(&mut self, parents: &DirstateParents) { | |
|
234 | self.set_parents(parents) | |
|
235 | } | |
|
236 | ||
|
237 | 219 | fn read<'a>( |
|
238 | 220 | &mut self, |
|
239 | 221 | file_contents: &'a [u8], |
@@ -13,8 +13,8 b' use std::convert::TryInto;' | |||
|
13 | 13 | |
|
14 | 14 | use cpython::{ |
|
15 | 15 | exc, ObjectProtocol, PyBool, PyBytes, PyClone, PyDict, PyErr, PyList, |
|
16 |
PyObject, PyResult, PySet, PyString, |
|
|
17 |
|
|
|
16 | PyObject, PyResult, PySet, PyString, Python, PythonObject, ToPyObject, | |
|
17 | UnsafePyLeaked, | |
|
18 | 18 | }; |
|
19 | 19 | |
|
20 | 20 | use crate::{ |
@@ -271,27 +271,6 b' py_class!(pub class DirstateMap |py| {' | |||
|
271 | 271 | .to_py_object(py)) |
|
272 | 272 | } |
|
273 | 273 | |
|
274 | def parents(&self, st: PyObject) -> PyResult<PyTuple> { | |
|
275 | self.inner(py).borrow_mut() | |
|
276 | .parents(st.extract::<PyBytes>(py)?.data(py)) | |
|
277 | .map(|parents| dirstate_parents_to_pytuple(py, parents)) | |
|
278 | .or_else(|_| { | |
|
279 | Err(PyErr::new::<exc::OSError, _>( | |
|
280 | py, | |
|
281 | "Dirstate error".to_string(), | |
|
282 | )) | |
|
283 | }) | |
|
284 | } | |
|
285 | ||
|
286 | def setparents(&self, p1: PyObject, p2: PyObject) -> PyResult<PyObject> { | |
|
287 | let p1 = extract_node_id(py, &p1)?; | |
|
288 | let p2 = extract_node_id(py, &p2)?; | |
|
289 | ||
|
290 | self.inner(py).borrow_mut() | |
|
291 | .set_parents(&DirstateParents { p1, p2 }); | |
|
292 | Ok(py.None()) | |
|
293 | } | |
|
294 | ||
|
295 | 274 | def read(&self, st: PyObject) -> PyResult<Option<PyObject>> { |
|
296 | 275 | match self.inner(py).borrow_mut() |
|
297 | 276 | .read(st.extract::<PyBytes>(py)?.data(py)) |
General Comments 0
You need to be logged in to leave comments.
Login now