Mercurial > public > mercurial-scm > hg
changeset 52787:e5f89bd1a5ee
rust-pyo3-revlog: _index___len__
author | Georges Racinet <georges.racinet@cloudcrane.io> |
---|---|
date | Wed, 25 Dec 2024 17:15:35 +0100 |
parents | 4e34e8fd46d4 |
children | e29e75e8328c |
files | rust/hg-pyo3/src/revlog/mod.rs tests/test-rust-revlog.py |
diffstat | 2 files changed, 9 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-pyo3/src/revlog/mod.rs Wed Dec 25 16:16:22 2024 +0100 +++ b/rust/hg-pyo3/src/revlog/mod.rs Wed Dec 25 17:15:35 2024 +0100 @@ -6,6 +6,7 @@ // // This software may be used and distributed according to the terms of the // GNU General Public License version 2 or any later version. +#![allow(non_snake_case)] use pyo3::buffer::PyBuffer; use pyo3::prelude::*; use pyo3::types::{PyBytes, PyBytesMethods, PyList}; @@ -223,6 +224,10 @@ .map(|rev| py_node_for_rev(slf.py(), idx, rev))) }) } + + fn _index___len__(slf: &Bound<'_, Self>) -> PyResult<usize> { + Self::with_index_read(slf, |idx| Ok(idx.len())) + } } impl InnerRevlog { @@ -253,7 +258,6 @@ f(&self_ref, guard) } - #[allow(dead_code)] fn with_index_read<T>( slf: &Bound<'_, Self>, f: impl FnOnce(&Index) -> PyResult<T>,
--- a/tests/test-rust-revlog.py Wed Dec 25 16:16:22 2024 +0100 +++ b/tests/test-rust-revlog.py Wed Dec 25 17:15:35 2024 +0100 @@ -46,6 +46,10 @@ self.assertIsNone(idx.partialmatch(self.bogus_node_hex[:3])) self.assertEqual(idx.shortest(self.node0), 1) + def test_len(self): + idx = self.parserustindex() + self.assertEqual(len(idx), 4) + # Conditional skipping done by the base class class RustInnerRevlogTest( @@ -57,10 +61,6 @@ idx = self.parserustindex() self.assertEqual(idx.headrevs(), [3]) - def test_len(self): - idx = self.parserustindex() - self.assertEqual(len(idx), 4) - def test_ancestors(self): rustidx = self.parserustindex() lazy = LazyAncestors(rustidx, [3], 0, True)