# HG changeset patch # User Boris Feld # Date 2018-12-20 11:17:15 # Node ID cca12a31ede5be3489891c89d65c5e9ab9d1235c # Parent b373477948dff61c345f0add61f4696c898e95d7 revlog: add some direct testing of the slicing logic This test check slicing backed by an actual revlog. It will test the C version of slicing (if the test are run with the C extensions). diff --git a/tests/test-revlog-raw.py b/tests/test-revlog-raw.py --- a/tests/test-revlog-raw.py +++ b/tests/test-revlog-raw.py @@ -12,11 +12,16 @@ from mercurial import ( vfs, ) +from mercurial.revlogutils import ( + deltas, +) + # TESTTMP is optional. This makes it convenient to run without run-tests.py tvfs = vfs.vfs(encoding.environ.get(b'TESTTMP', b'/tmp')) # Enable generaldelta otherwise revlog won't use delta as expected by the test -tvfs.options = {b'generaldelta': True, b'revlogv1': True} +tvfs.options = {b'generaldelta': True, b'revlogv1': True, + b'sparse-revlog': True} # The test wants to control whether to use delta explicitly, based on # "storedeltachains". @@ -291,6 +296,37 @@ def checkrevlog(rlog, expected): abort('rev %d: corrupted %stext' % (rev, raw and 'raw' or '')) +slicingdata = [ + ([0, 1, 2, 3, 55, 56, 58, 59, 60], + [[0, 1], [2], [58], [59, 60]], + 10), + ([0, 1, 2, 3, 55, 56, 58, 59, 60], + [[0, 1], [2], [58], [59, 60]], + 10), + ([-1, 0, 1, 2, 3, 55, 56, 58, 59, 60], + [[-1, 0, 1], [2], [58], [59, 60]], + 10), +] + +def slicingtest(rlog): + oldmin = rlog._srmingapsize + try: + # the test revlog is small, we remove the floor under which we + # slicing is diregarded. + rlog._srmingapsize = 0 + for item in slicingdata: + chain, expected, target = item + result = deltas.slicechunk(rlog, chain, targetsize=target) + result = list(result) + if result != expected: + print('slicing differ:') + print(' chain: %s' % chain) + print(' target: %s' % target) + print(' expected: %s' % expected) + print(' result: %s' % result) + finally: + rlog._srmingapsize = oldmin + def maintest(): expected = rl = None with newtransaction() as tr: @@ -313,6 +349,8 @@ def maintest(): rl4 = lowlevelcopy(rl, tr) checkrevlog(rl4, expected) print('lowlevelcopy test passed') + slicingtest(rl) + print('slicing test passed') try: maintest() diff --git a/tests/test-revlog-raw.py.out b/tests/test-revlog-raw.py.out --- a/tests/test-revlog-raw.py.out +++ b/tests/test-revlog-raw.py.out @@ -2,3 +2,4 @@ local test passed addgroupcopy test passed clone test passed lowlevelcopy test passed +slicing test passed