diff rust/hg-cpython/src/revlog.rs @ 46500:18a261b11b20

rust: Remove hex parsing from the nodemap Separating concerns simplifies error types. Differential Revision: https://phab.mercurial-scm.org/D9864
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 25 Jan 2021 18:25:26 +0100
parents 645ee7225fab
children 3c9208702db3
line wrap: on
line diff
--- a/rust/hg-cpython/src/revlog.rs	Mon Jan 25 11:48:47 2021 +0100
+++ b/rust/hg-cpython/src/revlog.rs	Mon Jan 25 18:25:26 2021 +0100
@@ -17,7 +17,7 @@
 };
 use hg::{
     nodemap::{Block, NodeMapError, NodeTree},
-    revlog::{nodemap::NodeMap, RevlogIndex},
+    revlog::{nodemap::NodeMap, NodePrefix, RevlogIndex},
     Revision,
 };
 use std::cell::RefCell;
@@ -107,7 +107,9 @@
             String::from_utf8_lossy(node.data(py)).to_string()
         };
 
-        nt.find_hex(idx, &node_as_string)
+        let prefix = NodePrefix::from_hex(&node_as_string).map_err(|_| PyErr::new::<ValueError, _>(py, "Invalid node or prefix"))?;
+
+        nt.find_bin(idx, prefix)
             // TODO make an inner API returning the node directly
             .map(|opt| opt.map(
                 |rev| PyBytes::new(py, idx.node(rev).unwrap().as_bytes())))
@@ -468,9 +470,6 @@
     match err {
         NodeMapError::MultipleResults => revlog_error(py),
         NodeMapError::RevisionNotInIndex(r) => rev_not_in_index(py, r),
-        NodeMapError::InvalidNodePrefix => {
-            PyErr::new::<ValueError, _>(py, "Invalid node or prefix")
-        }
     }
 }