comparison tests/test-revlog-raw.py @ 47150:8d3c2f9d4af7

revlog: use a "radix" to address revlog Instead of pointing to the index directly and to derive the other file from that, we directly provide the radix and let the revlog determine the associated file path internally. This is more robust and will give us more flexibility for picking this file name in the future. Differential Revision: https://phab.mercurial-scm.org/D10576
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 03 May 2021 12:22:36 +0200
parents 396442cd7e6a
children 906a7bcaac86
comparison
equal deleted inserted replaced
47149:396442cd7e6a 47150:8d3c2f9d4af7
77 # A transaction is required to write revlogs 77 # A transaction is required to write revlogs
78 report = lambda msg: None 78 report = lambda msg: None
79 return transaction.transaction(report, tvfs, {'plain': tvfs}, b'journal') 79 return transaction.transaction(report, tvfs, {'plain': tvfs}, b'journal')
80 80
81 81
82 def newrevlog(name=b'_testrevlog.i', recreate=False): 82 def newrevlog(name=b'_testrevlog', recreate=False):
83 if recreate: 83 if recreate:
84 tvfs.tryunlink(name) 84 tvfs.tryunlink(name + b'.i')
85 rlog = revlog.revlog( 85 target = (constants.KIND_OTHER, b'test')
86 tvfs, target=(constants.KIND_OTHER, b'test'), indexfile=name 86 rlog = revlog.revlog(tvfs, target=target, radix=name)
87 )
88 return rlog 87 return rlog
89 88
90 89
91 def appendrev(rlog, text, tr, isext=False, isdelta=True): 90 def appendrev(rlog, text, tr, isext=False, isdelta=True):
92 """Append a revision. If isext is True, set the EXTSTORED flag so flag 91 """Append a revision. If isext is True, set the EXTSTORED flag so flag
110 finally: 109 finally:
111 # Restore storedeltachains. It is always True, see revlog.__init__ 110 # Restore storedeltachains. It is always True, see revlog.__init__
112 rlog._storedeltachains = True 111 rlog._storedeltachains = True
113 112
114 113
115 def addgroupcopy(rlog, tr, destname=b'_destrevlog.i', optimaldelta=True): 114 def addgroupcopy(rlog, tr, destname=b'_destrevlog', optimaldelta=True):
116 """Copy revlog to destname using revlog.addgroup. Return the copied revlog. 115 """Copy revlog to destname using revlog.addgroup. Return the copied revlog.
117 116
118 This emulates push or pull. They use changegroup. Changegroup requires 117 This emulates push or pull. They use changegroup. Changegroup requires
119 repo to work. We don't have a repo, so a dummy changegroup is used. 118 repo to work. We don't have a repo, so a dummy changegroup is used.
120 119
175 dummydeltas = dummychangegroup().deltaiter() 174 dummydeltas = dummychangegroup().deltaiter()
176 dlog.addgroup(dummydeltas, linkmap, tr) 175 dlog.addgroup(dummydeltas, linkmap, tr)
177 return dlog 176 return dlog
178 177
179 178
180 def lowlevelcopy(rlog, tr, destname=b'_destrevlog.i'): 179 def lowlevelcopy(rlog, tr, destname=b'_destrevlog'):
181 """Like addgroupcopy, but use the low level revlog._addrevision directly. 180 """Like addgroupcopy, but use the low level revlog._addrevision directly.
182 181
183 It exercises some code paths that are hard to reach easily otherwise. 182 It exercises some code paths that are hard to reach easily otherwise.
184 """ 183 """
185 dlog = newrevlog(destname, recreate=True) 184 dlog = newrevlog(destname, recreate=True)
425 _maketext((0, 120), (60, 60), (618, 30), (398, 40), (158, 10)), 424 _maketext((0, 120), (60, 60), (618, 30), (398, 40), (158, 10)),
426 ] 425 ]
427 426
428 427
429 def makesnapshot(tr): 428 def makesnapshot(tr):
430 rl = newrevlog(name=b'_snaprevlog3.i', recreate=True) 429 rl = newrevlog(name=b'_snaprevlog3', recreate=True)
431 for i in data: 430 for i in data:
432 appendrev(rl, i, tr) 431 appendrev(rl, i, tr)
433 return rl 432 return rl
434 433
435 434
481 checkrevlog(rl1, expected) 480 checkrevlog(rl1, expected)
482 rl2 = addgroupcopy(rl, tr, optimaldelta=False) 481 rl2 = addgroupcopy(rl, tr, optimaldelta=False)
483 checkrevlog(rl2, expected) 482 checkrevlog(rl2, expected)
484 print('addgroupcopy test passed') 483 print('addgroupcopy test passed')
485 # Copy via revlog.clone 484 # Copy via revlog.clone
486 rl3 = newrevlog(name=b'_destrevlog3.i', recreate=True) 485 rl3 = newrevlog(name=b'_destrevlog3', recreate=True)
487 rl.clone(tr, rl3) 486 rl.clone(tr, rl3)
488 checkrevlog(rl3, expected) 487 checkrevlog(rl3, expected)
489 print('clone test passed') 488 print('clone test passed')
490 # Copy via low-level revlog._addrevision 489 # Copy via low-level revlog._addrevision
491 rl4 = lowlevelcopy(rl, tr) 490 rl4 = lowlevelcopy(rl, tr)