diff rust/hg-cpython/src/filepatterns.rs @ 42960:7a01778bc7b7

rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf Differential Revision: https://phab.mercurial-scm.org/D6774
author Rapha?l Gom?s <rgomes@octobus.net>
date Sun, 01 Sep 2019 20:53:14 +0200
parents ce6797ef6eab
children a264e8a91798
line wrap: on
line diff
--- a/rust/hg-cpython/src/filepatterns.rs	Sun Sep 01 20:53:14 2019 +0200
+++ b/rust/hg-cpython/src/filepatterns.rs	Sun Sep 01 20:53:14 2019 +0200
@@ -13,9 +13,14 @@
 //!
 use crate::exceptions::{PatternError, PatternFileError};
 use cpython::{
-    PyBytes, PyDict, PyModule, PyObject, PyResult, PyTuple, Python, ToPyObject,
+    PyBytes, PyDict, PyModule, PyObject, PyResult, PyString, PyTuple, Python,
+    ToPyObject,
 };
-use hg::{build_single_regex, read_pattern_file, LineNumber, PatternTuple};
+use hg::{
+    build_single_regex, read_pattern_file, utils::files::get_path_from_bytes,
+    LineNumber, PatternTuple,
+};
+use std::path::PathBuf;
 
 /// Rust does not like functions with different return signatures.
 /// The 3-tuple version is always returned by the hg-core function,
@@ -33,7 +38,9 @@
     warn: bool,
     source_info: bool,
 ) -> PyResult<PyTuple> {
-    match read_pattern_file(file_path.extract::<PyBytes>(py)?.data(py), warn) {
+    let bytes = file_path.extract::<PyBytes>(py)?;
+    let path = get_path_from_bytes(bytes.data(py));
+    match read_pattern_file(path, warn) {
         Ok((patterns, warnings)) => {
             if source_info {
                 let itemgetter = |x: &PatternTuple| {
@@ -58,11 +65,16 @@
 
 fn warnings_to_py_bytes(
     py: Python,
-    warnings: &[(Vec<u8>, Vec<u8>)],
-) -> Vec<(PyBytes, PyBytes)> {
+    warnings: &[(PathBuf, Vec<u8>)],
+) -> Vec<(PyString, PyBytes)> {
     warnings
         .iter()
-        .map(|(path, syn)| (PyBytes::new(py, path), PyBytes::new(py, syn)))
+        .map(|(path, syn)| {
+            (
+                PyString::new(py, &path.to_string_lossy()),
+                PyBytes::new(py, syn),
+            )
+        })
         .collect()
 }