Patchwork [3,of,5,STABLE] py3: send bytes from Rust-created warning patterns

login
register
mail settings
Submitter Raphaël Gomès
Date Dec. 12, 2019, 4:46 p.m.
Message ID <2f084275a6435092058e.1576169187@alphare-carbon.lan>
Download mbox | patch
Permalink /patch/43746/
State New
Headers show

Comments

Raphaël Gomès - Dec. 12, 2019, 4:46 p.m.
# HG changeset patch
# User Raphaël Gomès <rgomes@octobus.net>
# Date 1574095079 -3600
#      Mon Nov 18 17:37:59 2019 +0100
# Branch stable
# Node ID 2f084275a6435092058eaf9cb1a46cc6d7b0821a
# Parent  697e5119ce5d2ae8c7ef048a8a18e2b15c7af17a
py3: send bytes from Rust-created warning patterns

Python code expects bytes in both Python 2 and Python 3, so we should send
bytes.

Differential Revision: https://phab.mercurial-scm.org/D7454
via Mercurial-devel - Dec. 12, 2019, 5:22 p.m.
On Thu, Dec 12, 2019 at 9:14 AM Raphaël Gomès <raphael.gomes@octobus.net>
wrote:

> # HG changeset patch
> # User Raphaël Gomès <rgomes@octobus.net>
> # Date 1574095079 -3600
> #      Mon Nov 18 17:37:59 2019 +0100
> # Branch stable
> # Node ID 2f084275a6435092058eaf9cb1a46cc6d7b0821a
> # Parent  697e5119ce5d2ae8c7ef048a8a18e2b15c7af17a
> py3: send bytes from Rust-created warning patterns
>
> Python code expects bytes in both Python 2 and Python 3, so we should send
> bytes.
>
> Differential Revision: https://phab.mercurial-scm.org/D7454


delete?


>
>
> diff -r 697e5119ce5d -r 2f084275a643 rust/hg-cpython/src/filepatterns.rs
> --- a/rust/hg-cpython/src/filepatterns.rs       Mon Nov 18 17:34:44 2019
> +0100
> +++ b/rust/hg-cpython/src/filepatterns.rs       Mon Nov 18 17:37:59 2019
> +0100
> @@ -13,8 +13,7 @@
>  //!
>  use crate::exceptions::{PatternError, PatternFileError};
>  use cpython::{
> -    PyBytes, PyDict, PyModule, PyObject, PyResult, PyString, PyTuple,
> Python,
> -    ToPyObject,
> +    PyBytes, PyDict, PyModule, PyObject, PyResult, PyTuple, Python,
> ToPyObject,
>  };
>  use hg::{
>      build_single_regex, read_pattern_file,
> utils::files::get_path_from_bytes,
> @@ -66,12 +65,12 @@
>  fn warnings_to_py_bytes(
>      py: Python,
>      warnings: &[(PathBuf, Vec<u8>)],
> -) -> Vec<(PyString, PyBytes)> {
> +) -> Vec<(PyBytes, PyBytes)> {
>      warnings
>          .iter()
>          .map(|(path, syn)| {
>              (
> -                PyString::new(py, &path.to_string_lossy()),
> +                PyBytes::new(py, &path.to_string_lossy().as_bytes()),
>                  PyBytes::new(py, syn),
>              )
>          })
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff -r 697e5119ce5d -r 2f084275a643 rust/hg-cpython/src/filepatterns.rs
--- a/rust/hg-cpython/src/filepatterns.rs	Mon Nov 18 17:34:44 2019 +0100
+++ b/rust/hg-cpython/src/filepatterns.rs	Mon Nov 18 17:37:59 2019 +0100
@@ -13,8 +13,7 @@ 
 //!
 use crate::exceptions::{PatternError, PatternFileError};
 use cpython::{
-    PyBytes, PyDict, PyModule, PyObject, PyResult, PyString, PyTuple, Python,
-    ToPyObject,
+    PyBytes, PyDict, PyModule, PyObject, PyResult, PyTuple, Python, ToPyObject,
 };
 use hg::{
     build_single_regex, read_pattern_file, utils::files::get_path_from_bytes,
@@ -66,12 +65,12 @@ 
 fn warnings_to_py_bytes(
     py: Python,
     warnings: &[(PathBuf, Vec<u8>)],
-) -> Vec<(PyString, PyBytes)> {
+) -> Vec<(PyBytes, PyBytes)> {
     warnings
         .iter()
         .map(|(path, syn)| {
             (
-                PyString::new(py, &path.to_string_lossy()),
+                PyBytes::new(py, &path.to_string_lossy().as_bytes()),
                 PyBytes::new(py, syn),
             )
         })