D7930: rust-status: update rust-cpython bridge to account for the changes in core
Closed by commit rHGf96b28aa4b79: rust-status: update rust-cpython bridge to account for the changes in core (authored by Alphare). This revision was automatically updated to reflect the committed changes. This revision was not accepted when it landed; it landed in state "Needs Review". REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D7930?vs=20498=20722 CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7930/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7930 AFFECTED FILES rust/hg-core/src/dirstate/status.rs rust/hg-cpython/src/dirstate.rs rust/hg-cpython/src/dirstate/status.rs rust/hg-cpython/src/exceptions.rs CHANGE DETAILS diff --git a/rust/hg-cpython/src/exceptions.rs b/rust/hg-cpython/src/exceptions.rs --- a/rust/hg-cpython/src/exceptions.rs +++ b/rust/hg-cpython/src/exceptions.rs @@ -40,3 +40,5 @@ } py_exception!(rustext, HgPathPyError, RuntimeError); +py_exception!(rustext, FallbackError, RuntimeError); +py_exception!(shared_ref, AlreadyBorrowed, RuntimeError); diff --git a/rust/hg-cpython/src/dirstate/status.rs b/rust/hg-cpython/src/dirstate/status.rs --- a/rust/hg-cpython/src/dirstate/status.rs +++ b/rust/hg-cpython/src/dirstate/status.rs @@ -9,33 +9,34 @@ //! `hg-core` crate. From Python, this will be seen as //! `rustext.dirstate.status`. -use crate::dirstate::DirstateMap; -use cpython::exc::ValueError; +use crate::{dirstate::DirstateMap, exceptions::FallbackError}; use cpython::{ -ObjectProtocol, PyBytes, PyErr, PyList, PyObject, PyResult, PyTuple, -Python, PythonObject, ToPyObject, +exc::ValueError, ObjectProtocol, PyBytes, PyErr, PyList, PyObject, +PyResult, PyTuple, Python, PythonObject, ToPyObject, }; -use hg::utils::hg_path::HgPathBuf; use hg::{ -matchers::{AlwaysMatcher, FileMatcher}, -status, -utils::{files::get_path_from_bytes, hg_path::HgPath}, -DirstateStatus, +matchers::{AlwaysMatcher, FileMatcher, IncludeMatcher}, +parse_pattern_syntax, status, +utils::{ +files::{get_bytes_from_path, get_path_from_bytes}, +hg_path::{HgPath, HgPathBuf}, +}, +BadMatch, DirstateStatus, IgnorePattern, PatternFileWarning, StatusError, +StatusOptions, }; -use std::borrow::Borrow; +use std::borrow::{Borrow, Cow}; /// This will be useless once trait impls for collection are added to `PyBytes` /// upstream. -fn collect_pybytes_list>( +fn collect_pybytes_list( py: Python, -collection: &[P], +collection: &[impl AsRef], ) -> PyList { let list = PyList::new(py, &[]); -for (i, path) in collection.iter().enumerate() { -list.insert( +for path in collection.iter() { +list.append( py, -i, PyBytes::new(py, path.as_ref().as_bytes()).into_object(), ) } @@ -43,34 +44,97 @@ list } +fn collect_bad_matches( +py: Python, +collection: &[(impl AsRef, BadMatch)], +) -> PyResult { +let list = PyList::new(py, &[]); + +let os = py.import("os")?; +let get_error_message = |code: i32| -> PyResult<_> { +os.call( +py, +"strerror", +PyTuple::new(py, &[code.to_py_object(py).into_object()]), +None, +) +}; + +for (path, bad_match) in collection.iter() { +let message = match bad_match { +BadMatch::OsError(code) => get_error_message(*code)?, +BadMatch::BadType(bad_type) => format!( +"unsupported file type (type is {})", +bad_type.to_string() +) +.to_py_object(py) +.into_object(), +}; +list.append( +py, +(PyBytes::new(py, path.as_ref().as_bytes()), message) +.to_py_object(py) +.into_object(), +) +} + +Ok(list) +} + +fn handle_fallback(py: Python, err: StatusError) -> PyErr { +match err { +StatusError::Pattern(e) => { +PyErr::new::(py, e.to_string()) +} +e => PyErr::new::(py, e.to_string()), +} +} + pub fn status_wrapper( py: Python, dmap: DirstateMap, matcher: PyObject, root_dir: PyObject, -list_clean: bool, +ignore_files: PyList, +check_exec: bool, last_normal_time: i64, -check_exec: bool, -) -> PyResult<(PyList, PyList, PyList, PyList, PyList, PyList, PyList)> { +list_clean: bool, +list_ignored: bool, +list_unknown: bool, +) -> PyResult { let bytes = root_dir.extract::(py)?; let root_dir = get_path_from_bytes(bytes.data(py)); let dmap: DirstateMap = dmap.to_py_object(py); let dmap = dmap.get_inner(py); +let ignore_files: PyResult> = ignore_files +.iter(py) +.map(|b| { +let file = b.extract::(py)?; +Ok(get_path_from_bytes(file.data(py)).to_owned()) +}) +.collect(); +let ignore_files = ignore_files?; + match
D7930: rust-status: update rust-cpython bridge to account for the changes in core
Alphare updated this revision to Diff 20498. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D7930?vs=20463=20498 BRANCH default CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7930/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7930 AFFECTED FILES rust/hg-core/src/dirstate/status.rs rust/hg-cpython/src/dirstate.rs rust/hg-cpython/src/dirstate/status.rs rust/hg-cpython/src/exceptions.rs CHANGE DETAILS diff --git a/rust/hg-cpython/src/exceptions.rs b/rust/hg-cpython/src/exceptions.rs --- a/rust/hg-cpython/src/exceptions.rs +++ b/rust/hg-cpython/src/exceptions.rs @@ -40,3 +40,5 @@ } py_exception!(rustext, HgPathPyError, RuntimeError); +py_exception!(rustext, FallbackError, RuntimeError); +py_exception!(shared_ref, AlreadyBorrowed, RuntimeError); diff --git a/rust/hg-cpython/src/dirstate/status.rs b/rust/hg-cpython/src/dirstate/status.rs --- a/rust/hg-cpython/src/dirstate/status.rs +++ b/rust/hg-cpython/src/dirstate/status.rs @@ -9,33 +9,34 @@ //! `hg-core` crate. From Python, this will be seen as //! `rustext.dirstate.status`. -use crate::dirstate::DirstateMap; -use cpython::exc::ValueError; +use crate::{dirstate::DirstateMap, exceptions::FallbackError}; use cpython::{ -ObjectProtocol, PyBytes, PyErr, PyList, PyObject, PyResult, PyTuple, -Python, PythonObject, ToPyObject, +exc::ValueError, ObjectProtocol, PyBytes, PyErr, PyList, PyObject, +PyResult, PyTuple, Python, PythonObject, ToPyObject, }; -use hg::utils::hg_path::HgPathBuf; use hg::{ -matchers::{AlwaysMatcher, FileMatcher}, -status, -utils::{files::get_path_from_bytes, hg_path::HgPath}, -DirstateStatus, +matchers::{AlwaysMatcher, FileMatcher, IncludeMatcher}, +parse_pattern_syntax, status, +utils::{ +files::{get_bytes_from_path, get_path_from_bytes}, +hg_path::{HgPath, HgPathBuf}, +}, +BadMatch, DirstateStatus, IgnorePattern, PatternFileWarning, StatusError, +StatusOptions, }; -use std::borrow::Borrow; +use std::borrow::{Borrow, Cow}; /// This will be useless once trait impls for collection are added to `PyBytes` /// upstream. -fn collect_pybytes_list>( +fn collect_pybytes_list( py: Python, -collection: &[P], +collection: &[impl AsRef], ) -> PyList { let list = PyList::new(py, &[]); -for (i, path) in collection.iter().enumerate() { -list.insert( +for path in collection.iter() { +list.append( py, -i, PyBytes::new(py, path.as_ref().as_bytes()).into_object(), ) } @@ -43,34 +44,97 @@ list } +fn collect_bad_matches( +py: Python, +collection: &[(impl AsRef, BadMatch)], +) -> PyResult { +let list = PyList::new(py, &[]); + +let os = py.import("os")?; +let get_error_message = |code: i32| -> PyResult<_> { +os.call( +py, +"strerror", +PyTuple::new(py, &[code.to_py_object(py).into_object()]), +None, +) +}; + +for (path, bad_match) in collection.iter() { +let message = match bad_match { +BadMatch::OsError(code) => get_error_message(*code)?, +BadMatch::BadType(bad_type) => format!( +"unsupported file type (type is {})", +bad_type.to_string() +) +.to_py_object(py) +.into_object(), +}; +list.append( +py, +(PyBytes::new(py, path.as_ref().as_bytes()), message) +.to_py_object(py) +.into_object(), +) +} + +Ok(list) +} + +fn handle_fallback(py: Python, err: StatusError) -> PyErr { +match err { +StatusError::Pattern(e) => { +PyErr::new::(py, e.to_string()) +} +e => PyErr::new::(py, e.to_string()), +} +} + pub fn status_wrapper( py: Python, dmap: DirstateMap, matcher: PyObject, root_dir: PyObject, -list_clean: bool, +ignore_files: PyList, +check_exec: bool, last_normal_time: i64, -check_exec: bool, -) -> PyResult<(PyList, PyList, PyList, PyList, PyList, PyList, PyList)> { +list_clean: bool, +list_ignored: bool, +list_unknown: bool, +) -> PyResult { let bytes = root_dir.extract::(py)?; let root_dir = get_path_from_bytes(bytes.data(py)); let dmap: DirstateMap = dmap.to_py_object(py); let dmap = dmap.get_inner(py); +let ignore_files: PyResult> = ignore_files +.iter(py) +.map(|b| { +let file = b.extract::(py)?; +Ok(get_path_from_bytes(file.data(py)).to_owned()) +}) +.collect(); +let ignore_files = ignore_files?; + match matcher.get_type(py).name(py).borrow() { "alwaysmatcher" => { let matcher = AlwaysMatcher; -let (lookup, status_res) = status( +let ((lookup, status_res), warnings) = status(
D7930: rust-status: update rust-cpython bridge to account for the changes in core
Alphare updated this revision to Diff 20463. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D7930?vs=20455=20463 BRANCH default CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7930/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7930 AFFECTED FILES rust/hg-core/src/dirstate/status.rs rust/hg-cpython/src/dirstate.rs rust/hg-cpython/src/dirstate/status.rs rust/hg-cpython/src/exceptions.rs CHANGE DETAILS diff --git a/rust/hg-cpython/src/exceptions.rs b/rust/hg-cpython/src/exceptions.rs --- a/rust/hg-cpython/src/exceptions.rs +++ b/rust/hg-cpython/src/exceptions.rs @@ -40,3 +40,5 @@ } py_exception!(rustext, HgPathPyError, RuntimeError); +py_exception!(rustext, FallbackError, RuntimeError); +py_exception!(shared_ref, AlreadyBorrowed, RuntimeError); diff --git a/rust/hg-cpython/src/dirstate/status.rs b/rust/hg-cpython/src/dirstate/status.rs --- a/rust/hg-cpython/src/dirstate/status.rs +++ b/rust/hg-cpython/src/dirstate/status.rs @@ -9,33 +9,34 @@ //! `hg-core` crate. From Python, this will be seen as //! `rustext.dirstate.status`. -use crate::dirstate::DirstateMap; -use cpython::exc::ValueError; +use crate::{dirstate::DirstateMap, exceptions::FallbackError}; use cpython::{ -ObjectProtocol, PyBytes, PyErr, PyList, PyObject, PyResult, PyTuple, -Python, PythonObject, ToPyObject, +exc::ValueError, ObjectProtocol, PyBytes, PyErr, PyList, PyObject, +PyResult, PyTuple, Python, PythonObject, ToPyObject, }; -use hg::utils::hg_path::HgPathBuf; use hg::{ -matchers::{AlwaysMatcher, FileMatcher}, -status, -utils::{files::get_path_from_bytes, hg_path::HgPath}, -DirstateStatus, +matchers::{AlwaysMatcher, FileMatcher, IncludeMatcher}, +parse_pattern_syntax, status, +utils::{ +files::{get_bytes_from_path, get_path_from_bytes}, +hg_path::{HgPath, HgPathBuf}, +}, +BadMatch, DirstateStatus, IgnorePattern, PatternFileWarning, StatusError, +StatusOptions, }; -use std::borrow::Borrow; +use std::borrow::{Borrow, Cow}; /// This will be useless once trait impls for collection are added to `PyBytes` /// upstream. -fn collect_pybytes_list>( +fn collect_pybytes_list( py: Python, -collection: &[P], +collection: &[impl AsRef], ) -> PyList { let list = PyList::new(py, &[]); -for (i, path) in collection.iter().enumerate() { -list.insert( +for path in collection.iter() { +list.append( py, -i, PyBytes::new(py, path.as_ref().as_bytes()).into_object(), ) } @@ -43,34 +44,97 @@ list } +fn collect_bad_matches( +py: Python, +collection: &[(impl AsRef, BadMatch)], +) -> PyResult { +let list = PyList::new(py, &[]); + +let os = py.import("os")?; +let get_error_message = |code: i32| -> PyResult<_> { +os.call( +py, +"strerror", +PyTuple::new(py, &[code.to_py_object(py).into_object()]), +None, +) +}; + +for (path, bad_match) in collection.iter() { +let message = match bad_match { +BadMatch::OsError(code) => get_error_message(*code)?, +BadMatch::BadType(bad_type) => format!( +"unsupported file type (type is {})", +bad_type.to_string() +) +.to_py_object(py) +.into_object(), +}; +list.append( +py, +(PyBytes::new(py, path.as_ref().as_bytes()), message) +.to_py_object(py) +.into_object(), +) +} + +Ok(list) +} + +fn handle_fallback(py: Python, err: StatusError) -> PyErr { +match err { +StatusError::Pattern(e) => { +PyErr::new::(py, e.to_string()) +} +e => PyErr::new::(py, e.to_string()), +} +} + pub fn status_wrapper( py: Python, dmap: DirstateMap, matcher: PyObject, root_dir: PyObject, -list_clean: bool, +ignore_files: PyList, +check_exec: bool, last_normal_time: i64, -check_exec: bool, -) -> PyResult<(PyList, PyList, PyList, PyList, PyList, PyList, PyList)> { +list_clean: bool, +list_ignored: bool, +list_unknown: bool, +) -> PyResult { let bytes = root_dir.extract::(py)?; let root_dir = get_path_from_bytes(bytes.data(py)); let dmap: DirstateMap = dmap.to_py_object(py); let dmap = dmap.get_inner(py); +let ignore_files: PyResult> = ignore_files +.iter(py) +.map(|b| { +let file = b.extract::(py)?; +Ok(get_path_from_bytes(file.data(py)).to_owned()) +}) +.collect(); +let ignore_files = ignore_files?; + match matcher.get_type(py).name(py).borrow() { "alwaysmatcher" => { let matcher = AlwaysMatcher; -let (lookup, status_res) = status( +let ((lookup, status_res), warnings) = status(
D7930: rust-status: update rust-cpython bridge to account for the changes in core
Alphare updated this revision to Diff 20455. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D7930?vs=20189=20455 BRANCH default CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7930/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7930 AFFECTED FILES rust/hg-core/src/dirstate/status.rs rust/hg-cpython/src/dirstate.rs rust/hg-cpython/src/dirstate/status.rs rust/hg-cpython/src/exceptions.rs CHANGE DETAILS diff --git a/rust/hg-cpython/src/exceptions.rs b/rust/hg-cpython/src/exceptions.rs --- a/rust/hg-cpython/src/exceptions.rs +++ b/rust/hg-cpython/src/exceptions.rs @@ -40,3 +40,5 @@ } py_exception!(rustext, HgPathPyError, RuntimeError); +py_exception!(rustext, FallbackError, RuntimeError); +py_exception!(shared_ref, AlreadyBorrowed, RuntimeError); diff --git a/rust/hg-cpython/src/dirstate/status.rs b/rust/hg-cpython/src/dirstate/status.rs --- a/rust/hg-cpython/src/dirstate/status.rs +++ b/rust/hg-cpython/src/dirstate/status.rs @@ -9,33 +9,34 @@ //! `hg-core` crate. From Python, this will be seen as //! `rustext.dirstate.status`. -use crate::dirstate::DirstateMap; -use cpython::exc::ValueError; +use crate::{dirstate::DirstateMap, exceptions::FallbackError}; use cpython::{ -ObjectProtocol, PyBytes, PyErr, PyList, PyObject, PyResult, PyTuple, -Python, PythonObject, ToPyObject, +exc::ValueError, ObjectProtocol, PyBytes, PyErr, PyList, PyObject, +PyResult, PyTuple, Python, PythonObject, ToPyObject, }; -use hg::utils::hg_path::HgPathBuf; use hg::{ -matchers::{AlwaysMatcher, FileMatcher}, -status, -utils::{files::get_path_from_bytes, hg_path::HgPath}, -DirstateStatus, +matchers::{AlwaysMatcher, FileMatcher, IncludeMatcher}, +parse_pattern_syntax, status, +utils::{ +files::{get_bytes_from_path, get_path_from_bytes}, +hg_path::{HgPath, HgPathBuf}, +}, +BadMatch, DirstateStatus, IgnorePattern, PatternFileWarning, StatusError, +StatusOptions, }; -use std::borrow::Borrow; +use std::borrow::{Borrow, Cow}; /// This will be useless once trait impls for collection are added to `PyBytes` /// upstream. -fn collect_pybytes_list>( +fn collect_pybytes_list( py: Python, -collection: &[P], +collection: &[impl AsRef], ) -> PyList { let list = PyList::new(py, &[]); -for (i, path) in collection.iter().enumerate() { -list.insert( +for path in collection.iter() { +list.append( py, -i, PyBytes::new(py, path.as_ref().as_bytes()).into_object(), ) } @@ -43,34 +44,97 @@ list } +fn collect_bad_matches( +py: Python, +collection: &[(impl AsRef, BadMatch)], +) -> PyResult { +let list = PyList::new(py, &[]); + +let os = py.import("os")?; +let get_error_message = |code: i32| -> PyResult<_> { +os.call( +py, +"strerror", +PyTuple::new(py, &[code.to_py_object(py).into_object()]), +None, +) +}; + +for (path, bad_match) in collection.iter() { +let message = match bad_match { +BadMatch::OsError(code) => get_error_message(*code)?, +BadMatch::BadType(bad_type) => format!( +"unsupported file type (type is {})", +bad_type.to_string() +) +.to_py_object(py) +.into_object(), +}; +list.append( +py, +(PyBytes::new(py, path.as_ref().as_bytes()), message) +.to_py_object(py) +.into_object(), +) +} + +Ok(list) +} + +fn handle_fallback(py: Python, err: StatusError) -> PyErr { +match err { +StatusError::Pattern(e) => { +PyErr::new::(py, e.to_string()) +} +e => PyErr::new::(py, e.to_string()), +} +} + pub fn status_wrapper( py: Python, dmap: DirstateMap, matcher: PyObject, root_dir: PyObject, -list_clean: bool, +ignore_files: PyList, +check_exec: bool, last_normal_time: i64, -check_exec: bool, -) -> PyResult<(PyList, PyList, PyList, PyList, PyList, PyList, PyList)> { +list_clean: bool, +list_ignored: bool, +list_unknown: bool, +) -> PyResult { let bytes = root_dir.extract::(py)?; let root_dir = get_path_from_bytes(bytes.data(py)); let dmap: DirstateMap = dmap.to_py_object(py); let dmap = dmap.get_inner(py); +let ignore_files: PyResult> = ignore_files +.iter(py) +.map(|b| { +let file = b.extract::(py)?; +Ok(get_path_from_bytes(file.data(py)).to_owned()) +}) +.collect(); +let ignore_files = ignore_files?; + match matcher.get_type(py).name(py).borrow() { "alwaysmatcher" => { let matcher = AlwaysMatcher; -let (lookup, status_res) = status( +let ((lookup, status_res), warnings) = status(
D7930: rust-status: update rust-cpython bridge to account for the changes in core
Alphare updated this revision to Diff 20189. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D7930?vs=20158=20189 BRANCH default CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7930/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7930 AFFECTED FILES rust/hg-core/src/dirstate/status.rs rust/hg-cpython/src/dirstate.rs rust/hg-cpython/src/dirstate/status.rs rust/hg-cpython/src/exceptions.rs CHANGE DETAILS diff --git a/rust/hg-cpython/src/exceptions.rs b/rust/hg-cpython/src/exceptions.rs --- a/rust/hg-cpython/src/exceptions.rs +++ b/rust/hg-cpython/src/exceptions.rs @@ -40,3 +40,5 @@ } py_exception!(rustext, HgPathPyError, RuntimeError); +py_exception!(rustext, FallbackError, RuntimeError); +py_exception!(shared_ref, AlreadyBorrowed, RuntimeError); diff --git a/rust/hg-cpython/src/dirstate/status.rs b/rust/hg-cpython/src/dirstate/status.rs --- a/rust/hg-cpython/src/dirstate/status.rs +++ b/rust/hg-cpython/src/dirstate/status.rs @@ -9,33 +9,34 @@ //! `hg-core` crate. From Python, this will be seen as //! `rustext.dirstate.status`. -use crate::dirstate::DirstateMap; -use cpython::exc::ValueError; +use crate::{dirstate::DirstateMap, exceptions::FallbackError}; use cpython::{ -ObjectProtocol, PyBytes, PyErr, PyList, PyObject, PyResult, PyTuple, -Python, PythonObject, ToPyObject, +exc::ValueError, ObjectProtocol, PyBytes, PyErr, PyList, PyObject, +PyResult, PyTuple, Python, PythonObject, ToPyObject, }; -use hg::utils::hg_path::HgPathBuf; use hg::{ -matchers::{AlwaysMatcher, FileMatcher}, -status, -utils::{files::get_path_from_bytes, hg_path::HgPath}, -DirstateStatus, +matchers::{AlwaysMatcher, FileMatcher, IncludeMatcher}, +parse_pattern_syntax, status, +utils::{ +files::{get_bytes_from_path, get_path_from_bytes}, +hg_path::{HgPath, HgPathBuf}, +}, +BadMatch, DirstateStatus, IgnorePattern, PatternFileWarning, StatusError, +StatusOptions, }; -use std::borrow::Borrow; +use std::borrow::{Borrow, Cow}; /// This will be useless once trait impls for collection are added to `PyBytes` /// upstream. -fn collect_pybytes_list>( +fn collect_pybytes_list( py: Python, -collection: &[P], +collection: &[impl AsRef], ) -> PyList { let list = PyList::new(py, &[]); -for (i, path) in collection.iter().enumerate() { -list.insert( +for path in collection.iter() { +list.append( py, -i, PyBytes::new(py, path.as_ref().as_bytes()).into_object(), ) } @@ -43,34 +44,97 @@ list } +fn collect_bad_matches( +py: Python, +collection: &[(impl AsRef, BadMatch)], +) -> PyResult { +let list = PyList::new(py, &[]); + +let os = py.import("os")?; +let get_error_message = |code: i32| -> PyResult<_> { +os.call( +py, +"strerror", +PyTuple::new(py, &[code.to_py_object(py).into_object()]), +None, +) +}; + +for (path, bad_match) in collection.iter() { +let message = match bad_match { +BadMatch::OsError(code) => get_error_message(*code)?, +BadMatch::BadType(bad_type) => format!( +"unsupported file type (type is {})", +bad_type.to_string() +) +.to_py_object(py) +.into_object(), +}; +list.append( +py, +(PyBytes::new(py, path.as_ref().as_bytes()), message) +.to_py_object(py) +.into_object(), +) +} + +Ok(list) +} + +fn handle_fallback(py: Python, err: StatusError) -> PyErr { +match err { +StatusError::Pattern(e) => { +PyErr::new::(py, e.to_string()) +} +e => PyErr::new::(py, e.to_string()), +} +} + pub fn status_wrapper( py: Python, dmap: DirstateMap, matcher: PyObject, root_dir: PyObject, -list_clean: bool, +ignore_files: PyList, +check_exec: bool, last_normal_time: i64, -check_exec: bool, -) -> PyResult<(PyList, PyList, PyList, PyList, PyList, PyList, PyList)> { +list_clean: bool, +list_ignored: bool, +list_unknown: bool, +) -> PyResult { let bytes = root_dir.extract::(py)?; let root_dir = get_path_from_bytes(bytes.data(py)); let dmap: DirstateMap = dmap.to_py_object(py); let dmap = dmap.get_inner(py); +let ignore_files: PyResult> = ignore_files +.iter(py) +.map(|b| { +let file = b.extract::(py)?; +Ok(get_path_from_bytes(file.data(py)).to_owned()) +}) +.collect(); +let ignore_files = ignore_files?; + match matcher.get_type(py).name(py).borrow() { "alwaysmatcher" => { let matcher = AlwaysMatcher; -let (lookup, status_res) = status( +let ((lookup, status_res), warnings) = status(
D7930: rust-status: update rust-cpython bridge to account for the changes in core
Alphare updated this revision to Diff 20158. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D7930?vs=20049=20158 BRANCH default CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7930/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7930 AFFECTED FILES rust/hg-core/src/dirstate/status.rs rust/hg-cpython/src/dirstate.rs rust/hg-cpython/src/dirstate/status.rs rust/hg-cpython/src/exceptions.rs CHANGE DETAILS diff --git a/rust/hg-cpython/src/exceptions.rs b/rust/hg-cpython/src/exceptions.rs --- a/rust/hg-cpython/src/exceptions.rs +++ b/rust/hg-cpython/src/exceptions.rs @@ -40,3 +40,5 @@ } py_exception!(rustext, HgPathPyError, RuntimeError); +py_exception!(rustext, FallbackError, RuntimeError); +py_exception!(shared_ref, AlreadyBorrowed, RuntimeError); diff --git a/rust/hg-cpython/src/dirstate/status.rs b/rust/hg-cpython/src/dirstate/status.rs --- a/rust/hg-cpython/src/dirstate/status.rs +++ b/rust/hg-cpython/src/dirstate/status.rs @@ -9,33 +9,34 @@ //! `hg-core` crate. From Python, this will be seen as //! `rustext.dirstate.status`. -use crate::dirstate::DirstateMap; -use cpython::exc::ValueError; +use crate::{dirstate::DirstateMap, exceptions::FallbackError}; use cpython::{ -ObjectProtocol, PyBytes, PyErr, PyList, PyObject, PyResult, PyTuple, -Python, PythonObject, ToPyObject, +exc::ValueError, ObjectProtocol, PyBytes, PyErr, PyList, PyObject, +PyResult, PyTuple, Python, PythonObject, ToPyObject, }; -use hg::utils::hg_path::HgPathBuf; use hg::{ -matchers::{AlwaysMatcher, FileMatcher}, -status, -utils::{files::get_path_from_bytes, hg_path::HgPath}, -DirstateStatus, +matchers::{AlwaysMatcher, FileMatcher, IncludeMatcher}, +parse_pattern_syntax, status, +utils::{ +files::{get_bytes_from_path, get_path_from_bytes}, +hg_path::{HgPath, HgPathBuf}, +}, +BadMatch, DirstateStatus, IgnorePattern, PatternFileWarning, StatusError, +StatusOptions, }; -use std::borrow::Borrow; +use std::borrow::{Borrow, Cow}; /// This will be useless once trait impls for collection are added to `PyBytes` /// upstream. -fn collect_pybytes_list>( +fn collect_pybytes_list( py: Python, -collection: &[P], +collection: &[impl AsRef], ) -> PyList { let list = PyList::new(py, &[]); -for (i, path) in collection.iter().enumerate() { -list.insert( +for path in collection.iter() { +list.append( py, -i, PyBytes::new(py, path.as_ref().as_bytes()).into_object(), ) } @@ -43,34 +44,97 @@ list } +fn collect_bad_matches( +py: Python, +collection: &[(impl AsRef, BadMatch)], +) -> PyResult { +let list = PyList::new(py, &[]); + +let os = py.import("os")?; +let get_error_message = |code: i32| -> PyResult<_> { +os.call( +py, +"strerror", +PyTuple::new(py, &[code.to_py_object(py).into_object()]), +None, +) +}; + +for (path, bad_match) in collection.iter() { +let message = match bad_match { +BadMatch::OsError(code) => get_error_message(*code)?, +BadMatch::BadType(bad_type) => format!( +"unsupported file type (type is {})", +bad_type.to_string() +) +.to_py_object(py) +.into_object(), +}; +list.append( +py, +(PyBytes::new(py, path.as_ref().as_bytes()), message) +.to_py_object(py) +.into_object(), +) +} + +Ok(list) +} + +fn handle_fallback(py: Python, err: StatusError) -> PyErr { +match err { +StatusError::Pattern(e) => { +PyErr::new::(py, e.to_string()) +} +e => PyErr::new::(py, e.to_string()), +} +} + pub fn status_wrapper( py: Python, dmap: DirstateMap, matcher: PyObject, root_dir: PyObject, -list_clean: bool, +ignore_files: PyList, +check_exec: bool, last_normal_time: i64, -check_exec: bool, -) -> PyResult<(PyList, PyList, PyList, PyList, PyList, PyList, PyList)> { +list_clean: bool, +list_ignored: bool, +list_unknown: bool, +) -> PyResult { let bytes = root_dir.extract::(py)?; let root_dir = get_path_from_bytes(bytes.data(py)); let dmap: DirstateMap = dmap.to_py_object(py); let dmap = dmap.get_inner(py); +let ignore_files: PyResult> = ignore_files +.iter(py) +.map(|b| { +let file = b.extract::(py)?; +Ok(get_path_from_bytes(file.data(py)).to_owned()) +}) +.collect(); +let ignore_files = ignore_files?; + match matcher.get_type(py).name(py).borrow() { "alwaysmatcher" => { let matcher = AlwaysMatcher; -let (lookup, status_res) = status( +let ((lookup, status_res), warnings) = status(
D7930: rust-status: update rust-cpython bridge to account for the changes in core
Alphare updated this revision to Diff 20049. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D7930?vs=19948=20049 BRANCH default CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7930/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7930 AFFECTED FILES rust/hg-core/src/dirstate/status.rs rust/hg-cpython/src/dirstate.rs rust/hg-cpython/src/dirstate/status.rs rust/hg-cpython/src/exceptions.rs CHANGE DETAILS diff --git a/rust/hg-cpython/src/exceptions.rs b/rust/hg-cpython/src/exceptions.rs --- a/rust/hg-cpython/src/exceptions.rs +++ b/rust/hg-cpython/src/exceptions.rs @@ -40,3 +40,5 @@ } py_exception!(rustext, HgPathPyError, RuntimeError); +py_exception!(rustext, FallbackError, RuntimeError); +py_exception!(shared_ref, AlreadyBorrowed, RuntimeError); diff --git a/rust/hg-cpython/src/dirstate/status.rs b/rust/hg-cpython/src/dirstate/status.rs --- a/rust/hg-cpython/src/dirstate/status.rs +++ b/rust/hg-cpython/src/dirstate/status.rs @@ -9,26 +9,28 @@ //! `hg-core` crate. From Python, this will be seen as //! `rustext.dirstate.status`. -use crate::dirstate::DirstateMap; -use cpython::exc::ValueError; +use crate::{dirstate::DirstateMap, exceptions::FallbackError}; use cpython::{ -ObjectProtocol, PyBytes, PyErr, PyList, PyObject, PyResult, PyTuple, -Python, PythonObject, ToPyObject, +exc::ValueError, ObjectProtocol, PyBytes, PyErr, PyList, PyObject, +PyResult, PyTuple, Python, PythonObject, ToPyObject, }; -use hg::utils::hg_path::HgPathBuf; use hg::{ -matchers::{AlwaysMatcher, FileMatcher}, -status, -utils::{files::get_path_from_bytes, hg_path::HgPath}, -DirstateStatus, +matchers::{AlwaysMatcher, FileMatcher, IncludeMatcher}, +parse_pattern_syntax, status, +utils::{ +files::{get_bytes_from_path, get_path_from_bytes}, +hg_path::{HgPath, HgPathBuf}, +}, +BadMatch, DirstateStatus, IgnorePattern, PatternFileWarning, StatusError, +StatusOptions, }; -use std::borrow::Borrow; +use std::borrow::{Borrow, Cow}; /// This will be useless once trait impls for collection are added to `PyBytes` /// upstream. -fn collect_pybytes_list>( +fn collect_pybytes_list( py: Python, -collection: &[P], +collection: &[impl AsRef], ) -> PyList { let list = PyList::new(py, &[]); @@ -43,34 +45,98 @@ list } +fn collect_bad_matches( +py: Python, +collection: &[(impl AsRef, BadMatch)], +) -> PyResult { +let list = PyList::new(py, &[]); + +let os = py.import("os")?; +let get_error_message = |code: i32| -> PyResult<_> { +os.call( +py, +"strerror", +PyTuple::new(py, &[code.to_py_object(py).into_object()]), +None, +) +}; + +for (i, (path, bad_match)) in collection.iter().enumerate() { +let message = match bad_match { +BadMatch::OsError(code) => get_error_message(*code)?, +BadMatch::BadType(bad_type) => format!( +"unsupported file type (type is {})", +bad_type.to_string() +) +.to_py_object(py) +.into_object(), +}; +list.insert_item( +py, +i, +(PyBytes::new(py, path.as_ref().as_bytes()), message) +.to_py_object(py) +.into_object(), +) +} + +Ok(list) +} + +fn handle_fallback(py: Python, err: StatusError) -> PyErr { +match err { +StatusError::Pattern(e) => { +PyErr::new::(py, e.to_string()) +} +e => PyErr::new::(py, e.to_string()), +} +} + pub fn status_wrapper( py: Python, dmap: DirstateMap, matcher: PyObject, root_dir: PyObject, -list_clean: bool, +ignore_files: PyList, +check_exec: bool, last_normal_time: i64, -check_exec: bool, -) -> PyResult<(PyList, PyList, PyList, PyList, PyList, PyList, PyList)> { +list_clean: bool, +list_ignored: bool, +list_unknown: bool, +) -> PyResult { let bytes = root_dir.extract::(py)?; let root_dir = get_path_from_bytes(bytes.data(py)); let dmap: DirstateMap = dmap.to_py_object(py); let dmap = dmap.get_inner(py); +let ignore_files: PyResult> = ignore_files +.iter(py) +.map(|b| { +let file = b.extract::(py)?; +Ok(get_path_from_bytes(file.data(py)).to_owned()) +}) +.collect(); +let ignore_files = ignore_files?; + match matcher.get_type(py).name(py).borrow() { "alwaysmatcher" => { let matcher = AlwaysMatcher; -let (lookup, status_res) = status( +let ((lookup, status_res), warnings) = status( , , _dir, -list_clean, -last_normal_time, -check_exec, +_files, +StatusOptions { +
D7930: rust-status: update rust-cpython bridge to account for the changes in core
kevincox added inline comments. kevincox accepted this revision. INLINE COMMENTS > status.rs:76 > +BadType::Unknown => "unknown", > +} > +) This should probably be a method on BadType. REPOSITORY rHG Mercurial CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7930/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7930 To: Alphare, #hg-reviewers, kevincox Cc: kevincox, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D7930: rust-status: update rust-cpython bridge to account for the changes in core
Alphare updated this revision to Diff 19948. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D7930?vs=19422=19948 BRANCH default CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7930/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7930 AFFECTED FILES rust/hg-cpython/src/dirstate.rs rust/hg-cpython/src/dirstate/status.rs rust/hg-cpython/src/exceptions.rs CHANGE DETAILS diff --git a/rust/hg-cpython/src/exceptions.rs b/rust/hg-cpython/src/exceptions.rs --- a/rust/hg-cpython/src/exceptions.rs +++ b/rust/hg-cpython/src/exceptions.rs @@ -40,3 +40,5 @@ } py_exception!(rustext, HgPathPyError, RuntimeError); +py_exception!(rustext, FallbackError, RuntimeError); +py_exception!(shared_ref, AlreadyBorrowed, RuntimeError); diff --git a/rust/hg-cpython/src/dirstate/status.rs b/rust/hg-cpython/src/dirstate/status.rs --- a/rust/hg-cpython/src/dirstate/status.rs +++ b/rust/hg-cpython/src/dirstate/status.rs @@ -9,26 +9,28 @@ //! `hg-core` crate. From Python, this will be seen as //! `rustext.dirstate.status`. -use crate::dirstate::DirstateMap; -use cpython::exc::ValueError; +use crate::{dirstate::DirstateMap, exceptions::FallbackError}; use cpython::{ -ObjectProtocol, PyBytes, PyErr, PyList, PyObject, PyResult, PyTuple, -Python, PythonObject, ToPyObject, +exc::ValueError, ObjectProtocol, PyBytes, PyErr, PyList, PyObject, +PyResult, PyTuple, Python, PythonObject, ToPyObject, }; -use hg::utils::hg_path::HgPathBuf; use hg::{ -matchers::{AlwaysMatcher, FileMatcher}, -status, -utils::{files::get_path_from_bytes, hg_path::HgPath}, -DirstateStatus, +matchers::{AlwaysMatcher, FileMatcher, IncludeMatcher}, +parse_pattern_syntax, status, +utils::{ +files::{get_bytes_from_path, get_path_from_bytes}, +hg_path::{HgPath, HgPathBuf}, +}, +BadMatch, BadType, DirstateStatus, IgnorePattern, PatternFileWarning, +StatusError, StatusOptions, }; -use std::borrow::Borrow; +use std::borrow::{Borrow, Cow}; /// This will be useless once trait impls for collection are added to `PyBytes` /// upstream. -fn collect_pybytes_list>( +fn collect_pybytes_list( py: Python, -collection: &[P], +collection: &[impl AsRef], ) -> PyList { let list = PyList::new(py, &[]); @@ -43,34 +45,105 @@ list } +fn collect_bad_matches( +py: Python, +collection: &[(impl AsRef, BadMatch)], +) -> PyResult { +let list = PyList::new(py, &[]); + +let os = py.import("os")?; +let get_error_message = |code: i32| -> PyResult<_> { +os.call( +py, +"strerror", +PyTuple::new(py, &[code.to_py_object(py).into_object()]), +None, +) +}; + +for (i, (path, bad_match)) in collection.iter().enumerate() { +let message = match bad_match { +BadMatch::OsError(code) => get_error_message(*code)?, +BadMatch::BadType(bad_type) => format!( +"unsupported file type (type is {})", +match bad_type { +BadType::CharacterDevice => "character device", +BadType::BlockDevice => "block device", +BadType::FIFO => "fifo", +BadType::Socket => "socket", +BadType::Directory => "directory", +BadType::Unknown => "unknown", +} +) +.to_py_object(py) +.into_object(), +}; +list.insert_item( +py, +i, +(PyBytes::new(py, path.as_ref().as_bytes()), message) +.to_py_object(py) +.into_object(), +) +} + +Ok(list) +} + +fn handle_fallback(py: Python, err: StatusError) -> PyErr { +match err { +StatusError::Pattern(e) => { +PyErr::new::(py, e.to_string()) +} +e => PyErr::new::(py, e.to_string()), +} +} + pub fn status_wrapper( py: Python, dmap: DirstateMap, matcher: PyObject, root_dir: PyObject, -list_clean: bool, +ignore_files: PyList, +check_exec: bool, last_normal_time: i64, -check_exec: bool, -) -> PyResult<(PyList, PyList, PyList, PyList, PyList, PyList, PyList)> { +list_clean: bool, +list_ignored: bool, +list_unknown: bool, +) -> PyResult { let bytes = root_dir.extract::(py)?; let root_dir = get_path_from_bytes(bytes.data(py)); let dmap: DirstateMap = dmap.to_py_object(py); let dmap = dmap.get_inner(py); +let ignore_files: PyResult> = ignore_files +.iter(py) +.map(|b| { +let file = b.extract::(py)?; +Ok(get_path_from_bytes(file.data(py)).to_owned()) +}) +.collect(); +let ignore_files = ignore_files?; + match matcher.get_type(py).name(py).borrow() { "alwaysmatcher" => { let matcher = AlwaysMatcher; -let
D7930: rust-status: update rust-cpython bridge to account for the changes in core
Alphare created this revision. Herald added subscribers: mercurial-devel, kevincox. Herald added a reviewer: hg-reviewers. REPOSITORY rHG Mercurial BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D7930 AFFECTED FILES rust/hg-cpython/src/dirstate.rs rust/hg-cpython/src/dirstate/status.rs rust/hg-cpython/src/exceptions.rs CHANGE DETAILS diff --git a/rust/hg-cpython/src/exceptions.rs b/rust/hg-cpython/src/exceptions.rs --- a/rust/hg-cpython/src/exceptions.rs +++ b/rust/hg-cpython/src/exceptions.rs @@ -40,5 +40,6 @@ } py_exception!(rustext, HgPathPyError, RuntimeError); +py_exception!(rustext, FallbackError, RuntimeError); py_exception!(shared_ref, AlreadyBorrowed, RuntimeError); diff --git a/rust/hg-cpython/src/dirstate/status.rs b/rust/hg-cpython/src/dirstate/status.rs --- a/rust/hg-cpython/src/dirstate/status.rs +++ b/rust/hg-cpython/src/dirstate/status.rs @@ -9,26 +9,28 @@ //! `hg-core` crate. From Python, this will be seen as //! `rustext.dirstate.status`. -use crate::dirstate::DirstateMap; -use cpython::exc::ValueError; +use crate::{dirstate::DirstateMap, exceptions::FallbackError}; use cpython::{ -ObjectProtocol, PyBytes, PyErr, PyList, PyObject, PyResult, PyTuple, -Python, PythonObject, ToPyObject, +exc::ValueError, ObjectProtocol, PyBytes, PyErr, PyList, PyObject, +PyResult, PyTuple, Python, PythonObject, ToPyObject, }; -use hg::utils::hg_path::HgPathBuf; use hg::{ -matchers::{AlwaysMatcher, FileMatcher}, -status, -utils::{files::get_path_from_bytes, hg_path::HgPath}, -DirstateStatus, +matchers::{AlwaysMatcher, FileMatcher, IncludeMatcher}, +parse_pattern_syntax, status, +utils::{ +files::{get_bytes_from_path, get_path_from_bytes}, +hg_path::{HgPath, HgPathBuf}, +}, +BadMatch, BadType, DirstateStatus, IgnorePattern, PatternFileWarning, +StatusError, StatusOptions, }; -use std::borrow::Borrow; +use std::borrow::{Borrow, Cow}; /// This will be useless once trait impls for collection are added to `PyBytes` /// upstream. -fn collect_pybytes_list>( +fn collect_pybytes_list( py: Python, -collection: &[P], +collection: &[impl AsRef], ) -> PyList { let list = PyList::new(py, &[]); @@ -43,34 +45,105 @@ list } +fn collect_bad_matches( +py: Python, +collection: &[(impl AsRef, BadMatch)], +) -> PyResult { +let list = PyList::new(py, &[]); + +let os = py.import("os")?; +let get_error_message = |code: i32| -> PyResult<_> { +os.call( +py, +"strerror", +PyTuple::new(py, &[code.to_py_object(py).into_object()]), +None, +) +}; + +for (i, (path, bad_match)) in collection.iter().enumerate() { +let message = match bad_match { +BadMatch::OsError(code) => get_error_message(*code)?, +BadMatch::BadType(bad_type) => format!( +"unsupported file type (type is {})", +match bad_type { +BadType::CharacterDevice => "character device", +BadType::BlockDevice => "block device", +BadType::FIFO => "fifo", +BadType::Socket => "socket", +BadType::Directory => "directory", +BadType::Unknown => "unknown", +} +) +.to_py_object(py) +.into_object(), +}; +list.insert_item( +py, +i, +(PyBytes::new(py, path.as_ref().as_bytes()), message) +.to_py_object(py) +.into_object(), +) +} + +Ok(list) +} + +fn handle_fallback(py: Python, err: StatusError) -> PyErr { +match err { +StatusError::Pattern(e) => { +PyErr::new::(py, e.to_string()) +} +e => PyErr::new::(py, e.to_string()), +} +} + pub fn status_wrapper( py: Python, dmap: DirstateMap, matcher: PyObject, root_dir: PyObject, -list_clean: bool, +ignore_files: PyList, +check_exec: bool, last_normal_time: i64, -check_exec: bool, -) -> PyResult<(PyList, PyList, PyList, PyList, PyList, PyList, PyList)> { +list_clean: bool, +list_ignored: bool, +list_unknown: bool, +) -> PyResult { let bytes = root_dir.extract::(py)?; let root_dir = get_path_from_bytes(bytes.data(py)); let dmap: DirstateMap = dmap.to_py_object(py); let dmap = dmap.get_inner(py); +let ignore_files: PyResult> = ignore_files +.iter(py) +.map(|b| { +let file = b.extract::(py)?; +Ok(get_path_from_bytes(file.data(py)).to_owned()) +}) +.collect(); +let ignore_files = ignore_files?; + match matcher.get_type(py).name(py).borrow() { "alwaysmatcher" => { let matcher = AlwaysMatcher; -let (lookup, status_res) = status( +let ((lookup, status_res),