Skip to content
Snippets Groups Projects
Commit 4f11a67a12fb authored by Antoine Cezar's avatar Antoine Cezar
Browse files

hg-core: add `Revlog.get_node_rev`

Find the revision of a node given its full hash.

Differential Revision: https://phab.mercurial-scm.org/D9012
parent 89ac95bd4993
No related branches found
No related tags found
No related merge requests found
......@@ -79,6 +79,32 @@
})
}
/// Return number of entries of the `Revlog`.
pub fn len(&self) -> usize {
self.index().len()
}
/// Returns `true` if the `Revlog` has zero `entries`.
pub fn is_empty(&self) -> bool {
self.index().is_empty()
}
/// Return the full data associated to a node.
#[timed]
pub fn get_node_rev(&self, node: &[u8]) -> Result<Revision, RevlogError> {
let index = self.index();
// This is brute force. But it is fast enough for now.
// Optimization will come later.
for rev in (0..self.len() as Revision).rev() {
let index_entry =
index.get_entry(rev).ok_or(RevlogError::Corrupted)?;
if node == index_entry.hash() {
return Ok(rev);
}
}
Err(RevlogError::InvalidRevision)
}
/// Return the full data associated to a revision.
///
/// All entries required to build the final data out of deltas will be
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment