Mercurial > hg
changeset 51602:68929cf3c0c6
match: avoid rust fast path if the matcher was tampered with
Otherwise the fast path does not respect the modifications made
by the extension (concretely largefiles, but other extensions can
start using that too)
author | Arseniy Alekseyev <aalekseyev@janestreet.com> |
---|---|
date | Tue, 09 Apr 2024 11:12:24 +0100 |
parents | ea3343104f07 |
children | a2afa35641c9 |
files | rust/hg-cpython/src/dirstate/status.rs |
diffstat | 1 files changed, 15 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-cpython/src/dirstate/status.rs Tue Apr 09 11:00:52 2024 +0100 +++ b/rust/hg-cpython/src/dirstate/status.rs Tue Apr 09 11:12:24 2024 +0100 @@ -11,7 +11,7 @@ use crate::{dirstate::DirstateMap, exceptions::FallbackError}; use cpython::{ - exc::ValueError, ObjectProtocol, PyBytes, PyErr, PyList, PyObject, + exc::ValueError, ObjectProtocol, PyBool, PyBytes, PyErr, PyList, PyObject, PyResult, PyTuple, Python, PythonObject, ToPyObject, }; use hg::dirstate::status::StatusPath; @@ -26,8 +26,8 @@ files::{get_bytes_from_path, get_path_from_bytes}, hg_path::{HgPath, HgPathBuf}, }, - BadMatch, DirstateStatus, IgnorePattern, PatternFileWarning, StatusError, - StatusOptions, + BadMatch, DirstateStatus, IgnorePattern, PatternError, PatternFileWarning, + StatusError, StatusOptions, }; use std::borrow::Borrow; @@ -158,6 +158,18 @@ py: Python, matcher: PyObject, ) -> PyResult<Box<dyn Matcher + Sync>> { + let tampered = matcher + .call_method(py, "was_tampered_with", PyTuple::empty(py), None)? + .extract::<PyBool>(py)? + .is_true(); + if tampered { + return Err(handle_fallback( + py, + StatusError::Pattern(PatternError::UnsupportedSyntax( + "Pattern matcher was tampered with!".to_string(), + )), + )); + }; match matcher.get_type(py).name(py).borrow() { "alwaysmatcher" => Ok(Box::new(AlwaysMatcher)), "nevermatcher" => Ok(Box::new(NeverMatcher)),