Patchwork [2,of,2] rust-cpython: do not convert warning pattern to utf-8 bytes

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 19, 2019, 3:20 p.m.
Message ID <1a80d721cba5db045de9.1574176837@mimosa>
Download mbox | patch
Permalink /patch/43359/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 19, 2019, 3:20 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1574173197 -32400
#      Tue Nov 19 23:19:57 2019 +0900
# Node ID 1a80d721cba5db045de98bf2cf51f5d72f4958ae
# Parent  3a542e3823dda716ec473bf5ef9f4c5b60e8a368
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.

Patch

diff --git a/rust/hg-core/src/utils/files.rs b/rust/hg-core/src/utils/files.rs
--- a/rust/hg-core/src/utils/files.rs
+++ b/rust/hg-core/src/utils/files.rs
@@ -29,6 +29,14 @@  pub fn get_path_from_bytes(bytes: &[u8])
     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> {
diff --git a/rust/hg-cpython/src/filepatterns.rs b/rust/hg-cpython/src/filepatterns.rs
--- a/rust/hg-cpython/src/filepatterns.rs
+++ b/rust/hg-cpython/src/filepatterns.rs
@@ -68,7 +68,7 @@  fn warnings_to_py_bytes(
         .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),
             )
         })