##// END OF EJS Templates
dirstate: remove the python-side whitelist of allowed matchers...
dirstate: remove the python-side whitelist of allowed matchers This whitelist is too permissive because it allows matchers that contain disallowed ones deep inside, for example through `intersectionmatcher`. It is also too restrictive because it doesn't pass through some of the matchers we support, such as `patternmatcher`. It's also unnecessary because unsupported matchers raise `FallbackError` and we fall back anyway. Making this change makes more of the tests use rust code path, and therefore subtly change behavior. For example, rust status in largefiles repos seems to have strange behavior.

File last commit:

r50525:c7fb9b74 default
r52519:865efc02 default
Show More
utils.rs
43 lines | 1.4 KiB | application/rls-services+xml | RustLexer
use cpython::exc::ValueError;
use cpython::{PyBytes, PyDict, PyErr, PyObject, PyResult, PyTuple, Python};
use hg::revlog::Node;
#[allow(unused)]
pub fn print_python_trace(py: Python) -> PyResult<PyObject> {
eprintln!("===============================");
eprintln!("Printing Python stack from Rust");
eprintln!("===============================");
let traceback = py.import("traceback")?;
let sys = py.import("sys")?;
let kwargs = PyDict::new(py);
kwargs.set_item(py, "file", sys.get(py, "stderr")?)?;
traceback.call(py, "print_stack", PyTuple::new(py, &[]), Some(&kwargs))
}
// Necessary evil for the time being, could maybe be moved to
// a TryFrom in Node itself
const NODE_BYTES_LENGTH: usize = 20;
type NodeData = [u8; NODE_BYTES_LENGTH];
/// Copy incoming Python bytes given as `PyObject` into `Node`,
/// doing the necessary checks
pub fn node_from_py_object<'a>(
py: Python,
bytes: &'a PyObject,
) -> PyResult<Node> {
let as_py_bytes: &'a PyBytes = bytes.extract(py)?;
node_from_py_bytes(py, as_py_bytes)
}
/// Clone incoming Python bytes given as `PyBytes` as a `Node`,
/// doing the necessary checks.
pub fn node_from_py_bytes(py: Python, bytes: &PyBytes) -> PyResult<Node> {
<NodeData>::try_from(bytes.data(py))
.map_err(|_| {
PyErr::new::<ValueError, _>(
py,
format!("{}-byte hash required", NODE_BYTES_LENGTH),
)
})
.map(Into::into)
}