##// END OF EJS Templates
rust: Introduce a get_bytes_from_os_str utility function...
Simon Sapin -
r47338:d2e61f00 default
parent child Browse files
Show More
@@ -11,7 +11,7 b' use super::layer;'
11 use crate::config::layer::{
11 use crate::config::layer::{
12 ConfigError, ConfigLayer, ConfigParseError, ConfigValue,
12 ConfigError, ConfigLayer, ConfigParseError, ConfigValue,
13 };
13 };
14 use crate::utils::files::get_bytes_from_path;
14 use crate::utils::files::get_bytes_from_os_str;
15 use format_bytes::{write_bytes, DisplayBytes};
15 use format_bytes::{write_bytes, DisplayBytes};
16 use std::env;
16 use std::env;
17 use std::path::{Path, PathBuf};
17 use std::path::{Path, PathBuf};
@@ -134,8 +134,7 b' impl Config {'
134 layer.add(
134 layer.add(
135 section.to_owned(),
135 section.to_owned(),
136 key.to_owned(),
136 key.to_owned(),
137 // `value` is not a path but this works for any `OsStr`:
137 get_bytes_from_os_str(value),
138 get_bytes_from_path(value),
139 None,
138 None,
140 );
139 );
141 self.layers.push(layer)
140 self.layers.push(layer)
@@ -17,6 +17,7 b' use crate::utils::{'
17 use lazy_static::lazy_static;
17 use lazy_static::lazy_static;
18 use same_file::is_same_file;
18 use same_file::is_same_file;
19 use std::borrow::{Cow, ToOwned};
19 use std::borrow::{Cow, ToOwned};
20 use std::ffi::OsStr;
20 use std::fs::Metadata;
21 use std::fs::Metadata;
21 use std::iter::FusedIterator;
22 use std::iter::FusedIterator;
22 use std::ops::Deref;
23 use std::ops::Deref;
@@ -40,8 +41,13 b' pub fn get_path_from_bytes(bytes: &[u8])'
40 // that's why Vec<u8> is returned.
41 // that's why Vec<u8> is returned.
41 #[cfg(unix)]
42 #[cfg(unix)]
42 pub fn get_bytes_from_path(path: impl AsRef<Path>) -> Vec<u8> {
43 pub fn get_bytes_from_path(path: impl AsRef<Path>) -> Vec<u8> {
44 get_bytes_from_os_str(path.as_ref())
45 }
46
47 #[cfg(unix)]
48 pub fn get_bytes_from_os_str(str: impl AsRef<OsStr>) -> Vec<u8> {
43 use std::os::unix::ffi::OsStrExt;
49 use std::os::unix::ffi::OsStrExt;
44 path.as_ref().as_os_str().as_bytes().to_vec()
50 str.as_ref().as_bytes().to_vec()
45 }
51 }
46
52
47 /// An iterator over repository path yielding itself and its ancestors.
53 /// An iterator over repository path yielding itself and its ancestors.
@@ -70,8 +70,7 b' fn main_with_result(ui: &ui::Ui) -> Resu'
70 };
70 };
71
71
72 let config_args = values_of_global_arg("config")
72 let config_args = values_of_global_arg("config")
73 // `get_bytes_from_path` works for OsStr the same as for Path
73 .map(hg::utils::files::get_bytes_from_os_str);
74 .map(hg::utils::files::get_bytes_from_path);
75 let non_repo_config = &hg::config::Config::load(config_args)?;
74 let non_repo_config = &hg::config::Config::load(config_args)?;
76
75
77 let repo_path = value_of_global_arg("repository").map(Path::new);
76 let repo_path = value_of_global_arg("repository").map(Path::new);
General Comments 0
You need to be logged in to leave comments. Login now