Skip to content

Commit

Permalink
pystoremodel: expose TreeStore::insert_data
Browse files Browse the repository at this point in the history
Summary:
This is a lower level API on the super trait `KeyStore`. It might be useful if
the callstie already knows the serialized bytes.

Reviewed By: zzl0

Differential Revision: D64437525

fbshipit-source-id: 27b5925d6c6ef9e886ca00a8fd1627d968217213
  • Loading branch information
quark-zju authored and facebook-github-bot committed Oct 17, 2024
1 parent 0427ab0 commit 20ee0b3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions eden/scm/saplingnative/bindings/modules/pystoremodel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<InsertOpts>, path: &str, data: PyBytes) -> PyResult<Serde<Id20>> {
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<PyNone> {
let inner = self.inner(py);
py.allow_threads(|| inner.flush()).map_pyerr(py)?;
Expand Down

0 comments on commit 20ee0b3

Please sign in to comment.