Mercurial > hg
annotate tests/flagprocessorext.py @ 42914:08fce968d00b
doc: fix up confusing doc comment
Differential Revision: https://phab.mercurial-scm.org/D6829
author | Valentin Gatien-Baron <valentin.gatienbaron@gmail.com> |
---|---|
date | Sun, 08 Sep 2019 20:09:31 -0400 |
parents | 6d61be152c55 |
children | bd5858c28bbe |
rev | line source |
---|---|
30745 | 1 # coding=UTF-8 |
2 | |
3 from __future__ import absolute_import | |
4 | |
5 import base64 | |
6 import zlib | |
7 | |
8 from mercurial import ( | |
9 changegroup, | |
31832
77f746e5383a
test-flagprocessor: use changegroup3 in bundle2
Jun Wu <quark@fb.com>
parents:
30745
diff
changeset
|
10 exchange, |
30745 | 11 extensions, |
12 revlog, | |
13 util, | |
14 ) | |
42730
92ac6b1697a7
flagutil: move REVIDX_KNOWN_FLAGS source of truth in flagutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41413
diff
changeset
|
15 from mercurial.revlogutils import ( |
92ac6b1697a7
flagutil: move REVIDX_KNOWN_FLAGS source of truth in flagutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41413
diff
changeset
|
16 flagutil, |
92ac6b1697a7
flagutil: move REVIDX_KNOWN_FLAGS source of truth in flagutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41413
diff
changeset
|
17 ) |
30745 | 18 |
19 # Test only: These flags are defined here only in the context of testing the | |
20 # behavior of the flag processor. The canonical way to add flags is to get in | |
21 # touch with the community and make them known in revlog. | |
22 REVIDX_NOOP = (1 << 3) | |
23 REVIDX_BASE64 = (1 << 2) | |
24 REVIDX_GZIP = (1 << 1) | |
25 REVIDX_FAIL = 1 | |
26 | |
27 def validatehash(self, text): | |
28 return True | |
29 | |
30 def bypass(self, text): | |
31 return False | |
32 | |
33 def noopdonothing(self, text): | |
34 return (text, True) | |
35 | |
36 def b64encode(self, text): | |
37 return (base64.b64encode(text), False) | |
38 | |
39 def b64decode(self, text): | |
40 return (base64.b64decode(text), True) | |
41 | |
42 def gzipcompress(self, text): | |
43 return (zlib.compress(text), False) | |
44 | |
45 def gzipdecompress(self, text): | |
46 return (zlib.decompress(text), True) | |
47 | |
48 def supportedoutgoingversions(orig, repo): | |
49 versions = orig(repo) | |
36114
83246d6920f2
py3: use b'' for changegroup version literals
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35570
diff
changeset
|
50 versions.discard(b'01') |
83246d6920f2
py3: use b'' for changegroup version literals
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35570
diff
changeset
|
51 versions.discard(b'02') |
83246d6920f2
py3: use b'' for changegroup version literals
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35570
diff
changeset
|
52 versions.add(b'03') |
30745 | 53 return versions |
54 | |
55 def allsupportedversions(orig, ui): | |
56 versions = orig(ui) | |
36114
83246d6920f2
py3: use b'' for changegroup version literals
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35570
diff
changeset
|
57 versions.add(b'03') |
30745 | 58 return versions |
59 | |
37436
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
60 def makewrappedfile(obj): |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
61 class wrappedfile(obj.__class__): |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
62 def addrevision(self, text, transaction, link, p1, p2, |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
63 cachedelta=None, node=None, |
42730
92ac6b1697a7
flagutil: move REVIDX_KNOWN_FLAGS source of truth in flagutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41413
diff
changeset
|
64 flags=flagutil.REVIDX_DEFAULT_FLAGS): |
37436
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
65 if b'[NOOP]' in text: |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
66 flags |= REVIDX_NOOP |
30745 | 67 |
37436
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
68 if b'[BASE64]' in text: |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
69 flags |= REVIDX_BASE64 |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
70 |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
71 if b'[GZIP]' in text: |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
72 flags |= REVIDX_GZIP |
30745 | 73 |
37436
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
74 # This addrevision wrapper is meant to add a flag we will not have |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
75 # transforms registered for, ensuring we handle this error case. |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
76 if b'[FAIL]' in text: |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
77 flags |= REVIDX_FAIL |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
78 |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
79 return super(wrappedfile, self).addrevision(text, transaction, link, |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
80 p1, p2, |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
81 cachedelta=cachedelta, |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
82 node=node, |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
83 flags=flags) |
30745 | 84 |
37436
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
85 obj.__class__ = wrappedfile |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
86 |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
87 def reposetup(ui, repo): |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
88 class wrappingflagprocessorrepo(repo.__class__): |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
89 def file(self, f): |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
90 orig = super(wrappingflagprocessorrepo, self).file(f) |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
91 makewrappedfile(orig) |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
92 return orig |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
93 |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
94 repo.__class__ = wrappingflagprocessorrepo |
30745 | 95 |
96 def extsetup(ui): | |
97 # Enable changegroup3 for flags to be sent over the wire | |
98 wrapfunction = extensions.wrapfunction | |
99 wrapfunction(changegroup, | |
100 'supportedoutgoingversions', | |
101 supportedoutgoingversions) | |
102 wrapfunction(changegroup, | |
103 'allsupportedversions', | |
104 allsupportedversions) | |
105 | |
106 # Teach revlog about our test flags | |
107 flags = [REVIDX_NOOP, REVIDX_BASE64, REVIDX_GZIP, REVIDX_FAIL] | |
42730
92ac6b1697a7
flagutil: move REVIDX_KNOWN_FLAGS source of truth in flagutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41413
diff
changeset
|
108 flagutil.REVIDX_KNOWN_FLAGS |= util.bitsfrom(flags) |
30745 | 109 revlog.REVIDX_FLAGS_ORDER.extend(flags) |
110 | |
31832
77f746e5383a
test-flagprocessor: use changegroup3 in bundle2
Jun Wu <quark@fb.com>
parents:
30745
diff
changeset
|
111 # Teach exchange to use changegroup 3 |
37165
6c7a6b04b274
bundlespec: move computing the bundle contentops in parsebundlespec
Boris Feld <boris.feld@octobus.net>
parents:
36114
diff
changeset
|
112 for k in exchange._bundlespeccontentopts.keys(): |
41413
fad627d2047c
tests: add b'' prefixes to flagprocessorext.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37436
diff
changeset
|
113 exchange._bundlespeccontentopts[k][b"cg.version"] = b"03" |
31832
77f746e5383a
test-flagprocessor: use changegroup3 in bundle2
Jun Wu <quark@fb.com>
parents:
30745
diff
changeset
|
114 |
30745 | 115 # Register flag processors for each extension |
42732
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42730
diff
changeset
|
116 flagutil.addflagprocessor( |
30745 | 117 REVIDX_NOOP, |
118 ( | |
119 noopdonothing, | |
120 noopdonothing, | |
121 validatehash, | |
122 ) | |
123 ) | |
42732
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42730
diff
changeset
|
124 flagutil.addflagprocessor( |
30745 | 125 REVIDX_BASE64, |
126 ( | |
127 b64decode, | |
128 b64encode, | |
129 bypass, | |
130 ), | |
131 ) | |
42732
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42730
diff
changeset
|
132 flagutil.addflagprocessor( |
30745 | 133 REVIDX_GZIP, |
134 ( | |
135 gzipdecompress, | |
136 gzipcompress, | |
137 bypass | |
138 ) | |
139 ) |