# HG changeset patch # User Martin von Zweigbergk # Date 2022-04-05 19:06:32 # Node ID 5d205e476057453e6ccd07088872b147a222e295 # Parent 95da3e99cbd888fcacbed9f8663e8e50c0589349 rust-revlog: add methods for getting parent revs and entries Differential Revision: https://phab.mercurial-scm.org/D12442 diff --git a/rust/hg-core/src/revlog/changelog.rs b/rust/hg-core/src/revlog/changelog.rs --- a/rust/hg-core/src/revlog/changelog.rs +++ b/rust/hg-core/src/revlog/changelog.rs @@ -1,6 +1,6 @@ use crate::errors::HgError; use crate::repo::Repo; -use crate::revlog::revlog::{Revlog, RevlogError}; +use crate::revlog::revlog::{Revlog, RevlogEntry, RevlogError}; use crate::revlog::Revision; use crate::revlog::{Node, NodePrefix}; use crate::utils::hg_path::HgPath; @@ -30,6 +30,14 @@ impl Changelog { self.data_for_rev(rev) } + /// Return the `RevlogEntry` of the given revision number. + pub fn entry_for_rev( + &self, + rev: Revision, + ) -> Result { + self.revlog.get_entry(rev) + } + /// Return the `ChangelogEntry` of the given revision number. pub fn data_for_rev( &self, @@ -51,6 +59,13 @@ impl Changelog { pub fn node_from_rev(&self, rev: Revision) -> Option<&Node> { self.revlog.node_from_rev(rev) } + + pub fn rev_from_node( + &self, + node: NodePrefix, + ) -> Result { + self.revlog.rev_from_node(node) + } } /// `Changelog` entry which knows how to interpret the `changelog` data bytes. diff --git a/rust/hg-core/src/revlog/revlog.rs b/rust/hg-core/src/revlog/revlog.rs --- a/rust/hg-core/src/revlog/revlog.rs +++ b/rust/hg-core/src/revlog/revlog.rs @@ -331,6 +331,10 @@ impl<'a> RevlogEntry<'a> { self.rev } + pub fn node(&self) -> &Node { + &self.hash + } + pub fn uncompressed_len(&self) -> Option { u32::try_from(self.uncompressed_len).ok() } @@ -339,6 +343,38 @@ impl<'a> RevlogEntry<'a> { self.p1 != NULL_REVISION } + pub fn p1_entry(&self) -> Result, RevlogError> { + if self.p1 == NULL_REVISION { + Ok(None) + } else { + Ok(Some(self.revlog.get_entry(self.p1)?)) + } + } + + pub fn p2_entry(&self) -> Result, RevlogError> { + if self.p2 == NULL_REVISION { + Ok(None) + } else { + Ok(Some(self.revlog.get_entry(self.p2)?)) + } + } + + pub fn p1(&self) -> Option { + if self.p1 == NULL_REVISION { + None + } else { + Some(self.p1) + } + } + + pub fn p2(&self) -> Option { + if self.p2 == NULL_REVISION { + None + } else { + Some(self.p2) + } + } + pub fn is_cencored(&self) -> bool { (self.flags & REVISION_FLAG_CENSORED) != 0 }