diff rust/hg-core/src/requirements.rs @ 46167:8a4914397d02

rust: introduce Repo and Vfs types for filesystem abstraction This is similar to the corresponding Python classes. Repo represents a repository and knows the path to the `.hg` directory, the `store` directory, and the working directory. Separating these will enable supporting the share extension. A Vfs is created from a Repo for one of these three directories. It has filesystem access APIs that take a relative std::path::Path as a parameter. Differential Revision: https://phab.mercurial-scm.org/D9596
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 14 Dec 2020 16:33:15 +0100
parents 9eb07ab3f2d4
children 02d3bb972121
line wrap: on
line diff
--- a/rust/hg-core/src/requirements.rs	Sat Dec 19 15:56:54 2020 +0100
+++ b/rust/hg-core/src/requirements.rs	Mon Dec 14 16:33:15 2020 +0100
@@ -1,5 +1,5 @@
+use crate::repo::Repo;
 use std::io;
-use std::path::Path;
 
 #[derive(Debug)]
 pub enum RequirementsError {
@@ -33,8 +33,8 @@
         .collect()
 }
 
-pub fn load(repo_root: &Path) -> Result<Vec<String>, RequirementsError> {
-    match std::fs::read(repo_root.join(".hg").join("requires")) {
+pub fn load(repo: &Repo) -> Result<Vec<String>, RequirementsError> {
+    match repo.hg_vfs().read("requires") {
         Ok(bytes) => parse(&bytes).map_err(|()| RequirementsError::Corrupted),
 
         // Treat a missing file the same as an empty file.
@@ -52,8 +52,8 @@
     }
 }
 
-pub fn check(repo_root: &Path) -> Result<(), RequirementsError> {
-    for feature in load(repo_root)? {
+pub fn check(repo: &Repo) -> Result<(), RequirementsError> {
+    for feature in load(repo)? {
         if !SUPPORTED.contains(&&*feature) {
             return Err(RequirementsError::Unsupported { feature });
         }