From patchwork Fri Dec 27 17:13:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D7656: rust-index: make it possible to clone the struct referencing the C index From: phabricator X-Patchwork-Id: 44054 Message-Id: <52d3ce389628cd01ce7d0f075f698388@localhost.localdomain> To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Fri, 27 Dec 2019 17:13:06 +0000 marmoute updated this revision to Diff 18940. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D7656?vs=18889&id=18940 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 To: marmoute, #hg-reviewers, Alphare, indygreg Cc: durin42, kevincox, mercurial-devel 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,17 +7,14 @@ 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; /// Return a Struct implementing the Graph trait -pub(crate) fn pyindex_to_graph( - py: Python, - index: PyObject, -) -> PyResult { +pub(crate) fn pyindex_to_graph(py: Python, index: PyObject) -> PyResult { cindex::Index::new(py, index) } @@ -198,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 @@ -88,6 +88,15 @@ } } +impl PyClone for Index { + fn clone_ref(&self, py: Python) -> Self { + Index { + index: self.index.clone_ref(py), + capi: self.capi, + } + } +} + impl Graph for Index { /// wrap a call to the C extern parents function fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> {