D9012: hg-core: add `Revlog.get_node_rev`

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

D9012: hg-core: add `Revlog.get_node_rev`

marmoute (Pierre-Yves David)
acezar created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Find the revision of a node given its full hash.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9012

AFFECTED FILES
  rust/hg-core/src/revlog/revlog.rs

CHANGE DETAILS

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
@@ -80,6 +80,25 @@
         })
     }
 
+    /// Return number of entries of the `Revlog`.
+    pub fn len(&self) -> usize {
+        self.index().len()
+    }
+
+    /// Return the full data associated to a node.
+    #[timed]
+    pub fn get_node_rev(&self, node: &[u8]) -> Result<Revision, RevlogError> {
+        let index = self.index();
+        for rev in (0..self.len() as Revision).rev() {
+            let index_entry =
+                index.get_entry(rev).ok_or_else(|| 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



To: acezar, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel