comparison tests/test-parseindex2.py @ 47249:130c9f7ed914

revlog: add a "data compression mode" entry in the index tuple That will make it possible to keep track of compression information in the revlog index, opening the way to more efficient revision restoration (in native code, but the python usage is already defeating performance work). We start with adding a new entry to the index tuple, using a value matching the current behavior. We will introduce storage and other value in later changesets. Differential Revision: https://phab.mercurial-scm.org/D10646
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 03 May 2021 18:19:16 +0200
parents 47ffc754989a
children 2b69555e4875
comparison
equal deleted inserted replaced
47248:013c645dd28c 47249:130c9f7ed914
18 sha1nodeconstants, 18 sha1nodeconstants,
19 ) 19 )
20 from mercurial import ( 20 from mercurial import (
21 policy, 21 policy,
22 pycompat, 22 pycompat,
23 )
24 from mercurial.revlogutils import (
25 constants,
23 ) 26 )
24 27
25 parsers = policy.importmod('parsers') 28 parsers = policy.importmod('parsers')
26 29
27 # original python implementation 30 # original python implementation
47 append = index.append 50 append = index.append
48 if inline: 51 if inline:
49 cache = (0, data) 52 cache = (0, data)
50 while off <= l: 53 while off <= l:
51 e = struct.unpack(indexformatng, data[off : off + s]) 54 e = struct.unpack(indexformatng, data[off : off + s])
52 e = e + (0, 0) 55 e = e + (0, 0, constants.COMP_MODE_INLINE)
53 nodemap[e[7]] = n 56 nodemap[e[7]] = n
54 append(e) 57 append(e)
55 n += 1 58 n += 1
56 if e[1] < 0: 59 if e[1] < 0:
57 break 60 break
58 off += e[1] + s 61 off += e[1] + s
59 else: 62 else:
60 while off <= l: 63 while off <= l:
61 e = struct.unpack(indexformatng, data[off : off + s]) 64 e = struct.unpack(indexformatng, data[off : off + s])
62 e = e + (0, 0) 65 e = e + (0, 0, constants.COMP_MODE_INLINE)
63 nodemap[e[7]] = n 66 nodemap[e[7]] = n
64 append(e) 67 append(e)
65 n += 1 68 n += 1
66 off += s 69 off += s
67 70
240 except TypeError: 243 except TypeError:
241 # pure version doesn't support this 244 # pure version doesn't support this
242 break 245 break
243 246
244 def testminusone(self): 247 def testminusone(self):
245 want = (0, 0, 0, -1, -1, -1, -1, sha1nodeconstants.nullid, 0, 0) 248 want = (
249 0,
250 0,
251 0,
252 -1,
253 -1,
254 -1,
255 -1,
256 sha1nodeconstants.nullid,
257 0,
258 0,
259 constants.COMP_MODE_INLINE,
260 )
246 index, junk = parsers.parse_index2(data_inlined, True) 261 index, junk = parsers.parse_index2(data_inlined, True)
247 got = index[-1] 262 got = index[-1]
248 self.assertEqual(want, got) # inline data 263 self.assertEqual(want, got) # inline data
249 264
250 index, junk = parsers.parse_index2(data_non_inlined, False) 265 index, junk = parsers.parse_index2(data_non_inlined, False)
262 277
263 def appendrev(p1, p2=nullrev): 278 def appendrev(p1, p2=nullrev):
264 # node won't matter for this test, let's just make sure 279 # node won't matter for this test, let's just make sure
265 # they don't collide. Other data don't matter either. 280 # they don't collide. Other data don't matter either.
266 node = hexrev(p1) + hexrev(p2) + b'.' * 12 281 node = hexrev(p1) + hexrev(p2) + b'.' * 12
267 index.append((0, 0, 12, 1, 34, p1, p2, node, 0, 0)) 282 e = (
283 0,
284 0,
285 12,
286 1,
287 34,
288 p1,
289 p2,
290 node,
291 0,
292 0,
293 constants.COMP_MODE_INLINE,
294 )
295 index.append(e)
268 296
269 appendrev(4) 297 appendrev(4)
270 appendrev(5) 298 appendrev(5)
271 appendrev(6) 299 appendrev(6)
272 self.assertEqual(len(index), 7) 300 self.assertEqual(len(index), 7)