changeset 46821:e8ae91b1a63d

rhg: raise wdir specific error for `hg debugdata` Helps remove the conditional in `test-debugcommands.t` for rhg. Differential Revision: https://phab.mercurial-scm.org/D10254
author Pulkit Goyal <7895pulkit@gmail.com>
date Tue, 23 Mar 2021 19:58:49 +0530
parents 821929d59e01
children c71e8d9e7f2a
files rust/hg-core/src/revlog.rs rust/hg-core/src/revlog/revlog.rs rust/hg-core/src/revset.rs rust/rhg/src/error.rs tests/test-debugcommands.t
diffstat 5 files changed, 14 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/revlog.rs	Sat Mar 20 02:03:57 2021 +0530
+++ b/rust/hg-core/src/revlog.rs	Tue Mar 23 19:58:49 2021 +0530
@@ -35,6 +35,9 @@
 #[allow(clippy::unreadable_literal)]
 pub const WORKING_DIRECTORY_REVISION: Revision = 0x7fffffff;
 
+pub const WORKING_DIRECTORY_HEX: &str =
+    "ffffffffffffffffffffffffffffffffffffffff";
+
 /// The simplest expression of what we need of Mercurial DAGs.
 pub trait Graph {
     /// Return the two parents of the given `Revision`.
--- a/rust/hg-core/src/revlog/revlog.rs	Sat Mar 20 02:03:57 2021 +0530
+++ b/rust/hg-core/src/revlog/revlog.rs	Tue Mar 23 19:58:49 2021 +0530
@@ -23,6 +23,8 @@
 #[derive(derive_more::From)]
 pub enum RevlogError {
     InvalidRevision,
+    /// Working directory is not supported
+    WDirUnsupported,
     /// Found more than one entry whose ID match the requested prefix
     AmbiguousPrefix,
     #[from]
--- a/rust/hg-core/src/revset.rs	Sat Mar 20 02:03:57 2021 +0530
+++ b/rust/hg-core/src/revset.rs	Tue Mar 23 19:58:49 2021 +0530
@@ -7,7 +7,8 @@
 use crate::revlog::changelog::Changelog;
 use crate::revlog::revlog::{Revlog, RevlogError};
 use crate::revlog::NodePrefix;
-use crate::revlog::{Revision, NULL_REVISION};
+use crate::revlog::{Revision, NULL_REVISION, WORKING_DIRECTORY_HEX};
+use crate::Node;
 
 /// Resolve a query string into a single revision.
 ///
@@ -51,6 +52,10 @@
         }
     }
     if let Ok(prefix) = NodePrefix::from_hex(input) {
+        if prefix.is_prefix_of(&Node::from_hex(WORKING_DIRECTORY_HEX).unwrap())
+        {
+            return Err(RevlogError::WDirUnsupported);
+        }
         return revlog.get_node_rev(prefix);
     }
     Err(RevlogError::InvalidRevision)
--- a/rust/rhg/src/error.rs	Sat Mar 20 02:03:57 2021 +0530
+++ b/rust/rhg/src/error.rs	Tue Mar 23 19:58:49 2021 +0530
@@ -157,6 +157,9 @@
 impl From<(RevlogError, &str)> for CommandError {
     fn from((err, rev): (RevlogError, &str)) -> CommandError {
         match err {
+            RevlogError::WDirUnsupported => CommandError::abort(
+                "abort: working directory revision cannot be specified",
+            ),
             RevlogError::InvalidRevision => CommandError::abort(format!(
                 "abort: invalid revision identifier: {}",
                 rev
--- a/tests/test-debugcommands.t	Sat Mar 20 02:03:57 2021 +0530
+++ b/tests/test-debugcommands.t	Tue Mar 23 19:58:49 2021 +0530
@@ -531,17 +531,9 @@
 
 Test WdirUnsupported exception
 
-#if no-rhg
   $ hg debugdata -c ffffffffffffffffffffffffffffffffffffffff
   abort: working directory revision cannot be specified
   [255]
-#else
-TODO: add rhg support for (at least parsing) the working directory pseudo-changeset
-  $ hg debugdata -c ffffffffffffffffffffffffffffffffffffffff
-  abort: working directory revision cannot be specified (missing-correct-output !)
-  abort: invalid revision identifier: ffffffffffffffffffffffffffffffffffffffff (known-bad-output !)
-  [255]
-#endif
 
 Test cache warming command