rust-cpython: do not convert warning pattern to utf-8 bytes stable
authorYuya Nishihara <yuya@tcha.org>
Tue, 19 Nov 2019 23:19:57 +0900
branchstable
changeset 43868 b06cf2809ec3
parent 43867 4f1cddd1939e
child 43869 cf065c6a0197
child 43947 b4c82b704180
rust-cpython: do not convert warning pattern to utf-8 bytes On Unix, both Rust Path and Mercurial expect a locale-dependent bytes, and we don't support Windows yet. Differential Revision: https://phab.mercurial-scm.org/D7614
rust/hg-core/src/utils/files.rs
rust/hg-cpython/src/filepatterns.rs
--- a/rust/hg-core/src/utils/files.rs	Tue Nov 19 23:16:16 2019 +0900
+++ b/rust/hg-core/src/utils/files.rs	Tue Nov 19 23:19:57 2019 +0900
@@ -29,6 +29,14 @@
     Path::new(os_str)
 }
 
+// TODO: need to convert from WTF8 to MBCS bytes on Windows.
+// that's why Vec<u8> is returned.
+#[cfg(unix)]
+pub fn get_bytes_from_path(path: impl AsRef<Path>) -> Vec<u8> {
+    use std::os::unix::ffi::OsStrExt;
+    path.as_ref().as_os_str().as_bytes().to_vec()
+}
+
 /// An iterator over repository path yielding itself and its ancestors.
 #[derive(Copy, Clone, Debug)]
 pub struct Ancestors<'a> {
--- a/rust/hg-cpython/src/filepatterns.rs	Tue Nov 19 23:16:16 2019 +0900
+++ b/rust/hg-cpython/src/filepatterns.rs	Tue Nov 19 23:19:57 2019 +0900
@@ -68,7 +68,7 @@
         .iter()
         .map(|(path, syn)| {
             (
-                PyBytes::new(py, &path.to_string_lossy().as_bytes()),
+                PyBytes::new(py, &files::get_bytes_from_path(path)),
                 PyBytes::new(py, syn),
             )
         })