##// END OF EJS Templates
tests: add b'' prefixes to flagprocessorext.py...
Gregory Szorc -
r41458:fad627d2 default
parent child Browse files
Show More
@@ -1,136 +1,136
1 # coding=UTF-8
1 # coding=UTF-8
2
2
3 from __future__ import absolute_import
3 from __future__ import absolute_import
4
4
5 import base64
5 import base64
6 import zlib
6 import zlib
7
7
8 from mercurial import (
8 from mercurial import (
9 changegroup,
9 changegroup,
10 exchange,
10 exchange,
11 extensions,
11 extensions,
12 revlog,
12 revlog,
13 util,
13 util,
14 )
14 )
15
15
16 # Test only: These flags are defined here only in the context of testing the
16 # Test only: These flags are defined here only in the context of testing the
17 # behavior of the flag processor. The canonical way to add flags is to get in
17 # behavior of the flag processor. The canonical way to add flags is to get in
18 # touch with the community and make them known in revlog.
18 # touch with the community and make them known in revlog.
19 REVIDX_NOOP = (1 << 3)
19 REVIDX_NOOP = (1 << 3)
20 REVIDX_BASE64 = (1 << 2)
20 REVIDX_BASE64 = (1 << 2)
21 REVIDX_GZIP = (1 << 1)
21 REVIDX_GZIP = (1 << 1)
22 REVIDX_FAIL = 1
22 REVIDX_FAIL = 1
23
23
24 def validatehash(self, text):
24 def validatehash(self, text):
25 return True
25 return True
26
26
27 def bypass(self, text):
27 def bypass(self, text):
28 return False
28 return False
29
29
30 def noopdonothing(self, text):
30 def noopdonothing(self, text):
31 return (text, True)
31 return (text, True)
32
32
33 def b64encode(self, text):
33 def b64encode(self, text):
34 return (base64.b64encode(text), False)
34 return (base64.b64encode(text), False)
35
35
36 def b64decode(self, text):
36 def b64decode(self, text):
37 return (base64.b64decode(text), True)
37 return (base64.b64decode(text), True)
38
38
39 def gzipcompress(self, text):
39 def gzipcompress(self, text):
40 return (zlib.compress(text), False)
40 return (zlib.compress(text), False)
41
41
42 def gzipdecompress(self, text):
42 def gzipdecompress(self, text):
43 return (zlib.decompress(text), True)
43 return (zlib.decompress(text), True)
44
44
45 def supportedoutgoingversions(orig, repo):
45 def supportedoutgoingversions(orig, repo):
46 versions = orig(repo)
46 versions = orig(repo)
47 versions.discard(b'01')
47 versions.discard(b'01')
48 versions.discard(b'02')
48 versions.discard(b'02')
49 versions.add(b'03')
49 versions.add(b'03')
50 return versions
50 return versions
51
51
52 def allsupportedversions(orig, ui):
52 def allsupportedversions(orig, ui):
53 versions = orig(ui)
53 versions = orig(ui)
54 versions.add(b'03')
54 versions.add(b'03')
55 return versions
55 return versions
56
56
57 def makewrappedfile(obj):
57 def makewrappedfile(obj):
58 class wrappedfile(obj.__class__):
58 class wrappedfile(obj.__class__):
59 def addrevision(self, text, transaction, link, p1, p2,
59 def addrevision(self, text, transaction, link, p1, p2,
60 cachedelta=None, node=None,
60 cachedelta=None, node=None,
61 flags=revlog.REVIDX_DEFAULT_FLAGS):
61 flags=revlog.REVIDX_DEFAULT_FLAGS):
62 if b'[NOOP]' in text:
62 if b'[NOOP]' in text:
63 flags |= REVIDX_NOOP
63 flags |= REVIDX_NOOP
64
64
65 if b'[BASE64]' in text:
65 if b'[BASE64]' in text:
66 flags |= REVIDX_BASE64
66 flags |= REVIDX_BASE64
67
67
68 if b'[GZIP]' in text:
68 if b'[GZIP]' in text:
69 flags |= REVIDX_GZIP
69 flags |= REVIDX_GZIP
70
70
71 # This addrevision wrapper is meant to add a flag we will not have
71 # This addrevision wrapper is meant to add a flag we will not have
72 # transforms registered for, ensuring we handle this error case.
72 # transforms registered for, ensuring we handle this error case.
73 if b'[FAIL]' in text:
73 if b'[FAIL]' in text:
74 flags |= REVIDX_FAIL
74 flags |= REVIDX_FAIL
75
75
76 return super(wrappedfile, self).addrevision(text, transaction, link,
76 return super(wrappedfile, self).addrevision(text, transaction, link,
77 p1, p2,
77 p1, p2,
78 cachedelta=cachedelta,
78 cachedelta=cachedelta,
79 node=node,
79 node=node,
80 flags=flags)
80 flags=flags)
81
81
82 obj.__class__ = wrappedfile
82 obj.__class__ = wrappedfile
83
83
84 def reposetup(ui, repo):
84 def reposetup(ui, repo):
85 class wrappingflagprocessorrepo(repo.__class__):
85 class wrappingflagprocessorrepo(repo.__class__):
86 def file(self, f):
86 def file(self, f):
87 orig = super(wrappingflagprocessorrepo, self).file(f)
87 orig = super(wrappingflagprocessorrepo, self).file(f)
88 makewrappedfile(orig)
88 makewrappedfile(orig)
89 return orig
89 return orig
90
90
91 repo.__class__ = wrappingflagprocessorrepo
91 repo.__class__ = wrappingflagprocessorrepo
92
92
93 def extsetup(ui):
93 def extsetup(ui):
94 # Enable changegroup3 for flags to be sent over the wire
94 # Enable changegroup3 for flags to be sent over the wire
95 wrapfunction = extensions.wrapfunction
95 wrapfunction = extensions.wrapfunction
96 wrapfunction(changegroup,
96 wrapfunction(changegroup,
97 'supportedoutgoingversions',
97 'supportedoutgoingversions',
98 supportedoutgoingversions)
98 supportedoutgoingversions)
99 wrapfunction(changegroup,
99 wrapfunction(changegroup,
100 'allsupportedversions',
100 'allsupportedversions',
101 allsupportedversions)
101 allsupportedversions)
102
102
103 # Teach revlog about our test flags
103 # Teach revlog about our test flags
104 flags = [REVIDX_NOOP, REVIDX_BASE64, REVIDX_GZIP, REVIDX_FAIL]
104 flags = [REVIDX_NOOP, REVIDX_BASE64, REVIDX_GZIP, REVIDX_FAIL]
105 revlog.REVIDX_KNOWN_FLAGS |= util.bitsfrom(flags)
105 revlog.REVIDX_KNOWN_FLAGS |= util.bitsfrom(flags)
106 revlog.REVIDX_FLAGS_ORDER.extend(flags)
106 revlog.REVIDX_FLAGS_ORDER.extend(flags)
107
107
108 # Teach exchange to use changegroup 3
108 # Teach exchange to use changegroup 3
109 for k in exchange._bundlespeccontentopts.keys():
109 for k in exchange._bundlespeccontentopts.keys():
110 exchange._bundlespeccontentopts[k]["cg.version"] = "03"
110 exchange._bundlespeccontentopts[k][b"cg.version"] = b"03"
111
111
112 # Register flag processors for each extension
112 # Register flag processors for each extension
113 revlog.addflagprocessor(
113 revlog.addflagprocessor(
114 REVIDX_NOOP,
114 REVIDX_NOOP,
115 (
115 (
116 noopdonothing,
116 noopdonothing,
117 noopdonothing,
117 noopdonothing,
118 validatehash,
118 validatehash,
119 )
119 )
120 )
120 )
121 revlog.addflagprocessor(
121 revlog.addflagprocessor(
122 REVIDX_BASE64,
122 REVIDX_BASE64,
123 (
123 (
124 b64decode,
124 b64decode,
125 b64encode,
125 b64encode,
126 bypass,
126 bypass,
127 ),
127 ),
128 )
128 )
129 revlog.addflagprocessor(
129 revlog.addflagprocessor(
130 REVIDX_GZIP,
130 REVIDX_GZIP,
131 (
131 (
132 gzipdecompress,
132 gzipdecompress,
133 gzipcompress,
133 gzipcompress,
134 bypass
134 bypass
135 )
135 )
136 )
136 )
General Comments 0
You need to be logged in to leave comments. Login now