# HG changeset patch # User Simon Sapin # Date 1631635631 -7200 # Node ID 6c653d9d41b851ac0997ac537e1b51a3ef69cf1b # Parent 681851d6409b1adb0c78e4b728d7a71076489c04 rust: Make private the `index` field of the `Revlog` struct To replace the previous use of this field from another module, add a `node_from_rev` method. This is the same method that already existed on `Changelog`. Differential Revision: https://phab.mercurial-scm.org/D11414 diff -r 681851d6409b -r 6c653d9d41b8 rust/hg-core/src/revlog/changelog.rs --- a/rust/hg-core/src/revlog/changelog.rs Mon Jul 26 10:26:45 2021 +0200 +++ b/rust/hg-core/src/revlog/changelog.rs Tue Sep 14 18:07:11 2021 +0200 @@ -36,7 +36,7 @@ } pub fn node_from_rev(&self, rev: Revision) -> Option<&Node> { - Some(self.revlog.index.get_entry(rev)?.hash()) + self.revlog.node_from_rev(rev) } } diff -r 681851d6409b -r 6c653d9d41b8 rust/hg-core/src/revlog/revlog.rs --- a/rust/hg-core/src/revlog/revlog.rs Mon Jul 26 10:26:45 2021 +0200 +++ b/rust/hg-core/src/revlog/revlog.rs Tue Sep 14 18:07:11 2021 +0200 @@ -18,7 +18,7 @@ use crate::errors::HgError; use crate::repo::Repo; use crate::revlog::Revision; -use crate::NULL_REVISION; +use crate::{Node, NULL_REVISION}; #[derive(derive_more::From)] pub enum RevlogError { @@ -51,7 +51,7 @@ /// When index and data are not interleaved: bytes of the revlog index. /// When index and data are interleaved: bytes of the revlog index and /// data. - pub(crate) index: Index, + index: Index, /// When index and data are not interleaved: bytes of the revlog data data_bytes: Option + Send>>, /// When present on disk: the persistent nodemap for this revlog @@ -119,6 +119,11 @@ self.index.is_empty() } + /// Returns the node ID for the given revision number, if it exists in this revlog + pub fn node_from_rev(&self, rev: Revision) -> Option<&Node> { + Some(self.index.get_entry(rev)?.hash()) + } + /// Return the full data associated to a node. #[timed] pub fn get_node_rev(