[Updated] D9399: rhg: exit with relevant code for unsupported requirements

SimonSapin phabricator at mercurial-scm.org
Fri Nov 27 11:34:41 UTC 2020


Closed by commit rHG2ad2745e0be9: rhg: exit with relevant code for unsupported requirements (authored by SimonSapin).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D9399?vs=23671&id=23712

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D9399/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D9399

AFFECTED FILES
  rust/hg-core/src/requirements.rs
  rust/rhg/src/commands/cat.rs
  rust/rhg/src/commands/files.rs
  rust/rhg/src/error.rs
  tests/test-rhg.t

CHANGE DETAILS

diff --git a/tests/test-rhg.t b/tests/test-rhg.t
--- a/tests/test-rhg.t
+++ b/tests/test-rhg.t
@@ -124,3 +124,19 @@
   revlogv1
   sparserevlog
   store
+
+  $ echo indoor-pool >> .hg/requires
+  $ rhg files
+  [252]
+
+  $ rhg cat -r 1 copy_of_original
+  [252]
+
+  $ rhg debugrequirements
+  dotencode
+  fncache
+  generaldelta
+  revlogv1
+  sparserevlog
+  store
+  indoor-pool
diff --git a/rust/rhg/src/error.rs b/rust/rhg/src/error.rs
--- a/rust/rhg/src/error.rs
+++ b/rust/rhg/src/error.rs
@@ -30,6 +30,9 @@
         match self {
             CommandErrorKind::RootNotFound(_) => exitcode::ABORT,
             CommandErrorKind::CurrentDirNotFound(_) => exitcode::ABORT,
+            CommandErrorKind::RequirementsError(
+                RequirementsError::Unsupported { .. },
+            ) => exitcode::UNIMPLEMENTED_COMMAND,
             CommandErrorKind::RequirementsError(_) => exitcode::ABORT,
             CommandErrorKind::StdoutError => exitcode::ABORT,
             CommandErrorKind::StderrError => exitcode::ABORT,
diff --git a/rust/rhg/src/commands/files.rs b/rust/rhg/src/commands/files.rs
--- a/rust/rhg/src/commands/files.rs
+++ b/rust/rhg/src/commands/files.rs
@@ -11,6 +11,7 @@
     ListRevTrackedFiles, ListRevTrackedFilesError,
     ListRevTrackedFilesErrorKind,
 };
+use hg::requirements;
 use hg::utils::files::{get_bytes_from_path, relativize_path};
 use hg::utils::hg_path::{HgPath, HgPathBuf};
 use std::path::PathBuf;
@@ -57,6 +58,7 @@
 impl<'a> Command for FilesCommand<'a> {
     fn run(&self, ui: &Ui) -> Result<(), CommandError> {
         let root = FindRoot::new().run()?;
+        requirements::check(&root)?;
         if let Some(rev) = self.rev {
             let mut operation = ListRevTrackedFiles::new(&root, rev)
                 .map_err(|e| map_rev_error(rev, e))?;
diff --git a/rust/rhg/src/commands/cat.rs b/rust/rhg/src/commands/cat.rs
--- a/rust/rhg/src/commands/cat.rs
+++ b/rust/rhg/src/commands/cat.rs
@@ -4,6 +4,7 @@
 use crate::ui::Ui;
 use hg::operations::FindRoot;
 use hg::operations::{CatRev, CatRevError, CatRevErrorKind};
+use hg::requirements;
 use hg::utils::hg_path::HgPathBuf;
 use micro_timer::timed;
 use std::convert::TryFrom;
@@ -32,6 +33,7 @@
     #[timed]
     fn run(&self, ui: &Ui) -> Result<(), CommandError> {
         let root = FindRoot::new().run()?;
+        requirements::check(&root)?;
         let cwd = std::env::current_dir()
             .or_else(|e| Err(CommandErrorKind::CurrentDirNotFound(e)))?;
 
diff --git a/rust/hg-core/src/requirements.rs b/rust/hg-core/src/requirements.rs
--- a/rust/hg-core/src/requirements.rs
+++ b/rust/hg-core/src/requirements.rs
@@ -51,3 +51,22 @@
         Err(error) => Err(RequirementsError::Io(error))?,
     }
 }
+
+pub fn check(repo_root: &Path) -> Result<(), RequirementsError> {
+    for feature in load(repo_root)? {
+        if !SUPPORTED.contains(&&*feature) {
+            return Err(RequirementsError::Unsupported { feature })
+        }
+    }
+    Ok(())
+}
+
+// TODO: set this to actually-supported features
+const SUPPORTED: &[&str] = &[
+    "dotencode",
+    "fncache",
+    "generaldelta",
+    "revlogv1",
+    "sparserevlog",
+    "store",
+];



To: SimonSapin, #hg-reviewers, pulkit
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20201127/e2d5e64c/attachment-0002.html>


More information about the Mercurial-patches mailing list