diff rust/rhg/src/commands/debugrequirements.rs @ 45924:a2eda1ff22aa

requirements: move loading to hg-core and add parsing No functional change, checking comes later. Differential Revision: https://phab.mercurial-scm.org/D9398
author Simon Sapin <simon-commits@exyr.org>
date Tue, 24 Nov 2020 17:49:16 +0100
parents ead435aa5294
children dca9cb99971c
line wrap: on
line diff
--- a/rust/rhg/src/commands/debugrequirements.rs	Tue Nov 24 15:11:58 2020 +0100
+++ b/rust/rhg/src/commands/debugrequirements.rs	Tue Nov 24 17:49:16 2020 +0100
@@ -1,7 +1,8 @@
 use crate::commands::Command;
-use crate::error::{CommandError, CommandErrorKind};
+use crate::error::CommandError;
 use crate::ui::Ui;
 use hg::operations::FindRoot;
+use hg::requirements;
 
 pub const HELP_TEXT: &str = "
 Print the current repo requirements.
@@ -18,23 +19,12 @@
 impl Command for DebugRequirementsCommand {
     fn run(&self, ui: &Ui) -> Result<(), CommandError> {
         let root = FindRoot::new().run()?;
-        let requires = root.join(".hg").join("requires");
-        let requirements = match std::fs::read(requires) {
-            Ok(bytes) => bytes,
-
-            // Treat a missing file the same as an empty file.
-            // From `mercurial/localrepo.py`:
-            // > requires file contains a newline-delimited list of
-            // > features/capabilities the opener (us) must have in order to use
-            // > the repository. This file was introduced in Mercurial 0.9.2,
-            // > which means very old repositories may not have one. We assume
-            // > a missing file translates to no requirements.
-            Err(error) if error.kind() == std::io::ErrorKind::NotFound => Vec::new(),
-
-            Err(error) => Err(CommandErrorKind::FileError(error))?,
-        };
-
-        ui.write_stdout(&requirements)?;
+        let mut output = String::new();
+        for req in requirements::load(&root)? {
+            output.push_str(&req);
+            output.push('\n');
+        }
+        ui.write_stdout(output.as_bytes())?;
         Ok(())
     }
 }