Show More
@@ -1,167 +1,178 b'' | |||
|
1 | 1 | # This test verifies the conformance of various classes to various |
|
2 | 2 | # storage interfaces. |
|
3 | 3 | |
|
4 | 4 | import silenttestrunner |
|
5 | 5 | |
|
6 | 6 | from mercurial import ( |
|
7 | 7 | error, |
|
8 | 8 | filelog, |
|
9 | 9 | revlog, |
|
10 | 10 | transaction, |
|
11 | 11 | ui as uimod, |
|
12 | 12 | vfs as vfsmod, |
|
13 | 13 | ) |
|
14 | 14 | |
|
15 | 15 | from mercurial.testing import storage as storagetesting |
|
16 | 16 | |
|
17 | 17 | try: |
|
18 | from mercurial import rustext | |
|
19 | ||
|
20 | rustext.__name__ | |
|
21 | # Does not pass with pure Rust index | |
|
22 | import sys | |
|
23 | ||
|
24 | sys.exit(80) | |
|
25 | except ImportError: | |
|
26 | pass | |
|
27 | ||
|
28 | try: | |
|
18 | 29 | from hgext import sqlitestore |
|
19 | 30 | except ImportError: |
|
20 | 31 | sqlitestore = None |
|
21 | 32 | |
|
22 | 33 | try: |
|
23 | 34 | import sqlite3 |
|
24 | 35 | |
|
25 | 36 | if sqlite3.sqlite_version_info < (3, 8, 3): |
|
26 | 37 | # WITH clause not supported |
|
27 | 38 | sqlitestore = None |
|
28 | 39 | except ImportError: |
|
29 | 40 | pass |
|
30 | 41 | |
|
31 | 42 | try: |
|
32 | 43 | from mercurial import zstd |
|
33 | 44 | |
|
34 | 45 | zstd.__version__ |
|
35 | 46 | except ImportError: |
|
36 | 47 | zstd = None |
|
37 | 48 | |
|
38 | 49 | STATE = { |
|
39 | 50 | 'lastindex': 0, |
|
40 | 51 | 'ui': uimod.ui(), |
|
41 | 52 | 'vfs': vfsmod.vfs(b'.', realpath=True), |
|
42 | 53 | } |
|
43 | 54 | |
|
44 | 55 | |
|
45 | 56 | def makefilefn(self): |
|
46 | 57 | """Factory for filelog instances.""" |
|
47 | 58 | fl = filelog.filelog(STATE['vfs'], b'filelog-%d' % STATE['lastindex']) |
|
48 | 59 | STATE['lastindex'] += 1 |
|
49 | 60 | return fl |
|
50 | 61 | |
|
51 | 62 | |
|
52 | 63 | def maketransaction(self): |
|
53 | 64 | vfsmap = {b'plain': STATE['vfs'], b'store': STATE['vfs']} |
|
54 | 65 | |
|
55 | 66 | return transaction.transaction( |
|
56 | 67 | STATE['ui'].warn, STATE['vfs'], vfsmap, b'journal', b'undo' |
|
57 | 68 | ) |
|
58 | 69 | |
|
59 | 70 | |
|
60 | 71 | def addrawrevision( |
|
61 | 72 | self, |
|
62 | 73 | fl, |
|
63 | 74 | tr, |
|
64 | 75 | node, |
|
65 | 76 | p1, |
|
66 | 77 | p2, |
|
67 | 78 | linkrev, |
|
68 | 79 | rawtext=None, |
|
69 | 80 | delta=None, |
|
70 | 81 | censored=False, |
|
71 | 82 | ellipsis=False, |
|
72 | 83 | extstored=False, |
|
73 | 84 | ): |
|
74 | 85 | flags = 0 |
|
75 | 86 | |
|
76 | 87 | if censored: |
|
77 | 88 | flags |= revlog.REVIDX_ISCENSORED |
|
78 | 89 | if ellipsis: |
|
79 | 90 | flags |= revlog.REVIDX_ELLIPSIS |
|
80 | 91 | if extstored: |
|
81 | 92 | flags |= revlog.REVIDX_EXTSTORED |
|
82 | 93 | |
|
83 | 94 | if rawtext is not None: |
|
84 | 95 | fl._revlog.addrawrevision(rawtext, tr, linkrev, p1, p2, node, flags) |
|
85 | 96 | elif delta is not None: |
|
86 | 97 | fl._revlog.addrawrevision( |
|
87 | 98 | rawtext, tr, linkrev, p1, p2, node, flags, cachedelta=delta |
|
88 | 99 | ) |
|
89 | 100 | else: |
|
90 | 101 | raise error.Abort('must supply rawtext or delta arguments') |
|
91 | 102 | |
|
92 | 103 | # We may insert bad data. Clear caches to prevent e.g. cache hits to |
|
93 | 104 | # bypass hash verification. |
|
94 | 105 | fl._revlog.clearcaches() |
|
95 | 106 | |
|
96 | 107 | |
|
97 | 108 | # Assigning module-level attributes that inherit from unittest.TestCase |
|
98 | 109 | # is all that is needed to register tests. |
|
99 | 110 | filelogindextests = storagetesting.makeifileindextests( |
|
100 | 111 | makefilefn, maketransaction, addrawrevision |
|
101 | 112 | ) |
|
102 | 113 | filelogdatatests = storagetesting.makeifiledatatests( |
|
103 | 114 | makefilefn, maketransaction, addrawrevision |
|
104 | 115 | ) |
|
105 | 116 | filelogmutationtests = storagetesting.makeifilemutationtests( |
|
106 | 117 | makefilefn, maketransaction, addrawrevision |
|
107 | 118 | ) |
|
108 | 119 | |
|
109 | 120 | |
|
110 | 121 | def makesqlitefile(self): |
|
111 | 122 | path = STATE['vfs'].join(b'db-%d.db' % STATE['lastindex']) |
|
112 | 123 | STATE['lastindex'] += 1 |
|
113 | 124 | |
|
114 | 125 | db = sqlitestore.makedb(path) |
|
115 | 126 | |
|
116 | 127 | compression = b'zstd' if zstd else b'zlib' |
|
117 | 128 | |
|
118 | 129 | return sqlitestore.sqlitefilestore(db, b'dummy-path', compression) |
|
119 | 130 | |
|
120 | 131 | |
|
121 | 132 | def addrawrevisionsqlite( |
|
122 | 133 | self, |
|
123 | 134 | fl, |
|
124 | 135 | tr, |
|
125 | 136 | node, |
|
126 | 137 | p1, |
|
127 | 138 | p2, |
|
128 | 139 | linkrev, |
|
129 | 140 | rawtext=None, |
|
130 | 141 | delta=None, |
|
131 | 142 | censored=False, |
|
132 | 143 | ellipsis=False, |
|
133 | 144 | extstored=False, |
|
134 | 145 | ): |
|
135 | 146 | flags = 0 |
|
136 | 147 | |
|
137 | 148 | if censored: |
|
138 | 149 | flags |= sqlitestore.FLAG_CENSORED |
|
139 | 150 | |
|
140 | 151 | if ellipsis | extstored: |
|
141 | 152 | raise error.Abort( |
|
142 | 153 | b'support for ellipsis and extstored flags not ' b'supported' |
|
143 | 154 | ) |
|
144 | 155 | |
|
145 | 156 | if rawtext is not None: |
|
146 | 157 | fl._addrawrevision(node, rawtext, tr, linkrev, p1, p2, flags=flags) |
|
147 | 158 | elif delta is not None: |
|
148 | 159 | fl._addrawrevision( |
|
149 | 160 | node, rawtext, tr, linkrev, p1, p2, storedelta=delta, flags=flags |
|
150 | 161 | ) |
|
151 | 162 | else: |
|
152 | 163 | raise error.Abort(b'must supply rawtext or delta arguments') |
|
153 | 164 | |
|
154 | 165 | |
|
155 | 166 | if sqlitestore is not None: |
|
156 | 167 | sqlitefileindextests = storagetesting.makeifileindextests( |
|
157 | 168 | makesqlitefile, maketransaction, addrawrevisionsqlite |
|
158 | 169 | ) |
|
159 | 170 | sqlitefiledatatests = storagetesting.makeifiledatatests( |
|
160 | 171 | makesqlitefile, maketransaction, addrawrevisionsqlite |
|
161 | 172 | ) |
|
162 | 173 | sqlitefilemutationtests = storagetesting.makeifilemutationtests( |
|
163 | 174 | makesqlitefile, maketransaction, addrawrevisionsqlite |
|
164 | 175 | ) |
|
165 | 176 | |
|
166 | 177 | if __name__ == '__main__': |
|
167 | 178 | silenttestrunner.main(__name__) |
General Comments 0
You need to be logged in to leave comments.
Login now