--- a/rust/hg-cpython/src/cindex.rs Thu Dec 06 20:01:21 2018 +0100
+++ b/rust/hg-cpython/src/cindex.rs Tue Dec 04 11:05:06 2018 +0100
@@ -15,7 +15,7 @@
extern crate python3_sys as python_sys;
use self::python_sys::PyCapsule_Import;
-use cpython::{PyErr, PyObject, PyResult, Python};
+use cpython::{PyClone, PyErr, PyObject, PyResult, Python};
use hg::{Graph, GraphError, Revision};
use libc::c_int;
use std::ffi::CStr;
@@ -59,7 +59,6 @@
/// the core API, that would be tied to `GILGuard` / `Python<'p>`
/// in the case of the `cpython` crate bindings yet could leave room for other
/// mechanisms in other contexts.
-
pub struct Index {
index: PyObject,
parents: IndexParentsFn,
@@ -74,6 +73,16 @@
}
}
+impl Clone for Index {
+ fn clone(&self) -> Self {
+ let guard = Python::acquire_gil();
+ Index {
+ index: self.index.clone_ref(guard.python()),
+ 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> {