Patchwork D7789: rust-revlog: a trait for the revlog index

login
register
mail settings
Submitter phabricator
Date Jan. 6, 2020, 7:25 p.m.
Message ID <differential-rev-PHID-DREV-ucrgxltl23uqhih2fuyf-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/44148/
State New
Headers show

Comments

phabricator - Jan. 6, 2020, 7:25 p.m.
gracinet created this revision.
Herald added subscribers: mercurial-devel, kevincox, durin42.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  As explained in the doc comment, this is the minimum needed
  for our immediate concern, which is to implement a nodemap
  in Rust.
  
  The trait will be later implemented in `hg-cpython` by the
  index Python object implemented in C, thanks to exposition
  of the corresponding functions as a capsule.
  
  The `None` return cases in `node()` match what the `index_node()`
  C function does.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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

CHANGE DETAILS




To: gracinet, #hg-reviewers
Cc: durin42, kevincox, mercurial-devel
phabricator - Jan. 18, 2020, 1:31 a.m.
martinvonz added a comment.


  > The None return cases in node() match what the index_node()
  > C function does.
  
  You mean the code on https://www.mercurial-scm.org/repo/hg/file/fdaa4233dc18/mercurial/cext/revlog.c#l388? Line 394 there returns nullid, so does that really match? Why not return the nullid when given nullrev as input?

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7789/new/

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

To: gracinet, #hg-reviewers
Cc: martinvonz, durin42, kevincox, mercurial-devel

Patch

diff --git a/rust/hg-core/src/revlog.rs b/rust/hg-core/src/revlog.rs
--- a/rust/hg-core/src/revlog.rs
+++ b/rust/hg-core/src/revlog.rs
@@ -40,3 +40,15 @@ 
     ParentOutOfRange(Revision),
     WorkingDirectoryUnsupported,
 }
+
+/// The Mercurial Revlog Index
+///
+/// This is currently limited to the minimal interface that is needed for
+/// the [`nodemap`](nodemap/index.html) module
+pub trait RevlogIndex {
+    /// Total number of Revisions referenced in this index
+    fn len(&self) -> usize;
+
+    /// Return the Node or `None` if rev is out of bounds or `NULL_REVISON`
+    fn node(&self, rev: Revision) -> Option<&Node>;
+}