diff rust/hg-core/src/revlog/mod.rs @ 52776:169ccd142ef8

rust: add methods that take checked revisions This continues the work done in a3fa37bdb7ecbad4cf31bc6e87545fd42058a93b, turning more methods into checked/unchecked pairs of methods.
author Mitchell Kember <mkember@janestreet.com>
date Thu, 16 Jan 2025 15:36:26 -0500
parents 8497cfb0d76c
children 2fb13c3f4496
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/mod.rs	Tue Jan 14 17:44:02 2025 -0500
+++ b/rust/hg-core/src/revlog/mod.rs	Thu Jan 16 15:36:26 2025 -0500
@@ -343,12 +343,19 @@
 
     /// Returns the node ID for the given revision number, if it exists in this
     /// revlog
-    pub fn node_from_rev(&self, rev: UncheckedRevision) -> Option<&Node> {
-        if rev == NULL_REVISION.into() {
-            return Some(&NULL_NODE);
+    pub fn node_from_rev(&self, rev: Revision) -> &Node {
+        match self.index().get_entry(rev) {
+            None => &NULL_NODE,
+            Some(entry) => entry.hash(),
         }
-        let rev = self.index().check_revision(rev)?;
-        Some(self.index().get_entry(rev)?.hash())
+    }
+
+    /// Like [`Self::node_from_rev`] but checks `rev` first.
+    pub fn node_from_unchecked_rev(
+        &self,
+        rev: UncheckedRevision,
+    ) -> Option<&Node> {
+        Some(self.node_from_rev(self.index().check_revision(rev)?))
     }
 
     /// Return the revision number for the given node ID, if it exists in this