From 7ad57c10a5ea861fda5986240d31ba480a79af35 Mon Sep 17 00:00:00 2001 From: Andrey Chursin Date: Thu, 1 Jul 2021 10:47:44 -0700 Subject: [PATCH] bindings: use pycell instead of mincode for pull data Reviewed By: quark-zju Differential Revision: D29474445 fbshipit-source-id: dd6536bdbac6e5690c918a222bf3823537ceffcc --- .../bindings/modules/pydag/src/commits.rs | 11 ++++++----- .../bindings/modules/pyedenapi/src/client.rs | 6 +++--- .../bindings/modules/pyedenapi/src/pyext.rs | 14 ++++++++------ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/eden/scm/edenscmnative/bindings/modules/pydag/src/commits.rs b/eden/scm/edenscmnative/bindings/modules/pydag/src/commits.rs index 44b11123af..7a9a53d7c4 100644 --- a/eden/scm/edenscmnative/bindings/modules/pydag/src/commits.rs +++ b/eden/scm/edenscmnative/bindings/modules/pydag/src/commits.rs @@ -9,10 +9,11 @@ use crate::dagalgo::dagalgo; use crate::idmap; use crate::Names; use crate::Spans; -use anyhow::Result; +use anyhow::{format_err, Result}; use async_runtime::try_block_unless_interrupted as block_on; use cpython::*; use cpython_ext::convert::BytesLike; +use cpython_ext::pycell; use cpython_ext::ExtractInner; use cpython_ext::PyNone; use cpython_ext::PyPath; @@ -126,14 +127,14 @@ py_class!(pub class commits |py| { Ok(PyNone) } - /// Import pull data (serialized in mincode) and flush. + /// Import pull data(inside pycell) and flush. /// Returns (commit_count, segment_count) on success. - def importpulldata(&self, data: PyBytes) -> PyResult<(u64, usize)> { - let data: CloneData = mincode::deserialize(data.data(py)).map_pyerr(py)?; + def importpulldata(&self, data: pycell) -> PyResult<(u64, usize)> { + let data: Box> = data.take(py).ok_or(format_err!("Data is not CloneData")).map_pyerr(py)?; let commits = data.flat_segments.vertex_count(); let segments = data.flat_segments.segment_count(); let mut inner = self.inner(py).borrow_mut(); - block_on(inner.import_pull_data(data)).map_pyerr(py)?; + block_on(inner.import_pull_data(*data)).map_pyerr(py)?; Ok((commits, segments)) } diff --git a/eden/scm/edenscmnative/bindings/modules/pyedenapi/src/client.rs b/eden/scm/edenscmnative/bindings/modules/pyedenapi/src/client.rs index c7e3bc535c..3294e1213d 100644 --- a/eden/scm/edenscmnative/bindings/modules/pyedenapi/src/client.rs +++ b/eden/scm/edenscmnative/bindings/modules/pyedenapi/src/client.rs @@ -12,6 +12,7 @@ use cpython::*; use cpython_async::PyFuture; use cpython_async::TStream; use cpython_ext::convert::Serde; +use cpython_ext::pycell; use cpython_ext::{ExtractInner, ExtractInnerRef, PyPathBuf, ResultPyErrExt}; use edenapi::{Builder, EdenApi}; use edenapi_types::CommitGraphEntry; @@ -230,10 +231,9 @@ py_class!(pub class client |py| { self.inner(py).clone().clone_data_py(py, repo) } - /// pullfastforwardmaster(repo: str, old_master: Bytes, new_master: Bytes) -> bytes - /// mincode-serialized CloneData. + /// pullfastforwardmaster(repo: str, old_master: Bytes, new_master: Bytes) -> pycell def pullfastforwardmaster(&self, repo: String, old_master: PyBytes, new_master: PyBytes) - -> PyResult + -> PyResult { self.inner(py).clone().pull_fast_forward_master_py(py, repo, old_master, new_master) } diff --git a/eden/scm/edenscmnative/bindings/modules/pyedenapi/src/pyext.rs b/eden/scm/edenscmnative/bindings/modules/pyedenapi/src/pyext.rs index 63d8322ce8..93b2840d67 100644 --- a/eden/scm/edenscmnative/bindings/modules/pyedenapi/src/pyext.rs +++ b/eden/scm/edenscmnative/bindings/modules/pyedenapi/src/pyext.rs @@ -15,8 +15,9 @@ use async_runtime::block_unless_interrupted; use cpython_async::PyFuture; use cpython_async::TStream; use cpython_ext::convert::Serde; +use cpython_ext::pycell; use cpython_ext::{PyPathBuf, ResultPyErrExt}; -use dag_types::Location; +use dag_types::{Location, VertexName}; use edenapi::{EdenApi, EdenApiBlocking, EdenApiError, Fetch, Stats}; use edenapi_types::CommitGraphEntry; use edenapi_types::CommitKnownResponse; @@ -402,10 +403,10 @@ pub trait EdenApiPyExt: EdenApi { repo: String, old_master: PyBytes, new_master: PyBytes, - ) -> PyResult { + ) -> PyResult { let old_master = to_hgid(py, &old_master); let new_master = to_hgid(py, &new_master); - let bytes = { + let data = { py.allow_threads(|| { block_unless_interrupted(async move { match self @@ -413,15 +414,16 @@ pub trait EdenApiPyExt: EdenApi { .await { Err(e) => Err(e), - Ok(data) => Ok(mincode::serialize(&data)), + Ok(data) => Ok(data.convert_vertex(|hgid| { + VertexName(hgid.into_byte_array().to_vec().into()) + })), } }) }) .map_pyerr(py)? .map_pyerr(py)? - .map_pyerr(py)? }; - Ok(PyBytes::new(py, &bytes)) + pycell::new(py, data) } fn lookup_file_contents(