mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 00:45:18 +03:00
pycheckout: add checkoutplan::apply
Reviewed By: DurhamG Differential Revision: D26469704 fbshipit-source-id: 010a12b04b7f6a5d08e1aa248130026341306595
This commit is contained in:
parent
51a29c5d7e
commit
6498f4f892
@ -4,6 +4,8 @@ version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.20"
|
||||
async-runtime = { path = "../../../../lib/async-runtime" }
|
||||
checkout = { path = "../../../../lib/checkout" }
|
||||
cpython-ext = { path = "../../../../lib/cpython-ext", default-features = false }
|
||||
cpython = { version = "0.5", default-features = false }
|
||||
@ -11,3 +13,5 @@ manifest-tree = { path = "../../../../lib/manifest-tree" }
|
||||
pathmatcher = { path = "../../../../lib/pathmatcher" }
|
||||
pypathmatcher = { path = "../pypathmatcher" }
|
||||
pymanifest = { path = "../pymanifest" }
|
||||
pyrevisionstore = { path = "../pyrevisionstore" }
|
||||
vfs = { path = "../../../../lib/vfs" }
|
||||
|
@ -7,13 +7,18 @@
|
||||
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
use anyhow::format_err;
|
||||
use async_runtime::block_on_exclusive as block_on;
|
||||
use checkout::CheckoutPlan;
|
||||
use cpython::*;
|
||||
use cpython_ext::ResultPyErrExt;
|
||||
use cpython_ext::{ExtractInnerRef, PyNone, PyPathBuf, ResultPyErrExt};
|
||||
use manifest_tree::Diff;
|
||||
use pathmatcher::{AlwaysMatcher, Matcher};
|
||||
use pymanifest::treemanifest;
|
||||
use pypathmatcher::PythonMatcher;
|
||||
use pyrevisionstore::contentstore;
|
||||
use std::cell::RefCell;
|
||||
use vfs::VFS;
|
||||
|
||||
pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> {
|
||||
let name = [package, "checkout"].join(".");
|
||||
@ -23,7 +28,7 @@ pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> {
|
||||
}
|
||||
|
||||
py_class!(class checkoutplan |py| {
|
||||
data plan: CheckoutPlan;
|
||||
data plan: RefCell<Option<CheckoutPlan>>;
|
||||
|
||||
def __new__(
|
||||
_cls,
|
||||
@ -40,7 +45,18 @@ py_class!(class checkoutplan |py| {
|
||||
let target = target_manifest.borrow_underlying(py);
|
||||
let diff = Diff::new(¤t, &target, &matcher);
|
||||
let plan = CheckoutPlan::from_diff(diff).map_pyerr(py)?;
|
||||
checkoutplan::create_instance(py, plan)
|
||||
checkoutplan::create_instance(py, RefCell::new(Some(plan)))
|
||||
}
|
||||
|
||||
def apply(&self, root: PyPathBuf, content_store: &contentstore) -> PyResult<PyNone> {
|
||||
let vfs = VFS::new(root.to_path_buf()).map_pyerr(py)?;
|
||||
let store = content_store.extract_inner_ref(py);
|
||||
let plan = self.plan(py).borrow_mut()
|
||||
.take()
|
||||
.ok_or_else(|| format_err!("checkoutplan::apply can not be called twice on the same checkoutplan"))
|
||||
.map_pyerr(py)?;
|
||||
block_on(plan.apply_remote_data_store(&vfs, store)).map_pyerr(py)?;
|
||||
Ok(PyNone)
|
||||
}
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user