Patchwork D8154: rust-index: add `append` method to cindex/Index

login
register
mail settings
Submitter phabricator
Date Feb. 26, 2020, 5:36 p.m.
Message ID <differential-rev-PHID-DREV-gudxojqcpusx37km33tr-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/45334/
State Superseded
Headers show

Comments

phabricator - Feb. 26, 2020, 5:36 p.m.
Alphare created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This will be used by `MixedIndex` in a later patch.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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

CHANGE DETAILS




To: Alphare, #hg-reviewers
Cc: mercurial-devel

Patch

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
@@ -10,7 +10,10 @@ 
 //! Ideally, we should use an Index entirely implemented in Rust,
 //! but this will take some time to get there.
 
-use cpython::{exc::ImportError, PyClone, PyErr, PyObject, PyResult, Python};
+use cpython::{
+    exc::ImportError, ObjectProtocol, PyClone, PyErr, PyObject, PyResult,
+    PyTuple, Python, PythonObject,
+};
 use hg::revlog::{Node, RevlogIndex};
 use hg::{Graph, GraphError, Revision, WORKING_DIRECTORY_REVISION};
 use libc::c_int;
@@ -97,6 +100,15 @@ 
     pub fn inner(&self) -> &PyObject {
         &self.index
     }
+
+    pub fn append(&mut self, py: Python, tup: PyTuple) -> PyResult<PyObject> {
+        self.index.call_method(
+            py,
+            "append",
+            PyTuple::new(py, &[tup.into_object()]),
+            None,
+        )
+    }
 }
 
 impl Clone for Index {