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

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

Comments

Raphaël Gomès - Dec. 12, 2019, 4:46 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1574173197 -32400
#      Tue Nov 19 23:19:57 2019 +0900
# Branch stable
# Node ID e0da98d4b03fbe274fe4c736ace28bc588c41ddf
# Parent  c549f8598cdf726b2e4239db5728ceebec448c23
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 -r c549f8598cdf -r e0da98d4b03f rust/hg-core/src/utils/files.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> {
diff -r c549f8598cdf -r e0da98d4b03f rust/hg-cpython/src/filepatterns.rs
--- 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),
             )
         })