diff rust/hg-core/src/revlog/index.rs @ 51224:7434747343ab

rust-index: check that the entry bytes are the same in both indexes This is a temporary measure to show that both the Rust and C indexes are kept in sync. Comes with some related documentation precisions. For comparison of error cases, see `index_entry_binary()` in `revlog.c`.
author Rapha?l Gom?s <rgomes@octobus.net>
date Thu, 02 Nov 2023 11:16:13 +0100
parents 51cc12158f97
children 002b49905aac
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/index.rs	Sat Sep 30 16:15:56 2023 +0200
+++ b/rust/hg-core/src/revlog/index.rs	Thu Nov 02 11:16:13 2023 +0100
@@ -366,8 +366,11 @@
         self.len() == 0
     }
 
-    /// Return the index entry corresponding to the given revision if it
-    /// exists.
+    /// Return the index entry corresponding to the given revision or `None`
+    /// for [`NULL_REVISION`]
+    ///
+    /// The specified revision being of the checked type, it always exists
+    /// if it was validated by this index.
     pub fn get_entry(&self, rev: Revision) -> Option<IndexEntry> {
         if rev == NULL_REVISION {
             return None;
@@ -379,6 +382,21 @@
         })
     }
 
+    /// Return the binary content of the index entry for the given revision
+    ///
+    /// See [get_entry()](`Self::get_entry()`) for cases when `None` is
+    /// returned.
+    pub fn entry_binary(&self, rev: Revision) -> Option<&[u8]> {
+        self.get_entry(rev).map(|e| {
+            let bytes = e.as_bytes();
+            if rev.0 == 0 {
+                &bytes[4..]
+            } else {
+                bytes
+            }
+        })
+    }
+
     fn get_entry_inline(
         &self,
         rev: Revision,
@@ -543,6 +561,10 @@
     pub fn hash(&self) -> &'a Node {
         (&self.bytes[32..52]).try_into().unwrap()
     }
+
+    pub fn as_bytes(&self) -> &'a [u8] {
+        self.bytes
+    }
 }
 
 #[cfg(test)]