diff rust/hg-core/src/revlog/mod.rs @ 52343:393ad2685fb4

rust: make RevlogError AmbiguousPrefix case contain the actual prefix This brings the work started in `652149ed64f0` to its logical conclusion and makes the RevlogError self-sufficient so it can be directly converted to CommandError, without an extra rev text annotation. Without this change, it's confusing that the extra annotation is ignored in most-but-not-all cases.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Tue, 26 Nov 2024 15:45:11 +0000
parents 645d247d4c75
children df7fb698f7a8
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/mod.rs	Mon Dec 02 09:45:56 2024 -0500
+++ b/rust/hg-core/src/revlog/mod.rs	Tue Nov 26 15:45:11 2024 +0000
@@ -208,15 +208,15 @@
     /// Working directory is not supported
     WDirUnsupported,
     /// Found more than one entry whose ID match the requested prefix
-    AmbiguousPrefix,
+    AmbiguousPrefix(String),
     #[from]
     Other(HgError),
 }
 
-impl From<NodeMapError> for RevlogError {
-    fn from(error: NodeMapError) -> Self {
+impl From<(NodeMapError, String)> for RevlogError {
+    fn from((error, rev): (NodeMapError, String)) -> Self {
         match error {
-            NodeMapError::MultipleResults => RevlogError::AmbiguousPrefix,
+            NodeMapError::MultipleResults => RevlogError::AmbiguousPrefix(rev),
             NodeMapError::RevisionNotInIndex(rev) => RevlogError::corrupted(
                 format!("nodemap point to revision {} not in index", rev),
             ),
@@ -359,7 +359,8 @@
     ) -> Result<Revision, RevlogError> {
         if let Some(nodemap) = &self.nodemap {
             nodemap
-                .find_bin(self.index(), node)?
+                .find_bin(self.index(), node)
+                .map_err(|err| (err, format!("{:x}", node)))?
                 .ok_or(RevlogError::InvalidRevision(format!("{:x}", node)))
         } else {
             self.index().rev_from_node_no_persistent_nodemap(node)
@@ -887,7 +888,7 @@
             .rev_from_node(NodePrefix::from_hex("00").unwrap())
             .expect_err("Expected to give AmbiguousPrefix error")
         {
-            RevlogError::AmbiguousPrefix => (),
+            RevlogError::AmbiguousPrefix(_) => (),
             e => {
                 panic!("Got another error than AmbiguousPrefix: {:?}", e);
             }