diff rust/hg-pyo3/src/revlog/mod.rs @ 52797:f76911bfbfb1

rust-pyo3-revlog: issnapshot We're borrowing twice for simplicity, but it seems that is also what the `hg-cpython` version was doing.
author Georges Racinet <georges.racinet@cloudcrane.io>
date Mon, 23 Dec 2024 19:45:14 +0100
parents 670ebb2f975a
children 88d62995a65b
line wrap: on
line diff
--- a/rust/hg-pyo3/src/revlog/mod.rs	Mon Dec 23 19:22:21 2024 +0100
+++ b/rust/hg-pyo3/src/revlog/mod.rs	Mon Dec 23 19:45:14 2024 +0100
@@ -9,7 +9,7 @@
 #![allow(non_snake_case)]
 use pyo3::buffer::PyBuffer;
 use pyo3::conversion::IntoPyObject;
-use pyo3::exceptions::{PyIndexError, PyTypeError};
+use pyo3::exceptions::{PyIndexError, PyTypeError, PyValueError};
 use pyo3::prelude::*;
 use pyo3::types::{PyBytes, PyBytesMethods, PyList, PyTuple};
 use pyo3_sharedref::{PyShareable, SharedByPyObject};
@@ -427,6 +427,21 @@
         }
     }
 
+    /// True if the object is a snapshot
+    fn _index_issnapshot(
+        slf: &Bound<'_, Self>,
+        rev: PyRevision,
+    ) -> PyResult<bool> {
+        let rev: UncheckedRevision = rev.into();
+        let rev = Self::with_index_read(slf, |idx| {
+            idx.check_revision(rev).ok_or_else(|| rev_not_in_index(rev))
+        })?;
+        Self::with_core_read(slf, |irl| {
+            irl.is_snapshot(rev)
+                .map_err(|e| PyValueError::new_err(e.to_string()))
+        })
+    }
+
     fn _index___len__(slf: &Bound<'_, Self>) -> PyResult<usize> {
         Self::with_index_read(slf, |idx| Ok(idx.len()))
     }