Mercurial > hg
comparison rust/hg-cpython/src/dirstate/dirstate_map.rs @ 45610:496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
The previous patch added the `dirstate-tree` feature gate to enable the two
dirstate implementations to co-habit while the tree-based one gets better.
This patch copies over the code that differs, be it because the algorithm
changed or because the borrowing rules are different.
Indeed, `DirstateTree` is not observationally equivalent to the std `HashMap` in
the APIs we use: it does not have the `Entry` API (yet?) and its iterator
returns owned values instead of references. This last point is because the
implementation needs to be changed to a more clever and efficient solution.
Differential Revision: https://phab.mercurial-scm.org/D9133
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Wed, 30 Sep 2020 18:10:29 +0200 |
parents | 26114bd6ec60 |
children | 5bae4bc9bd42 |
comparison
equal
deleted
inserted
replaced
45609:e604a3c03ab9 | 45610:496537c9c1b4 |
---|---|
140 .map_err(|e: DirstateParseError| { | 140 .map_err(|e: DirstateParseError| { |
141 PyErr::new::<exc::ValueError, _>(py, e.to_string()) | 141 PyErr::new::<exc::ValueError, _>(py, e.to_string()) |
142 })?, | 142 })?, |
143 ) | 143 ) |
144 .and_then(|b| Ok(b.to_py_object(py))) | 144 .and_then(|b| Ok(b.to_py_object(py))) |
145 .or_else(|_| { | 145 .or_else(|e| { |
146 Err(PyErr::new::<exc::OSError, _>( | 146 Err(PyErr::new::<exc::OSError, _>( |
147 py, | 147 py, |
148 "Dirstate error".to_string(), | 148 format!("Dirstate error: {}", e.to_string()), |
149 )) | 149 )) |
150 }) | 150 }) |
151 } | 151 } |
152 | 152 |
153 def clearambiguoustimes( | 153 def clearambiguoustimes( |
547 &'a self, | 547 &'a self, |
548 py: Python<'a>, | 548 py: Python<'a>, |
549 ) -> Ref<'a, RustDirstateMap> { | 549 ) -> Ref<'a, RustDirstateMap> { |
550 self.inner(py).borrow() | 550 self.inner(py).borrow() |
551 } | 551 } |
552 #[cfg(not(feature = "dirstate-tree"))] | |
552 fn translate_key( | 553 fn translate_key( |
553 py: Python, | 554 py: Python, |
554 res: (&HgPathBuf, &DirstateEntry), | 555 res: (&HgPathBuf, &DirstateEntry), |
555 ) -> PyResult<Option<PyBytes>> { | 556 ) -> PyResult<Option<PyBytes>> { |
556 Ok(Some(PyBytes::new(py, res.0.as_bytes()))) | 557 Ok(Some(PyBytes::new(py, res.0.as_bytes()))) |
557 } | 558 } |
559 #[cfg(not(feature = "dirstate-tree"))] | |
558 fn translate_key_value( | 560 fn translate_key_value( |
559 py: Python, | 561 py: Python, |
560 res: (&HgPathBuf, &DirstateEntry), | 562 res: (&HgPathBuf, &DirstateEntry), |
561 ) -> PyResult<Option<(PyBytes, PyObject)>> { | 563 ) -> PyResult<Option<(PyBytes, PyObject)>> { |
562 let (f, entry) = res; | 564 let (f, entry) = res; |
563 Ok(Some(( | 565 Ok(Some(( |
564 PyBytes::new(py, f.as_bytes()), | 566 PyBytes::new(py, f.as_bytes()), |
565 make_dirstate_tuple(py, entry)?, | 567 make_dirstate_tuple(py, &entry)?, |
568 ))) | |
569 } | |
570 #[cfg(feature = "dirstate-tree")] | |
571 fn translate_key( | |
572 py: Python, | |
573 res: (HgPathBuf, DirstateEntry), | |
574 ) -> PyResult<Option<PyBytes>> { | |
575 Ok(Some(PyBytes::new(py, res.0.as_bytes()))) | |
576 } | |
577 #[cfg(feature = "dirstate-tree")] | |
578 fn translate_key_value( | |
579 py: Python, | |
580 res: (HgPathBuf, DirstateEntry), | |
581 ) -> PyResult<Option<(PyBytes, PyObject)>> { | |
582 let (f, entry) = res; | |
583 Ok(Some(( | |
584 PyBytes::new(py, f.as_bytes()), | |
585 make_dirstate_tuple(py, &entry)?, | |
566 ))) | 586 ))) |
567 } | 587 } |
568 } | 588 } |
569 | 589 |
570 py_shared_iterator!( | 590 py_shared_iterator!( |