Show More
@@ -14,7 +14,6 b' use crate::config::layer::{' | |||
|
14 | 14 | use std::path::PathBuf; |
|
15 | 15 | |
|
16 | 16 | use crate::repo::Repo; |
|
17 | use crate::utils::files::read_whole_file; | |
|
18 | 17 | |
|
19 | 18 | /// Holds the config values for the current repository |
|
20 | 19 | /// TODO update this docstring once we support more sources |
@@ -64,7 +63,7 b' impl Config {' | |||
|
64 | 63 | ConfigSource::AbsPath(c) => { |
|
65 | 64 | // TODO check if it should be trusted |
|
66 | 65 | // mercurial/ui.py:427 |
|
67 |
let data = match read |
|
|
66 | let data = match std::fs::read(&c) { | |
|
68 | 67 | Err(_) => continue, // same as the python code |
|
69 | 68 | Ok(data) => data, |
|
70 | 69 | }; |
@@ -8,9 +8,7 b'' | |||
|
8 | 8 | // GNU General Public License version 2 or any later version. |
|
9 | 9 | |
|
10 | 10 | use crate::errors::{HgError, IoResultExt}; |
|
11 | use crate::utils::files::{ | |
|
12 | get_bytes_from_path, get_path_from_bytes, read_whole_file, | |
|
13 | }; | |
|
11 | use crate::utils::files::{get_bytes_from_path, get_path_from_bytes}; | |
|
14 | 12 | use format_bytes::format_bytes; |
|
15 | 13 | use lazy_static::lazy_static; |
|
16 | 14 | use regex::bytes::Regex; |
@@ -244,10 +242,10 b' fn read_include(' | |||
|
244 | 242 | new_src: &Path, |
|
245 | 243 | ) -> (PathBuf, io::Result<Vec<u8>>) { |
|
246 | 244 | if new_src.is_absolute() { |
|
247 |
(new_src.to_path_buf(), read |
|
|
245 | (new_src.to_path_buf(), std::fs::read(&new_src)) | |
|
248 | 246 | } else { |
|
249 | 247 | let dir = old_src.parent().unwrap(); |
|
250 | 248 | let new_src = dir.join(&new_src); |
|
251 |
(new_src.to_owned(), read |
|
|
249 | (new_src.to_owned(), std::fs::read(&new_src)) | |
|
252 | 250 | } |
|
253 | 251 | } |
@@ -18,7 +18,6 b' use lazy_static::lazy_static;' | |||
|
18 | 18 | use same_file::is_same_file; |
|
19 | 19 | use std::borrow::{Cow, ToOwned}; |
|
20 | 20 | use std::fs::Metadata; |
|
21 | use std::io::Read; | |
|
22 | 21 | use std::iter::FusedIterator; |
|
23 | 22 | use std::ops::Deref; |
|
24 | 23 | use std::path::{Path, PathBuf}; |
@@ -309,17 +308,6 b' pub fn relativize_path(path: &HgPath, cw' | |||
|
309 | 308 | } |
|
310 | 309 | } |
|
311 | 310 | |
|
312 | /// Reads a file in one big chunk instead of doing multiple reads | |
|
313 | pub fn read_whole_file(filepath: &Path) -> std::io::Result<Vec<u8>> { | |
|
314 | let mut file = std::fs::File::open(filepath)?; | |
|
315 | let size = file.metadata()?.len(); | |
|
316 | ||
|
317 | let mut res = vec![0; size as usize]; | |
|
318 | file.read_exact(&mut res)?; | |
|
319 | ||
|
320 | Ok(res) | |
|
321 | } | |
|
322 | ||
|
323 | 311 | #[cfg(test)] |
|
324 | 312 | mod tests { |
|
325 | 313 | use super::*; |
General Comments 0
You need to be logged in to leave comments.
Login now