comparison 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
comparison
equal deleted inserted replaced
47141:ac72eee94035 47142:4292bed8da7c
51 # Size of a C unsigned long long int, platform independent 51 # Size of a C unsigned long long int, platform independent
52 big_int_size = struct.calcsize(b'>Q') 52 big_int_size = struct.calcsize(b'>Q')
53 # Size of a C long int, platform independent 53 # Size of a C long int, platform independent
54 int_size = struct.calcsize(b'>i') 54 int_size = struct.calcsize(b'>i')
55 # An empty index entry, used as a default value to be overridden, or nullrev 55 # An empty index entry, used as a default value to be overridden, or nullrev
56 null_item = (0, 0, 0, -1, -1, -1, -1, sha1nodeconstants.nullid) 56 null_item = (0, 0, 0, -1, -1, -1, -1, sha1nodeconstants.nullid, 0, 0)
57 57
58 @util.propertycache 58 @util.propertycache
59 def entry_size(self): 59 def entry_size(self):
60 return self.index_format.size 60 return self.index_format.size
61 61
120 if i >= self._lgt: 120 if i >= self._lgt:
121 data = self._extra[i - self._lgt] 121 data = self._extra[i - self._lgt]
122 else: 122 else:
123 index = self._calculate_index(i) 123 index = self._calculate_index(i)
124 data = self._data[index : index + self.entry_size] 124 data = self._data[index : index + self.entry_size]
125 r = self.index_format.unpack(data) 125 r = self._unpack_entry(data)
126 if self._lgt and i == 0: 126 if self._lgt and i == 0:
127 r = (offset_type(0, gettype(r[0])),) + r[1:] 127 r = (offset_type(0, gettype(r[0])),) + r[1:]
128 return r
129
130 def _unpack_entry(self, data):
131 r = self.index_format.unpack(data)
132 r = r + (0, 0)
128 return r 133 return r
129 134
130 def pack_header(self, header): 135 def pack_header(self, header):
131 """pack header information as binary""" 136 """pack header information as binary"""
132 v_fmt = revlog_constants.INDEX_HEADER 137 v_fmt = revlog_constants.INDEX_HEADER
133 return v_fmt.pack(header) 138 return v_fmt.pack(header)
134 139
135 def entry_binary(self, rev): 140 def entry_binary(self, rev):
136 """return the raw binary string representing a revision""" 141 """return the raw binary string representing a revision"""
137 entry = self[rev] 142 entry = self[rev]
138 p = revlog_constants.INDEX_ENTRY_V1.pack(*entry) 143 p = revlog_constants.INDEX_ENTRY_V1.pack(*entry[:8])
139 if rev == 0: 144 if rev == 0:
140 p = p[revlog_constants.INDEX_HEADER.size :] 145 p = p[revlog_constants.INDEX_HEADER.size :]
141 return p 146 return p
142 147
143 148
264 return cls(data, inline), (0, data) 269 return cls(data, inline), (0, data)
265 270
266 271
267 class Index2Mixin(object): 272 class Index2Mixin(object):
268 index_format = revlog_constants.INDEX_ENTRY_V2 273 index_format = revlog_constants.INDEX_ENTRY_V2
269 null_item = (0, 0, 0, -1, -1, -1, -1, sha1nodeconstants.nullid, 0, 0)
270 274
271 def replace_sidedata_info( 275 def replace_sidedata_info(
272 self, i, sidedata_offset, sidedata_length, offset_flags 276 self, i, sidedata_offset, sidedata_length, offset_flags
273 ): 277 ):
274 """ 278 """
289 new = offset_flags + old[8:64] + packed + old[64 + packed_size :] 293 new = offset_flags + old[8:64] + packed + old[64 + packed_size :]
290 self._extra[i - self._lgt] = new 294 self._extra[i - self._lgt] = new
291 else: 295 else:
292 msg = b"cannot rewrite entries outside of this transaction" 296 msg = b"cannot rewrite entries outside of this transaction"
293 raise KeyError(msg) 297 raise KeyError(msg)
298
299 def _unpack_entry(self, data):
300 return self.index_format.unpack(data)
294 301
295 def entry_binary(self, rev): 302 def entry_binary(self, rev):
296 """return the raw binary string representing a revision""" 303 """return the raw binary string representing a revision"""
297 entry = self[rev] 304 entry = self[rev]
298 p = revlog_constants.INDEX_ENTRY_V2.pack(*entry) 305 p = revlog_constants.INDEX_ENTRY_V2.pack(*entry)