##// END OF EJS Templates
rust-index: check equality between rust and cindex for `__len__`
Raphaël Gomès -
r52086:e79b0a4b default
parent child Browse files
Show More
@@ -142,10 +142,11 b' py_class!(pub class MixedIndex |py| {'
142 let node_bytes = tup.get_item(py, 7).extract(py)?;
142 let node_bytes = tup.get_item(py, 7).extract(py)?;
143 let node = node_from_py_object(py, &node_bytes)?;
143 let node = node_from_py_object(py, &node_bytes)?;
144
144
145 let rev = self.len(py)? as BaseRevision;
145 let mut idx = self.cindex(py).borrow_mut();
146 let mut idx = self.cindex(py).borrow_mut();
146
147
147 // This is ok since we will just add the revision to the index
148 // This is ok since we will just add the revision to the index
148 let rev = Revision(idx.len() as BaseRevision);
149 let rev = Revision(rev);
149 idx.append(py, tup.clone_ref(py))?;
150 idx.append(py, tup.clone_ref(py))?;
150 self.index(py)
151 self.index(py)
151 .borrow_mut()
152 .borrow_mut()
@@ -259,7 +260,7 b' py_class!(pub class MixedIndex |py| {'
259 // and index_getitem.
260 // and index_getitem.
260
261
261 def __len__(&self) -> PyResult<usize> {
262 def __len__(&self) -> PyResult<usize> {
262 self.cindex(py).borrow().inner().len(py)
263 self.len(py)
263 }
264 }
264
265
265 def __getitem__(&self, key: PyObject) -> PyResult<PyObject> {
266 def __getitem__(&self, key: PyObject) -> PyResult<PyObject> {
@@ -287,7 +288,7 b' py_class!(pub class MixedIndex |py| {'
287 let cindex = self.cindex(py).borrow();
288 let cindex = self.cindex(py).borrow();
288 match item.extract::<i32>(py) {
289 match item.extract::<i32>(py) {
289 Ok(rev) => {
290 Ok(rev) => {
290 Ok(rev >= -1 && rev < cindex.inner().len(py)? as BaseRevision)
291 Ok(rev >= -1 && rev < self.len(py)? as BaseRevision)
291 }
292 }
292 Err(_) => {
293 Err(_) => {
293 cindex.inner().call_method(
294 cindex.inner().call_method(
@@ -432,6 +433,13 b' impl MixedIndex {'
432 )
433 )
433 }
434 }
434
435
436 fn len(&self, py: Python) -> PyResult<usize> {
437 let rust_index_len = self.index(py).borrow().len();
438 let cindex_len = self.cindex(py).borrow().inner().len(py)?;
439 assert_eq!(rust_index_len, cindex_len);
440 Ok(cindex_len)
441 }
442
435 /// This is scaffolding at this point, but it could also become
443 /// This is scaffolding at this point, but it could also become
436 /// a way to start a persistent nodemap or perform a
444 /// a way to start a persistent nodemap or perform a
437 /// vacuum / repack operation
445 /// vacuum / repack operation
@@ -441,7 +449,7 b' impl MixedIndex {'
441 nt: &mut NodeTree,
449 nt: &mut NodeTree,
442 ) -> PyResult<PyObject> {
450 ) -> PyResult<PyObject> {
443 let index = self.cindex(py).borrow();
451 let index = self.cindex(py).borrow();
444 for r in 0..index.len() {
452 for r in 0..self.len(py)? {
445 let rev = Revision(r as BaseRevision);
453 let rev = Revision(r as BaseRevision);
446 // in this case node() won't ever return None
454 // in this case node() won't ever return None
447 nt.insert(&*index, index.node(rev).unwrap(), rev)
455 nt.insert(&*index, index.node(rev).unwrap(), rev)
General Comments 0
You need to be logged in to leave comments. Login now