mercurial/pure/parsers.py
changeset 47075 0d8ff1f4ab0c
parent 47055 d55b71393907
child 47078 d57386e5c80e
--- a/mercurial/pure/parsers.py	Thu Apr 15 12:08:34 2021 +0200
+++ b/mercurial/pure/parsers.py	Thu Apr 08 00:01:11 2021 +0200
@@ -127,10 +127,24 @@
             r = (offset_type(0, gettype(r[0])),) + r[1:]
         return r
 
+    def entry_binary(self, rev, header):
+        """return the raw binary string representing a revision"""
+        entry = self[rev]
+        p = revlog_constants.INDEX_ENTRY_V1.pack(*entry)
+        if rev == 0:
+            v_fmt = revlog_constants.INDEX_HEADER
+            v_bin = v_fmt.pack(header)
+            p = v_bin + p[v_fmt.size :]
+        return p
+
 
 class IndexObject(BaseIndexObject):
     def __init__(self, data):
-        assert len(data) % self.entry_size == 0
+        assert len(data) % self.entry_size == 0, (
+            len(data),
+            self.entry_size,
+            len(data) % self.entry_size,
+        )
         self._data = data
         self._lgt = len(data) // self.entry_size
         self._extra = []
@@ -272,6 +286,16 @@
             msg = b"cannot rewrite entries outside of this transaction"
             raise KeyError(msg)
 
+    def entry_binary(self, rev, header):
+        """return the raw binary string representing a revision"""
+        entry = self[rev]
+        p = revlog_constants.INDEX_ENTRY_V2.pack(*entry)
+        if rev == 0:
+            v_fmt = revlog_constants.INDEX_HEADER
+            v_bin = v_fmt.pack(header)
+            p = v_bin + p[v_fmt.size :]
+        return p
+
 
 class IndexObject2(Index2Mixin, IndexObject):
     pass