diff mercurial/pure/parsers.py @ 47142:4292bed8da7c

revlog: make the index always return the same tuple It is simpler to manage the diferrence in on disk format in the internal index code itself and lets the rest of the code always handle the same object. This will become even more important when the data we store will be entirely different (for example the changelog does not need the "linkrev" field. We start with item reading, we will deal with item writing in the next changesets. Differential Revision: https://phab.mercurial-scm.org/D10568
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 03 May 2021 12:21:15 +0200
parents 223b47235d1c
children 47ffc754989a
line wrap: on
line diff
--- a/mercurial/pure/parsers.py	Mon May 03 12:21:05 2021 +0200
+++ b/mercurial/pure/parsers.py	Mon May 03 12:21:15 2021 +0200
@@ -53,7 +53,7 @@
     # Size of a C long int, platform independent
     int_size = struct.calcsize(b'>i')
     # An empty index entry, used as a default value to be overridden, or nullrev
-    null_item = (0, 0, 0, -1, -1, -1, -1, sha1nodeconstants.nullid)
+    null_item = (0, 0, 0, -1, -1, -1, -1, sha1nodeconstants.nullid, 0, 0)
 
     @util.propertycache
     def entry_size(self):
@@ -122,11 +122,16 @@
         else:
             index = self._calculate_index(i)
             data = self._data[index : index + self.entry_size]
-        r = self.index_format.unpack(data)
+        r = self._unpack_entry(data)
         if self._lgt and i == 0:
             r = (offset_type(0, gettype(r[0])),) + r[1:]
         return r
 
+    def _unpack_entry(self, data):
+        r = self.index_format.unpack(data)
+        r = r + (0, 0)
+        return r
+
     def pack_header(self, header):
         """pack header information as binary"""
         v_fmt = revlog_constants.INDEX_HEADER
@@ -135,7 +140,7 @@
     def entry_binary(self, rev):
         """return the raw binary string representing a revision"""
         entry = self[rev]
-        p = revlog_constants.INDEX_ENTRY_V1.pack(*entry)
+        p = revlog_constants.INDEX_ENTRY_V1.pack(*entry[:8])
         if rev == 0:
             p = p[revlog_constants.INDEX_HEADER.size :]
         return p
@@ -266,7 +271,6 @@
 
 class Index2Mixin(object):
     index_format = revlog_constants.INDEX_ENTRY_V2
-    null_item = (0, 0, 0, -1, -1, -1, -1, sha1nodeconstants.nullid, 0, 0)
 
     def replace_sidedata_info(
         self, i, sidedata_offset, sidedata_length, offset_flags
@@ -292,6 +296,9 @@
             msg = b"cannot rewrite entries outside of this transaction"
             raise KeyError(msg)
 
+    def _unpack_entry(self, data):
+        return self.index_format.unpack(data)
+
     def entry_binary(self, rev):
         """return the raw binary string representing a revision"""
         entry = self[rev]