Patchwork D7614: rust-cpython: do not convert warning pattern to utf-8 bytes

login
register
mail settings
Submitter phabricator
Date Dec. 13, 2019, 6:18 p.m.
Message ID <249a123ea131ccf31ff54d4506b15c64@localhost.localdomain>
Download mbox | patch
Permalink /patch/43802/
State Not Applicable
Headers show

Comments

phabricator - Dec. 13, 2019, 6:18 p.m.
Closed by commit rHGb06cf2809ec3: rust-cpython: do not convert warning pattern to utf-8 bytes (authored by yuja).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7614?vs=18644&id=18692

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7614/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7614

AFFECTED FILES
  rust/hg-core/src/utils/files.rs
  rust/hg-cpython/src/filepatterns.rs

CHANGE DETAILS




To: Alphare, #hg-reviewers
Cc: durin42, kevincox, mercurial-devel

Patch

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 @@ 
         .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),
             )
         })
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 @@ 
     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> {