diff mercurial/pure/parsers.py @ 47037:d57386e5c80e

revlog: have an explicit "pack_header" method Having to pass the version header when retrieving the binary version of every single entry is a bit silly. So we extract that special logic in its own method. This also prepare the move to newer revlog format, not storing the header within an actual entry… Differential Revision: https://phab.mercurial-scm.org/D10510
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 01 Apr 2021 11:31:54 +0200
parents 0d8ff1f4ab0c
children 223b47235d1c
line wrap: on
line diff
--- a/mercurial/pure/parsers.py	Sat May 01 14:47:39 2021 +0200
+++ b/mercurial/pure/parsers.py	Thu Apr 01 11:31:54 2021 +0200
@@ -127,14 +127,17 @@
             r = (offset_type(0, gettype(r[0])),) + r[1:]
         return r
 
-    def entry_binary(self, rev, header):
+    def pack_header(self, header):
+        """pack header information as binary"""
+        v_fmt = revlog_constants.INDEX_HEADER
+        return v_fmt.pack(header)
+
+    def entry_binary(self, rev):
         """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 :]
+            p = p[revlog_constants.INDEX_HEADER.size :]
         return p
 
 
@@ -286,14 +289,12 @@
             msg = b"cannot rewrite entries outside of this transaction"
             raise KeyError(msg)
 
-    def entry_binary(self, rev, header):
+    def entry_binary(self, rev):
         """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 :]
+            p = p[revlog_constants.INDEX_HEADER.size :]
         return p