equal
deleted
inserted
replaced
|
1 use crate::repo::Repo; |
1 use std::io; |
2 use std::io; |
2 use std::path::Path; |
|
3 |
3 |
4 #[derive(Debug)] |
4 #[derive(Debug)] |
5 pub enum RequirementsError { |
5 pub enum RequirementsError { |
6 // TODO: include a path? |
6 // TODO: include a path? |
7 Io(io::Error), |
7 Io(io::Error), |
31 } |
31 } |
32 }) |
32 }) |
33 .collect() |
33 .collect() |
34 } |
34 } |
35 |
35 |
36 pub fn load(repo_root: &Path) -> Result<Vec<String>, RequirementsError> { |
36 pub fn load(repo: &Repo) -> Result<Vec<String>, RequirementsError> { |
37 match std::fs::read(repo_root.join(".hg").join("requires")) { |
37 match repo.hg_vfs().read("requires") { |
38 Ok(bytes) => parse(&bytes).map_err(|()| RequirementsError::Corrupted), |
38 Ok(bytes) => parse(&bytes).map_err(|()| RequirementsError::Corrupted), |
39 |
39 |
40 // Treat a missing file the same as an empty file. |
40 // Treat a missing file the same as an empty file. |
41 // From `mercurial/localrepo.py`: |
41 // From `mercurial/localrepo.py`: |
42 // > requires file contains a newline-delimited list of |
42 // > requires file contains a newline-delimited list of |
50 |
50 |
51 Err(error) => Err(RequirementsError::Io(error))?, |
51 Err(error) => Err(RequirementsError::Io(error))?, |
52 } |
52 } |
53 } |
53 } |
54 |
54 |
55 pub fn check(repo_root: &Path) -> Result<(), RequirementsError> { |
55 pub fn check(repo: &Repo) -> Result<(), RequirementsError> { |
56 for feature in load(repo_root)? { |
56 for feature in load(repo)? { |
57 if !SUPPORTED.contains(&&*feature) { |
57 if !SUPPORTED.contains(&&*feature) { |
58 return Err(RequirementsError::Unsupported { feature }); |
58 return Err(RequirementsError::Unsupported { feature }); |
59 } |
59 } |
60 } |
60 } |
61 Ok(()) |
61 Ok(()) |