Mercurial > public > mercurial-scm > hg
diff rust/hg-core/src/utils/files.rs @ 42437:9609430d3625
rust-filepatterns: use bytes instead of String
In my initial patch, I introduced an unnecessary hard constraint on UTF-8
filenames and patterns which I forgot to remove. Although the performance
penalty for using String might be negligible, we don't want to break
compatibility with non-UTF-8 encodings for no reason.
Moreover, this change allows for a cleaner Rust core API.
This patch introduces a new utils module that is used with this fix.
Finally, PatternError was not put inside the Python module generated by
Rust, which would have raised a NameError.
Differential Revision: https://phab.mercurial-scm.org/D6485
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Thu, 06 Jun 2019 15:30:56 +0200 |
parents | |
children | f305f1d7d559 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rust/hg-core/src/utils/files.rs Thu Jun 06 15:30:56 2019 +0200 @@ -0,0 +1,17 @@ +use std::path::Path; + +pub fn get_path_from_bytes(bytes: &[u8]) -> &Path { + let os_str; + #[cfg(unix)] + { + use std::os::unix::ffi::OsStrExt; + os_str = std::ffi::OsStr::from_bytes(bytes); + } + #[cfg(windows)] + { + use std::os::windows::ffi::OsStrExt; + os_str = std::ffi::OsString::from_wide(bytes); + } + + Path::new(os_str) +}