Mercurial > public > mercurial-scm > hg
comparison rust/hg-cpython/src/filepatterns.rs @ 42634:0247601869ba
rust-filepatterns: fix type of warnings tuple to (bytes, bytes)
Otherwise warn() in match.py would fail if the warning contains non-ASCII
character.
We might want to add a thin ByteString wrapper around Vec<u8> to
implement ToPyObject<ObjectType = PyBytes>, but I'm not sure.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 21 Jul 2019 12:46:57 +0900 |
parents | 326fdce22fb2 |
children | ce6797ef6eab |
comparison
equal
deleted
inserted
replaced
42633:f78f305454fd | 42634:0247601869ba |
---|---|
38 let itemgetter = |x: &PatternTuple| { | 38 let itemgetter = |x: &PatternTuple| { |
39 (PyBytes::new(py, &x.0), x.1, PyBytes::new(py, &x.2)) | 39 (PyBytes::new(py, &x.0), x.1, PyBytes::new(py, &x.2)) |
40 }; | 40 }; |
41 let results: Vec<(PyBytes, LineNumber, PyBytes)> = | 41 let results: Vec<(PyBytes, LineNumber, PyBytes)> = |
42 patterns.iter().map(itemgetter).collect(); | 42 patterns.iter().map(itemgetter).collect(); |
43 return Ok((results, warnings).to_py_object(py)); | 43 return Ok((results, warnings_to_py_bytes(py, &warnings)) |
44 .to_py_object(py)); | |
44 } | 45 } |
45 let itemgetter = |x: &PatternTuple| PyBytes::new(py, &x.0); | 46 let itemgetter = |x: &PatternTuple| PyBytes::new(py, &x.0); |
46 let results: Vec<PyBytes> = | 47 let results: Vec<PyBytes> = |
47 patterns.iter().map(itemgetter).collect(); | 48 patterns.iter().map(itemgetter).collect(); |
48 Ok((results, warnings).to_py_object(py)) | 49 Ok( |
50 (results, warnings_to_py_bytes(py, &warnings)) | |
51 .to_py_object(py), | |
52 ) | |
49 } | 53 } |
50 Err(e) => Err(PatternFileError::pynew(py, e)), | 54 Err(e) => Err(PatternFileError::pynew(py, e)), |
51 } | 55 } |
56 } | |
57 | |
58 fn warnings_to_py_bytes( | |
59 py: Python, | |
60 warnings: &[(Vec<u8>, Vec<u8>)], | |
61 ) -> Vec<(PyBytes, PyBytes)> { | |
62 warnings | |
63 .iter() | |
64 .map(|(path, syn)| (PyBytes::new(py, path), PyBytes::new(py, syn))) | |
65 .collect() | |
52 } | 66 } |
53 | 67 |
54 fn build_single_regex_wrapper( | 68 fn build_single_regex_wrapper( |
55 py: Python, | 69 py: Python, |
56 kind: PyObject, | 70 kind: PyObject, |