pyrevisionstore: implement flush for PythonMutableDataPack

Summary:
A new flush method is added to mutablebasepack that just close and re-init
self.

Reviewed By: kulshrax

Differential Revision: D15416708

fbshipit-source-id: 79cdcb20b51b9688a5e95402057c7da27883003c
This commit is contained in:
Xavier Deguillard 2019-05-21 14:14:06 -07:00 committed by Facebook Github Bot
parent 5d29594498
commit 8e9bc8c347
2 changed files with 20 additions and 0 deletions

View File

@ -524,6 +524,9 @@ class mutablebasepack(versionmixin):
opener.createmode = 0o444
self.opener = opener
self._ui = ui
self._packdir = packdir
self.entries = {}
shallowutil.mkstickygroupdir(ui, packdir)
@ -549,6 +552,11 @@ class mutablebasepack(versionmixin):
versionbuf = struct.pack("!B", self.VERSION) # unsigned 1 byte int
self.writeraw(versionbuf)
def flush(self):
path = self.close()
self.__init__(self._ui, self._packdir)
return path
def __enter__(self):
return self

View File

@ -227,4 +227,16 @@ impl MutableDeltaStore for PythonMutableDataPack {
let py_path = PyBytes::extract(py, &py_path).map_err(|e| pyerr_to_error(py, e))?;
Ok(Some(local_bytes_to_path(py_path.data(py))?.into_owned()))
}
fn flush(&mut self) -> Fallible<Option<PathBuf>> {
let gil = Python::acquire_gil();
let py = gil.python();
let py_path = self
.py_datapack
.call_method(py, "flush", NoArgs, None)
.map_err(|e| pyerr_to_error(py, e))?;
let py_path = PyBytes::extract(py, &py_path).map_err(|e| pyerr_to_error(py, e))?;
Ok(Some(local_bytes_to_path(py_path.data(py))?.into_owned()))
}
}