changeset 52814:3fcd86374074

rust-pyo3-revlog: canonical_index_file property
author Rapha?l Gom?s <rgomes@octobus.net>
date Thu, 02 Jan 2025 17:44:52 +0100
parents 65df754d598b
children 4e58167a72a5
files rust/hg-pyo3/src/revlog/mod.rs tests/test-rust-revlog.py
diffstat 2 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-pyo3/src/revlog/mod.rs	Thu Jan 02 17:27:22 2025 +0100
+++ b/rust/hg-pyo3/src/revlog/mod.rs	Thu Jan 02 17:44:52 2025 +0100
@@ -8,6 +8,7 @@
 // GNU General Public License version 2 or any later version.
 #![allow(non_snake_case)]
 use hg::revlog::nodemap::Block;
+use hg::utils::files::get_bytes_from_path;
 use pyo3::buffer::PyBuffer;
 use pyo3::conversion::IntoPyObject;
 use pyo3::exceptions::{PyIndexError, PyTypeError, PyValueError};
@@ -219,6 +220,17 @@
         })
     }
 
+    #[getter]
+    fn canonical_index_file(
+        slf: &Bound<'_, Self>,
+        py: Python<'_>,
+    ) -> PyResult<Py<PyBytes>> {
+        Self::with_core_read(slf, |_self_ref, irl| {
+            let path = irl.canonical_index_file();
+            Ok(PyBytes::new(py, &get_bytes_from_path(path)).into())
+        })
+    }
+
     fn reading(slf: &Bound<'_, Self>) -> PyResult<ReadingContextManager> {
         Ok(ReadingContextManager {
             inner_revlog: slf.clone().unbind(),
--- a/tests/test-rust-revlog.py	Thu Jan 02 17:27:22 2025 +0100
+++ b/tests/test-rust-revlog.py	Thu Jan 02 17:44:52 2025 +0100
@@ -192,6 +192,10 @@
         # let's check bool for an empty one
         self.assertFalse(LazyAncestors(rustidx, [0], 0, False))
 
+    def test_canonical_index_file(self):
+        irl = self.make_inner_revlog()
+        self.assertEqual(irl.canonical_index_file, b'test.i')
+
 
 # Conditional skipping done by the base class
 class PyO3InnerRevlogTest(