diff --git a/eden/scm/saplingnative/bindings/modules/pystoremodel/src/lib.rs b/eden/scm/saplingnative/bindings/modules/pystoremodel/src/lib.rs index 9fadc5fdb9adc..02e91bd69be02 100644 --- a/eden/scm/saplingnative/bindings/modules/pystoremodel/src/lib.rs +++ b/eden/scm/saplingnative/bindings/modules/pystoremodel/src/lib.rs @@ -14,6 +14,7 @@ use cpython_ext::ResultPyErrExt; use storemodel::Bytes; use storemodel::FileStore as NativeFileStore; use storemodel::InsertOpts; +use storemodel::Kind; use storemodel::SerializationFormat; use storemodel::TreeItemFlag; use storemodel::TreeStore as NativeTreeStore; @@ -80,6 +81,23 @@ py_class!(pub class TreeStore |py| { Ok(Serde(id)) } + /// insert_data(opts, path, data: bytes) -> node + /// opts: {parents: List[node], hg_flags: int} + /// + /// The callsite takes care of serialization. + /// `data` does not include Git or Hg SHA1 headers. + /// + /// Check `storemodel::KeyStore` for details. + def insert_data(&self, opts: Serde, path: &str, data: PyBytes) -> PyResult> { + let mut opts = opts.0; + opts.kind = Kind::Tree; + let path = RepoPath::from_str(path).map_pyerr(py)?; + let data = data.data(py); + let inner = self.inner(py); + let id = py.allow_threads(|| inner.insert_data(opts, path, data)).map_pyerr(py)?; + Ok(Serde(id)) + } + def flush(&self) -> PyResult { let inner = self.inner(py); py.allow_threads(|| inner.flush()).map_pyerr(py)?;