comparison rust/hg-cpython/src/dirstate/dirstate_map.rs @ 47477:eb416759af7e

dirstate: Removed unused instances of `DirsMultiset` … in Rust-backed dirstatemap. The Python class `dirstatemap` had cached properties `_dirs` and `_alldirs` that were not used for `hastrackeddir` and `hasdir` since they were redundant with corresponding fields for the Rust `DirstateMap` struct. `dirfoldmap` is modified to reuse instead the directory iterator introduced in 3b9914b28133c0918186b6e8b9e4f1916e21338d. Differential Revision: https://phab.mercurial-scm.org/D10921
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 28 Jun 2021 15:52:10 +0200
parents 3b9914b28133
children eaae39894312
comparison
equal deleted inserted replaced
47476:f23eafb036af 47477:eb416759af7e
17 UnsafePyLeaked, 17 UnsafePyLeaked,
18 }; 18 };
19 19
20 use crate::{ 20 use crate::{
21 dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator}, 21 dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator},
22 dirstate::make_dirstate_tuple,
22 dirstate::non_normal_entries::{ 23 dirstate::non_normal_entries::{
23 NonNormalEntries, NonNormalEntriesIterator, 24 NonNormalEntries, NonNormalEntriesIterator,
24 }, 25 },
25 dirstate::owning::OwningDirstateMap, 26 dirstate::owning::OwningDirstateMap,
26 dirstate::{dirs_multiset::Dirs, make_dirstate_tuple},
27 parsers::dirstate_parents_to_pytuple, 27 parsers::dirstate_parents_to_pytuple,
28 }; 28 };
29 use hg::{ 29 use hg::{
30 dirstate::parsers::Timestamp, 30 dirstate::parsers::Timestamp,
31 dirstate_tree::dispatch::DirstateMapMethods, 31 dirstate_tree::dispatch::DirstateMapMethods,
32 dirstate_tree::on_disk::DirstateV2ParseError, 32 dirstate_tree::on_disk::DirstateV2ParseError,
33 errors::HgError, 33 errors::HgError,
34 revlog::Node, 34 revlog::Node,
35 utils::files::normalize_case, 35 utils::files::normalize_case,
36 utils::hg_path::{HgPath, HgPathBuf}, 36 utils::hg_path::{HgPath, HgPathBuf},
37 DirsMultiset, DirstateEntry, DirstateError, 37 DirstateEntry, DirstateError, DirstateMap as RustDirstateMap,
38 DirstateMap as RustDirstateMap, DirstateParents, EntryState, StateMapIter, 38 DirstateParents, EntryState, StateMapIter,
39 }; 39 };
40 40
41 // TODO 41 // TODO
42 // This object needs to share references to multiple members of its Rust 42 // This object needs to share references to multiple members of its Rust
43 // inner struct, namely `copy_map`, `dirs` and `all_dirs`. 43 // inner struct, namely `copy_map`, `dirs` and `all_dirs`.
389 py, 389 py,
390 unsafe { leaked_ref.map(py, |o| o.iter()) }, 390 unsafe { leaked_ref.map(py, |o| o.iter()) },
391 ) 391 )
392 } 392 }
393 393
394 def getdirs(&self) -> PyResult<Dirs> {
395 // TODO don't copy, share the reference
396 self.inner(py).borrow_mut().set_dirs()
397 .map_err(|e| {
398 PyErr::new::<exc::ValueError, _>(py, e.to_string())
399 })?;
400 Dirs::from_inner(
401 py,
402 DirsMultiset::from_dirstate(
403 self.inner(py).borrow().iter(),
404 Some(EntryState::Removed),
405 )
406 .map_err(|e| {
407 PyErr::new::<exc::ValueError, _>(py, e.to_string())
408 })?,
409 )
410 }
411 def getalldirs(&self) -> PyResult<Dirs> {
412 // TODO don't copy, share the reference
413 self.inner(py).borrow_mut().set_all_dirs()
414 .map_err(|e| {
415 PyErr::new::<exc::ValueError, _>(py, e.to_string())
416 })?;
417 Dirs::from_inner(
418 py,
419 DirsMultiset::from_dirstate(
420 self.inner(py).borrow().iter(),
421 None,
422 ).map_err(|e| {
423 PyErr::new::<exc::ValueError, _>(py, e.to_string())
424 })?,
425 )
426 }
427
428 // TODO all copymap* methods, see docstring above 394 // TODO all copymap* methods, see docstring above
429 def copymapcopy(&self) -> PyResult<PyDict> { 395 def copymapcopy(&self) -> PyResult<PyDict> {
430 let dict = PyDict::new(py); 396 let dict = PyDict::new(py);
431 for item in self.inner(py).borrow().copy_map_iter() { 397 for item in self.inner(py).borrow().copy_map_iter() {
432 let (key, value) = item.map_err(|e| v2_error(py, e))?; 398 let (key, value) = item.map_err(|e| v2_error(py, e))?;