rust-index: add support for `del index[r]`
authorRaphaël Gomès <rgomes@octobus.net>
Thu, 02 Nov 2023 15:50:13 +0100
changeset 51250 a8ca22119385
parent 51249 2966b88d4531
child 51251 0409bd6ba663
rust-index: add support for `del index[r]` Only the `del index[r:]` syntax was supported, but the comment said otherwise. It's not actually used in core code, but the C index supports it.
rust/hg-cpython/src/revlog.rs
--- a/rust/hg-cpython/src/revlog.rs	Mon Oct 30 21:26:17 2023 +0100
+++ b/rust/hg-cpython/src/revlog.rs	Thu Nov 02 15:50:13 2023 +0100
@@ -214,8 +214,12 @@
 
     def __delitem__(&self, key: PyObject) -> PyResult<()> {
         // __delitem__ is both for `del idx[r]` and `del idx[r1:r2]`
-        let start = key.getattr(py, "start")?;
-        let start = UncheckedRevision(start.extract(py)?);
+        let start = if let Ok(rev) = key.extract(py) {
+            UncheckedRevision(rev)
+        } else {
+            let start = key.getattr(py, "start")?;
+            UncheckedRevision(start.extract(py)?)
+        };
         let start = self.index(py)
             .borrow()
             .check_revision(start)