D7656: rust-index: make it possible to clone the struct referencing the C index

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Thu Dec 19 13:11:24 EST 2019


marmoute updated this revision to Diff 18889.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7656?vs=18702&id=18889

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7656/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7656

AFFECTED FILES
  rust/hg-cpython/src/cindex.rs
  rust/hg-cpython/src/revlog.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/revlog.rs b/rust/hg-cpython/src/revlog.rs
--- a/rust/hg-cpython/src/revlog.rs
+++ b/rust/hg-cpython/src/revlog.rs
@@ -7,8 +7,8 @@
 
 use crate::cindex;
 use cpython::{
-    ObjectProtocol, PyDict, PyModule, PyObject, PyResult, PyTuple, Python,
-    PythonObject, ToPyObject,
+    ObjectProtocol, PyClone, PyDict, PyModule, PyObject, PyResult, PyTuple,
+    Python, PythonObject, ToPyObject,
 };
 use hg::Revision;
 use std::cell::RefCell;
@@ -198,6 +198,10 @@
             .inner()
             .call_method(py, name, args, kwargs)
     }
+
+    pub fn clone_cindex(&self, py: Python) -> cindex::Index {
+        self.cindex(py).borrow().clone_ref(py)
+    }
 }
 
 /// Create the module, with __package__ given from parent
diff --git a/rust/hg-cpython/src/cindex.rs b/rust/hg-cpython/src/cindex.rs
--- a/rust/hg-cpython/src/cindex.rs
+++ b/rust/hg-cpython/src/cindex.rs
@@ -85,6 +85,15 @@
     }
 }
 
+impl PyClone for Index {
+    fn clone_ref(&self, py: Python) -> Self {
+        Index {
+            index: self.index.clone_ref(py),
+            parents: self.parents.clone(),
+        }
+    }
+}
+
 impl Graph for Index {
     /// wrap a call to the C extern parents function
     fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> {



To: marmoute, #hg-reviewers
Cc: durin42, kevincox, mercurial-devel


More information about the Mercurial-devel mailing list