Mercurial > public > mercurial-scm > hg
comparison rust/hg-cpython/src/revlog.rs @ 44010:2728fcb8127c
rust-index: make it possible to clone the struct referencing the C index
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.
Differential Revision: https://phab.mercurial-scm.org/D7656
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Fri, 13 Dec 2019 19:52:26 +0100 |
parents | b69d5f3a41d0 |
children | c627f1b2f3c3 |
comparison
equal
deleted
inserted
replaced
44009:e685fac56693 | 44010:2728fcb8127c |
---|---|
5 // This software may be used and distributed according to the terms of the | 5 // This software may be used and distributed according to the terms of the |
6 // GNU General Public License version 2 or any later version. | 6 // GNU General Public License version 2 or any later version. |
7 | 7 |
8 use crate::cindex; | 8 use crate::cindex; |
9 use cpython::{ | 9 use cpython::{ |
10 ObjectProtocol, PyDict, PyModule, PyObject, PyResult, PyTuple, Python, | 10 ObjectProtocol, PyClone, PyDict, PyModule, PyObject, PyResult, PyTuple, Python, PythonObject, |
11 PythonObject, ToPyObject, | 11 ToPyObject, |
12 }; | 12 }; |
13 use hg::Revision; | 13 use hg::Revision; |
14 use std::cell::RefCell; | 14 use std::cell::RefCell; |
15 | 15 |
16 /// Return a Struct implementing the Graph trait | 16 /// Return a Struct implementing the Graph trait |
17 pub(crate) fn pyindex_to_graph( | 17 pub(crate) fn pyindex_to_graph(py: Python, index: PyObject) -> PyResult<cindex::Index> { |
18 py: Python, | |
19 index: PyObject, | |
20 ) -> PyResult<cindex::Index> { | |
21 cindex::Index::new(py, index) | 18 cindex::Index::new(py, index) |
22 } | 19 } |
23 | 20 |
24 py_class!(pub class MixedIndex |py| { | 21 py_class!(pub class MixedIndex |py| { |
25 data cindex: RefCell<cindex::Index>; | 22 data cindex: RefCell<cindex::Index>; |
196 self.cindex(py) | 193 self.cindex(py) |
197 .borrow() | 194 .borrow() |
198 .inner() | 195 .inner() |
199 .call_method(py, name, args, kwargs) | 196 .call_method(py, name, args, kwargs) |
200 } | 197 } |
198 | |
199 pub fn clone_cindex(&self, py: Python) -> cindex::Index { | |
200 self.cindex(py).borrow().clone_ref(py) | |
201 } | |
201 } | 202 } |
202 | 203 |
203 /// Create the module, with __package__ given from parent | 204 /// Create the module, with __package__ given from parent |
204 pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> { | 205 pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> { |
205 let dotted_name = &format!("{}.revlog", package); | 206 let dotted_name = &format!("{}.revlog", package); |