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

login
register
mail settings
Submitter phabricator
Date Dec. 13, 2019, 8:13 p.m.
Message ID <differential-rev-PHID-DREV-fpyy2ynmnxotbof5guej-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/43812/
State Superseded
Headers show

Comments

phabricator - Dec. 13, 2019, 8:13 p.m.
marmoute created this revision.
Herald added subscribers: mercurial-devel, kevincox, durin42.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  If we are to hand over the C index object to other code, we need to be able to
  create a new python reference to it.

REPOSITORY
  rHG Mercurial

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

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

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: durin42, kevincox, mercurial-devel
phabricator - Dec. 23, 2019, 6:05 p.m.
This revision now requires changes to proceed.
indygreg added a comment.
indygreg requested changes to this revision.


  This patch needs to be rebased on top of D7543 <https://phab.mercurial-scm.org/D7543> because it can't compile with its changes.

REPOSITORY
  rHG Mercurial

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

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

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

Patch

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,7 +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;
@@ -194,6 +195,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> {