annotate tests/test-revlog-raw.py @ 49673:e33776297d1f

test-revlog-raw: drop the overwrite of dead code The revlog class no longer have a _isgooddeltainfo method for a long time. So overwriting it does not get us anything. The test have been wrapping the right code since then anyway.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 07 Nov 2022 18:06:17 -0500
parents 642e31cb55f0
children efbbc2f9121e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
1 # test revlog interaction about raw data (flagprocessor)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
2
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
3
41087
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
4 import collections
41035
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
5 import hashlib
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
6 import sys
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
7
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
8 from mercurial import (
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
9 encoding,
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
10 revlog,
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
11 transaction,
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
12 vfs,
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
13 )
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
14
41034
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
15 from mercurial.revlogutils import (
47072
4c041c71ec01 revlog: introduce an explicit tracking of what the revlog is about
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
16 constants,
41034
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
17 deltas,
42732
6d61be152c55 flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41365
diff changeset
18 flagutil,
41034
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
19 )
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
20
47214
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
21
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
22 class _NoTransaction:
47214
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
23 """transaction like object to update the nodemap outside a transaction"""
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
24
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
25 def __init__(self):
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
26 self._postclose = {}
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
27
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
28 def addpostclose(self, callback_id, callback_func):
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
29 self._postclose[callback_id] = callback_func
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
30
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
31 def registertmp(self, *args, **kwargs):
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
32 pass
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
33
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
34 def addbackup(self, *args, **kwargs):
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
35 pass
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
36
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
37 def add(self, *args, **kwargs):
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
38 pass
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
39
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
40 def addabort(self, *args, **kwargs):
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
41 pass
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
42
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
43 def _report(self, *args):
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
44 pass
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
45
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
46
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
47 # TESTTMP is optional. This makes it convenient to run without run-tests.py
37896
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 36744
diff changeset
48 tvfs = vfs.vfs(encoding.environ.get(b'TESTTMP', b'/tmp'))
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
49
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
50 # Enable generaldelta otherwise revlog won't use delta as expected by the test
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
51 tvfs.options = {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
52 b'generaldelta': True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
53 b'revlogv1': True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
54 b'sparse-revlog': True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
55 }
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
56
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
57
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
58 def abort(msg):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
59 print('abort: %s' % msg)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
60 # Return 0 so run-tests.py could compare the output.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
61 sys.exit()
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
62
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
63
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
64 # Register a revlog processor for flag EXTSTORED.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
65 #
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
66 # It simply prepends a fixed header, and replaces '1' to 'i'. So it has
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
67 # insertion and replacement, and may be interesting to test revlog's line-based
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
68 # deltas.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
69 _extheader = b'E\n'
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
70
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
71
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
72 def readprocessor(self, rawtext):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
73 # True: the returned text could be used to verify hash
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
74 text = rawtext[len(_extheader) :].replace(b'i', b'1')
46709
3d740058b467 sidedata: move to new sidedata storage in revlogv2
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46113
diff changeset
75 return text, True
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
76
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
77
46709
3d740058b467 sidedata: move to new sidedata storage in revlogv2
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46113
diff changeset
78 def writeprocessor(self, text):
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
79 # False: the returned rawtext shouldn't be used to verify hash
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
80 rawtext = _extheader + text.replace(b'1', b'i')
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
81 return rawtext, False
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
82
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
83
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
84 def rawprocessor(self, rawtext):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
85 # False: do not verify hash. Only the content returned by "readprocessor"
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
86 # can be used to verify hash.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
87 return False
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
88
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
89
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
90 flagutil.addflagprocessor(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
91 revlog.REVIDX_EXTSTORED, (readprocessor, writeprocessor, rawprocessor)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
92 )
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
93
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
94 # Utilities about reading and appending revlog
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
95
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
96
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
97 def newtransaction():
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
98 # A transaction is required to write revlogs
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
99 report = lambda msg: None
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
100 return transaction.transaction(report, tvfs, {'plain': tvfs}, b'journal')
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
101
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
102
47150
8d3c2f9d4af7 revlog: use a "radix" to address revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47149
diff changeset
103 def newrevlog(name=b'_testrevlog', recreate=False):
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
104 if recreate:
47150
8d3c2f9d4af7 revlog: use a "radix" to address revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47149
diff changeset
105 tvfs.tryunlink(name + b'.i')
8d3c2f9d4af7 revlog: use a "radix" to address revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47149
diff changeset
106 target = (constants.KIND_OTHER, b'test')
8d3c2f9d4af7 revlog: use a "radix" to address revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47149
diff changeset
107 rlog = revlog.revlog(tvfs, target=target, radix=name)
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
108 return rlog
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
109
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
110
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
111 def appendrev(rlog, text, tr, isext=False, isdelta=True):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44452
diff changeset
112 """Append a revision. If isext is True, set the EXTSTORED flag so flag
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
113 processor will be used (and rawtext is different from text). If isdelta is
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
114 True, force the revision to be a delta, otherwise it's full text.
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44452
diff changeset
115 """
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
116 nextrev = len(rlog)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
117 p1 = rlog.node(nextrev - 1)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46711
diff changeset
118 p2 = rlog.nullid
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
119 if isext:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
120 flags = revlog.REVIDX_EXTSTORED
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
121 else:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
122 flags = revlog.REVIDX_DEFAULT_FLAGS
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
123 # Change storedeltachains temporarily, to override revlog's delta decision
39232
0a5b20c107a6 repository: remove storedeltachains from ifilestorage
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37896
diff changeset
124 rlog._storedeltachains = isdelta
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
125 try:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
126 rlog.addrevision(text, tr, nextrev, p1, p2, flags=flags)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
127 return nextrev
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
128 except Exception as ex:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
129 abort('rev %d: failed to append: %s' % (nextrev, ex))
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
130 finally:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
131 # Restore storedeltachains. It is always True, see revlog.__init__
39232
0a5b20c107a6 repository: remove storedeltachains from ifilestorage
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37896
diff changeset
132 rlog._storedeltachains = True
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
133
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
134
47150
8d3c2f9d4af7 revlog: use a "radix" to address revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47149
diff changeset
135 def addgroupcopy(rlog, tr, destname=b'_destrevlog', optimaldelta=True):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44452
diff changeset
136 """Copy revlog to destname using revlog.addgroup. Return the copied revlog.
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
137
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
138 This emulates push or pull. They use changegroup. Changegroup requires
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
139 repo to work. We don't have a repo, so a dummy changegroup is used.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
140
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
141 If optimaldelta is True, use optimized delta parent, so the destination
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
142 revlog could probably reuse it. Otherwise it builds sub-optimal delta, and
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
143 the destination revlog needs more work to use it.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
144
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
145 This exercises some revlog.addgroup (and revlog._addrevision(text=None))
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
146 code path, which is not covered by "appendrev" alone.
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44452
diff changeset
147 """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
148
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
149 class dummychangegroup:
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
150 @staticmethod
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
151 def deltachunk(pnode):
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46711
diff changeset
152 pnode = pnode or rlog.nullid
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
153 parentrev = rlog.rev(pnode)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
154 r = parentrev + 1
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
155 if r >= len(rlog):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
156 return {}
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
157 if optimaldelta:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
158 deltaparent = parentrev
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
159 else:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
160 # suboptimal deltaparent
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
161 deltaparent = min(0, parentrev)
36744
33275ab5e837 revlog: do not use delta for lfs revisions
Jun Wu <quark@fb.com>
parents: 35638
diff changeset
162 if not rlog.candelta(deltaparent, r):
33275ab5e837 revlog: do not use delta for lfs revisions
Jun Wu <quark@fb.com>
parents: 35638
diff changeset
163 deltaparent = -1
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
164 return {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
165 b'node': rlog.node(r),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
166 b'p1': pnode,
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46711
diff changeset
167 b'p2': rlog.nullid,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
168 b'cs': rlog.node(rlog.linkrev(r)),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
169 b'flags': rlog.flags(r),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
170 b'deltabase': rlog.node(deltaparent),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
171 b'delta': rlog.revdiff(deltaparent, r),
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46709
diff changeset
172 b'sidedata': rlog.sidedata(r),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
173 }
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
174
34291
1db9abf407c5 revlog: add revmap back to revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34148
diff changeset
175 def deltaiter(self):
34148
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 33625
diff changeset
176 chain = None
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 33625
diff changeset
177 for chunkdata in iter(lambda: self.deltachunk(chain), {}):
37896
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 36744
diff changeset
178 node = chunkdata[b'node']
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 36744
diff changeset
179 p1 = chunkdata[b'p1']
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 36744
diff changeset
180 p2 = chunkdata[b'p2']
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 36744
diff changeset
181 cs = chunkdata[b'cs']
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 36744
diff changeset
182 deltabase = chunkdata[b'deltabase']
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 36744
diff changeset
183 delta = chunkdata[b'delta']
03a09579c854 tests: port test-revlog-raw.py to Python 3
Augie Fackler <augie@google.com>
parents: 36744
diff changeset
184 flags = chunkdata[b'flags']
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46709
diff changeset
185 sidedata = chunkdata[b'sidedata']
34148
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 33625
diff changeset
186
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 33625
diff changeset
187 chain = node
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 33625
diff changeset
188
46711
a41565bef69f changegroup: add v4 changegroup for revlog v2 exchange
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46709
diff changeset
189 yield (node, p1, p2, cs, deltabase, delta, flags, sidedata)
34148
c8b6ed51386b changegroup: remove changegroup dependency from revlog.addgroup
Durham Goode <durham@fb.com>
parents: 33625
diff changeset
190
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
191 def linkmap(lnode):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
192 return rlog.rev(lnode)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
193
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
194 dlog = newrevlog(destname, recreate=True)
34291
1db9abf407c5 revlog: add revmap back to revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34148
diff changeset
195 dummydeltas = dummychangegroup().deltaiter()
1db9abf407c5 revlog: add revmap back to revlog.addgroup
Durham Goode <durham@fb.com>
parents: 34148
diff changeset
196 dlog.addgroup(dummydeltas, linkmap, tr)
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
197 return dlog
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
198
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
199
47150
8d3c2f9d4af7 revlog: use a "radix" to address revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47149
diff changeset
200 def lowlevelcopy(rlog, tr, destname=b'_destrevlog'):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44452
diff changeset
201 """Like addgroupcopy, but use the low level revlog._addrevision directly.
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
202
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
203 It exercises some code paths that are hard to reach easily otherwise.
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44452
diff changeset
204 """
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
205 dlog = newrevlog(destname, recreate=True)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
206 for r in rlog:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
207 p1 = rlog.node(r - 1)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46711
diff changeset
208 p2 = rlog.nullid
36744
33275ab5e837 revlog: do not use delta for lfs revisions
Jun Wu <quark@fb.com>
parents: 35638
diff changeset
209 if r == 0 or (rlog.flags(r) & revlog.REVIDX_EXTSTORED):
42777
740450677221 rawdata: update callers in test-revlog-raw
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42732
diff changeset
210 text = rlog.rawdata(r)
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
211 cachedelta = None
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
212 else:
36744
33275ab5e837 revlog: do not use delta for lfs revisions
Jun Wu <quark@fb.com>
parents: 35638
diff changeset
213 # deltaparent cannot have EXTSTORED flag.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
214 deltaparent = max(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
215 [-1]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
216 + [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
217 p
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
218 for p in range(r)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
219 if rlog.flags(p) & revlog.REVIDX_EXTSTORED == 0
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
220 ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
221 )
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
222 text = None
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
223 cachedelta = (deltaparent, rlog.revdiff(deltaparent, r))
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
224 flags = rlog.flags(r)
47214
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
225 with dlog._writing(_NoTransaction()):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
226 dlog._addrevision(
47214
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
227 rlog.node(r),
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
228 text,
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
229 tr,
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
230 r,
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
231 p1,
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
232 p2,
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
233 flags,
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47150
diff changeset
234 cachedelta,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
235 )
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
236 return dlog
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
237
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
238
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
239 # Utilities to generate revisions for testing
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
240
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
241
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
242 def genbits(n):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44452
diff changeset
243 """Given a number n, generate (2 ** (n * 2) + 1) numbers in range(2 ** n).
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
244 i.e. the generated numbers have a width of n bits.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
245
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
246 The combination of two adjacent numbers will cover all possible cases.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
247 That is to say, given any x, y where both x, and y are in range(2 ** n),
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
248 there is an x followed immediately by y in the generated sequence.
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44452
diff changeset
249 """
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
250 m = 2 ** n
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
251
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
252 # Gray Code. See https://en.wikipedia.org/wiki/Gray_code
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
253 gray = lambda x: x ^ (x >> 1)
44452
9d2b2df2c2ba cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
254 reversegray = {gray(i): i for i in range(m)}
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
255
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
256 # Generate (n * 2) bit gray code, yield lower n bits as X, and look for
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
257 # the next unused gray code where higher n bits equal to X.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
258
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
259 # For gray codes whose higher bits are X, a[X] of them have been used.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
260 a = [0] * m
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
261
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
262 # Iterate from 0.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
263 x = 0
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
264 yield x
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
265 for i in range(m * m):
31763
8a0c47982ade test-revlog-raw: fix "genbits" implementation
Jun Wu <quark@fb.com>
parents: 31748
diff changeset
266 x = reversegray[x]
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
267 y = gray(a[x] + x * m) & (m - 1)
31763
8a0c47982ade test-revlog-raw: fix "genbits" implementation
Jun Wu <quark@fb.com>
parents: 31748
diff changeset
268 assert a[x] < m
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
269 a[x] += 1
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
270 x = y
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
271 yield x
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
272
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
273
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
274 def gentext(rev):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
275 '''Given a revision number, generate dummy text'''
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
276 return b''.join(b'%d\n' % j for j in range(-1, rev % 5))
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
277
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
278
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
279 def writecases(rlog, tr):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44452
diff changeset
280 """Write some revisions interested to the test.
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
281
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
282 The test is interested in 3 properties of a revision:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
283
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
284 - Is it a delta or a full text? (isdelta)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
285 This is to catch some delta application issues.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
286 - Does it have a flag of EXTSTORED? (isext)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
287 This is to catch some flag processor issues. Especially when
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
288 interacted with revlog deltas.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
289 - Is its text empty? (isempty)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
290 This is less important. It is intended to try to catch some careless
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
291 checks like "if text" instead of "if text is None". Note: if flag
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
292 processor is involved, raw text may be not empty.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
293
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
294 Write 65 revisions. So that all combinations of the above flags for
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
295 adjacent revisions are covered. That is to say,
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
296
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
297 len(set(
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
298 (r.delta, r.ext, r.empty, (r+1).delta, (r+1).ext, (r+1).empty)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
299 for r in range(len(rlog) - 1)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
300 )) is 64.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
301
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
302 Where "r.delta", "r.ext", and "r.empty" are booleans matching properties
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
303 mentioned above.
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
304
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
305 Return expected [(text, rawtext)].
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44452
diff changeset
306 """
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
307 result = []
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
308 for i, x in enumerate(genbits(3)):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
309 isdelta, isext, isempty = bool(x & 1), bool(x & 2), bool(x & 4)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
310 if isempty:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
311 text = b''
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
312 else:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
313 text = gentext(i)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
314 rev = appendrev(rlog, text, tr, isext=isext, isdelta=isdelta)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
315
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
316 # Verify text, rawtext, and rawsize
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
317 if isext:
46709
3d740058b467 sidedata: move to new sidedata storage in revlogv2
Rapha?l Gom?s <rgomes@octobus.net>
parents: 46113
diff changeset
318 rawtext = writeprocessor(None, text)[0]
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
319 else:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
320 rawtext = text
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
321 if rlog.rawsize(rev) != len(rawtext):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
322 abort('rev %d: wrong rawsize' % rev)
48529
c514936d92b4 revlog: remove deprecated APIs
Rapha?l Gom?s <rgomes@octobus.net>
parents: 47214
diff changeset
323 if rlog.revision(rev) != text:
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
324 abort('rev %d: wrong text' % rev)
42777
740450677221 rawdata: update callers in test-revlog-raw
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42732
diff changeset
325 if rlog.rawdata(rev) != rawtext:
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
326 abort('rev %d: wrong rawtext' % rev)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
327 result.append((text, rawtext))
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
328
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
329 # Verify flags like isdelta, isext work as expected
36744
33275ab5e837 revlog: do not use delta for lfs revisions
Jun Wu <quark@fb.com>
parents: 35638
diff changeset
330 # isdelta can be overridden to False if this or p1 has isext set
33275ab5e837 revlog: do not use delta for lfs revisions
Jun Wu <quark@fb.com>
parents: 35638
diff changeset
331 if bool(rlog.deltaparent(rev) > -1) and not isdelta:
33275ab5e837 revlog: do not use delta for lfs revisions
Jun Wu <quark@fb.com>
parents: 35638
diff changeset
332 abort('rev %d: isdelta is unexpected' % rev)
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
333 if bool(rlog.flags(rev)) != isext:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
334 abort('rev %d: isext is ineffective' % rev)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
335 return result
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
336
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
337
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
338 # Main test and checking
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
339
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
340
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
341 def checkrevlog(rlog, expected):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
342 '''Check if revlog has expected contents. expected is [(text, rawtext)]'''
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
343 # Test using different access orders. This could expose some issues
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
344 # depending on revlog caching (see revlog._cache).
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
345 for r0 in range(len(rlog) - 1):
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
346 r1 = r0 + 1
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
347 for revorder in [[r0, r1], [r1, r0]]:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
348 for raworder in [[True], [False], [True, False], [False, True]]:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
349 nlog = newrevlog()
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
350 for rev in revorder:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
351 for raw in raworder:
42777
740450677221 rawdata: update callers in test-revlog-raw
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42732
diff changeset
352 if raw:
740450677221 rawdata: update callers in test-revlog-raw
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42732
diff changeset
353 t = nlog.rawdata(rev)
740450677221 rawdata: update callers in test-revlog-raw
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42732
diff changeset
354 else:
740450677221 rawdata: update callers in test-revlog-raw
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42732
diff changeset
355 t = nlog.revision(rev)
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
356 if t != expected[rev][int(raw)]:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
357 abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
358 'rev %d: corrupted %stext'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
359 % (rev, raw and 'raw' or '')
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
360 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
361
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
362
41034
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
363 slicingdata = [
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
364 ([0, 1, 2, 3, 55, 56, 58, 59, 60], [[0, 1], [2], [58], [59, 60]], 10),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
365 ([0, 1, 2, 3, 55, 56, 58, 59, 60], [[0, 1], [2], [58], [59, 60]], 10),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
366 (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
367 [-1, 0, 1, 2, 3, 55, 56, 58, 59, 60],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
368 [[-1, 0, 1], [2], [58], [59, 60]],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
369 10,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
370 ),
41034
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
371 ]
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
372
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
373
41034
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
374 def slicingtest(rlog):
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
375 oldmin = rlog._srmingapsize
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
376 try:
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
377 # the test revlog is small, we remove the floor under which we
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
378 # slicing is diregarded.
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
379 rlog._srmingapsize = 0
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
380 for item in slicingdata:
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
381 chain, expected, target = item
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
382 result = deltas.slicechunk(rlog, chain, targetsize=target)
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
383 result = list(result)
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
384 if result != expected:
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
385 print('slicing differ:')
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
386 print(' chain: %s' % chain)
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
387 print(' target: %s' % target)
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
388 print(' expected: %s' % expected)
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
389 print(' result: %s' % result)
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
390 finally:
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
391 rlog._srmingapsize = oldmin
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
392
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
393
41035
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
394 def md5sum(s):
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
395 return hashlib.md5(s).digest()
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
396
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
397
41035
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
398 def _maketext(*coord):
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
399 """create piece of text according to range of integers
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
400
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
401 The test returned use a md5sum of the integer to make it less
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
402 compressible"""
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
403 pieces = []
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
404 for start, size in coord:
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
405 num = range(start, start + size)
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
406 p = [md5sum(b'%d' % r) for r in num]
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
407 pieces.append(b'\n'.join(p))
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
408 return b'\n'.join(pieces) + b'\n'
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
409
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
410
41035
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
411 data = [
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
412 _maketext((0, 120), (456, 60)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
413 _maketext((0, 120), (345, 60)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
414 _maketext((0, 120), (734, 60)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
415 _maketext((0, 120), (734, 60), (923, 45)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
416 _maketext((0, 120), (734, 60), (234, 45)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
417 _maketext((0, 120), (734, 60), (564, 45)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
418 _maketext((0, 120), (734, 60), (361, 45)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
419 _maketext((0, 120), (734, 60), (489, 45)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
420 _maketext((0, 120), (123, 60)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
421 _maketext((0, 120), (145, 60)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
422 _maketext((0, 120), (104, 60)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
423 _maketext((0, 120), (430, 60)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
424 _maketext((0, 120), (430, 60), (923, 45)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
425 _maketext((0, 120), (430, 60), (234, 45)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
426 _maketext((0, 120), (430, 60), (564, 45)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
427 _maketext((0, 120), (430, 60), (361, 45)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
428 _maketext((0, 120), (430, 60), (489, 45)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
429 _maketext((0, 120), (249, 60)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
430 _maketext((0, 120), (832, 60)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
431 _maketext((0, 120), (891, 60)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
432 _maketext((0, 120), (543, 60)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
433 _maketext((0, 120), (120, 60)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
434 _maketext((0, 120), (60, 60), (768, 30)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
435 _maketext((0, 120), (60, 60), (260, 30)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
436 _maketext((0, 120), (60, 60), (450, 30)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
437 _maketext((0, 120), (60, 60), (361, 30)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
438 _maketext((0, 120), (60, 60), (886, 30)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
439 _maketext((0, 120), (60, 60), (116, 30)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
440 _maketext((0, 120), (60, 60), (567, 30), (629, 40)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
441 _maketext((0, 120), (60, 60), (569, 30), (745, 40)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
442 _maketext((0, 120), (60, 60), (777, 30), (700, 40)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
443 _maketext((0, 120), (60, 60), (618, 30), (398, 40), (158, 10)),
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
444 ]
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
445
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
446
41035
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
447 def makesnapshot(tr):
47150
8d3c2f9d4af7 revlog: use a "radix" to address revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47149
diff changeset
448 rl = newrevlog(name=b'_snaprevlog3', recreate=True)
41035
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
449 for i in data:
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
450 appendrev(rl, i, tr)
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
451 return rl
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
452
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
453
41035
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
454 snapshots = [-1, 0, 6, 8, 11, 17, 19, 21, 25, 30]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
455
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
456
41035
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
457 def issnapshottest(rlog):
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
458 result = []
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
459 if rlog.issnapshot(-1):
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
460 result.append(-1)
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
461 for rev in rlog:
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
462 if rlog.issnapshot(rev):
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
463 result.append(rev)
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
464 if snapshots != result:
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
465 print('snapshot differ:')
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
466 print(' expected: %s' % snapshots)
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
467 print(' got: %s' % result)
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
468
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
469
41087
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
470 snapshotmapall = {0: [6, 8, 11, 17, 19, 25], 8: [21], -1: [0, 30]}
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
471 snapshotmap15 = {0: [17, 19, 25], 8: [21], -1: [30]}
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
472
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
473
41087
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
474 def findsnapshottest(rlog):
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
475 resultall = collections.defaultdict(list)
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
476 deltas._findsnapshots(rlog, resultall, 0)
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
477 resultall = dict(resultall.items())
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
478 if resultall != snapshotmapall:
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
479 print('snapshot map differ:')
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
480 print(' expected: %s' % snapshotmapall)
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
481 print(' got: %s' % resultall)
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
482 result15 = collections.defaultdict(list)
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
483 deltas._findsnapshots(rlog, result15, 15)
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
484 result15 = dict(result15.items())
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
485 if result15 != snapshotmap15:
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
486 print('snapshot map differ:')
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
487 print(' expected: %s' % snapshotmap15)
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
488 print(' got: %s' % result15)
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
489
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
490
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
491 def maintest():
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
492 with newtransaction() as tr:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
493 rl = newrevlog(recreate=True)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
494 expected = writecases(rl, tr)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
495 checkrevlog(rl, expected)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
496 print('local test passed')
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
497 # Copy via revlog.addgroup
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
498 rl1 = addgroupcopy(rl, tr)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
499 checkrevlog(rl1, expected)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
500 rl2 = addgroupcopy(rl, tr, optimaldelta=False)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
501 checkrevlog(rl2, expected)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
502 print('addgroupcopy test passed')
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
503 # Copy via revlog.clone
47150
8d3c2f9d4af7 revlog: use a "radix" to address revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47149
diff changeset
504 rl3 = newrevlog(name=b'_destrevlog3', recreate=True)
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
505 rl.clone(tr, rl3)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
506 checkrevlog(rl3, expected)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
507 print('clone test passed')
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
508 # Copy via low-level revlog._addrevision
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
509 rl4 = lowlevelcopy(rl, tr)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
510 checkrevlog(rl4, expected)
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
511 print('lowlevelcopy test passed')
41034
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
512 slicingtest(rl)
cca12a31ede5 revlog: add some direct testing of the slicing logic
Boris Feld <boris.feld@octobus.net>
parents: 39232
diff changeset
513 print('slicing test passed')
41035
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
514 rl5 = makesnapshot(tr)
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
515 issnapshottest(rl5)
15f78383d3c8 revlog: add an explicit test for `issnapshot`
Boris Feld <boris.feld@octobus.net>
parents: 41034
diff changeset
516 print('issnapshot test passed')
41087
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
517 findsnapshottest(rl5)
797a416a91bd revlog: add test case for _findsnapshots
Boris Feld <boris.feld@octobus.net>
parents: 41035
diff changeset
518 print('findsnapshot test passed')
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
519
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42988
diff changeset
520
31748
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
521 try:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
522 maintest()
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
523 except Exception as ex:
985de02b5b9d revlog: add a stronger test for raw processing
Jun Wu <quark@fb.com>
parents:
diff changeset
524 abort('crashed: %s' % ex)