comparison tests/flagprocessorext.py @ 43076:2372284d9457

formatting: blacken the codebase This is using my patch to black (https://github.com/psf/black/pull/826) so we don't un-wrap collection literals. Done with: hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S # skip-blame mass-reformatting only # no-check-commit reformats foo_bar functions Differential Revision: https://phab.mercurial-scm.org/D6971
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:45:02 -0400
parents f4caf910669e
children 74271829ddc0
comparison
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
10 exchange, 10 exchange,
11 extensions, 11 extensions,
12 revlog, 12 revlog,
13 util, 13 util,
14 ) 14 )
15 from mercurial.revlogutils import ( 15 from mercurial.revlogutils import flagutil
16 flagutil,
17 )
18 16
19 # Test only: These flags are defined here only in the context of testing the 17 # 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 18 # 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. 19 # touch with the community and make them known in revlog.
22 REVIDX_NOOP = (1 << 3) 20 REVIDX_NOOP = 1 << 3
23 REVIDX_BASE64 = (1 << 2) 21 REVIDX_BASE64 = 1 << 2
24 REVIDX_GZIP = (1 << 1) 22 REVIDX_GZIP = 1 << 1
25 REVIDX_FAIL = 1 23 REVIDX_FAIL = 1
24
26 25
27 def validatehash(self, text): 26 def validatehash(self, text):
28 return True 27 return True
29 28
29
30 def bypass(self, text): 30 def bypass(self, text):
31 return False 31 return False
32
32 33
33 def noopdonothing(self, text, sidedata): 34 def noopdonothing(self, text, sidedata):
34 return (text, True) 35 return (text, True)
35 36
37
36 def noopdonothingread(self, text): 38 def noopdonothingread(self, text):
37 return (text, True, {}) 39 return (text, True, {})
40
38 41
39 def b64encode(self, text, sidedata): 42 def b64encode(self, text, sidedata):
40 return (base64.b64encode(text), False) 43 return (base64.b64encode(text), False)
41 44
45
42 def b64decode(self, text): 46 def b64decode(self, text):
43 return (base64.b64decode(text), True, {}) 47 return (base64.b64decode(text), True, {})
48
44 49
45 def gzipcompress(self, text, sidedata): 50 def gzipcompress(self, text, sidedata):
46 return (zlib.compress(text), False) 51 return (zlib.compress(text), False)
47 52
53
48 def gzipdecompress(self, text): 54 def gzipdecompress(self, text):
49 return (zlib.decompress(text), True, {}) 55 return (zlib.decompress(text), True, {})
56
50 57
51 def supportedoutgoingversions(orig, repo): 58 def supportedoutgoingversions(orig, repo):
52 versions = orig(repo) 59 versions = orig(repo)
53 versions.discard(b'01') 60 versions.discard(b'01')
54 versions.discard(b'02') 61 versions.discard(b'02')
55 versions.add(b'03') 62 versions.add(b'03')
56 return versions 63 return versions
57 64
65
58 def allsupportedversions(orig, ui): 66 def allsupportedversions(orig, ui):
59 versions = orig(ui) 67 versions = orig(ui)
60 versions.add(b'03') 68 versions.add(b'03')
61 return versions 69 return versions
62 70
71
63 def makewrappedfile(obj): 72 def makewrappedfile(obj):
64 class wrappedfile(obj.__class__): 73 class wrappedfile(obj.__class__):
65 def addrevision(self, text, transaction, link, p1, p2, 74 def addrevision(
66 cachedelta=None, node=None, 75 self,
67 flags=flagutil.REVIDX_DEFAULT_FLAGS): 76 text,
77 transaction,
78 link,
79 p1,
80 p2,
81 cachedelta=None,
82 node=None,
83 flags=flagutil.REVIDX_DEFAULT_FLAGS,
84 ):
68 if b'[NOOP]' in text: 85 if b'[NOOP]' in text:
69 flags |= REVIDX_NOOP 86 flags |= REVIDX_NOOP
70 87
71 if b'[BASE64]' in text: 88 if b'[BASE64]' in text:
72 flags |= REVIDX_BASE64 89 flags |= REVIDX_BASE64
77 # This addrevision wrapper is meant to add a flag we will not have 94 # This addrevision wrapper is meant to add a flag we will not have
78 # transforms registered for, ensuring we handle this error case. 95 # transforms registered for, ensuring we handle this error case.
79 if b'[FAIL]' in text: 96 if b'[FAIL]' in text:
80 flags |= REVIDX_FAIL 97 flags |= REVIDX_FAIL
81 98
82 return super(wrappedfile, self).addrevision(text, transaction, link, 99 return super(wrappedfile, self).addrevision(
83 p1, p2, 100 text,
84 cachedelta=cachedelta, 101 transaction,
85 node=node, 102 link,
86 flags=flags) 103 p1,
104 p2,
105 cachedelta=cachedelta,
106 node=node,
107 flags=flags,
108 )
87 109
88 obj.__class__ = wrappedfile 110 obj.__class__ = wrappedfile
111
89 112
90 def reposetup(ui, repo): 113 def reposetup(ui, repo):
91 class wrappingflagprocessorrepo(repo.__class__): 114 class wrappingflagprocessorrepo(repo.__class__):
92 def file(self, f): 115 def file(self, f):
93 orig = super(wrappingflagprocessorrepo, self).file(f) 116 orig = super(wrappingflagprocessorrepo, self).file(f)
94 makewrappedfile(orig) 117 makewrappedfile(orig)
95 return orig 118 return orig
96 119
97 repo.__class__ = wrappingflagprocessorrepo 120 repo.__class__ = wrappingflagprocessorrepo
98 121
122
99 def extsetup(ui): 123 def extsetup(ui):
100 # Enable changegroup3 for flags to be sent over the wire 124 # Enable changegroup3 for flags to be sent over the wire
101 wrapfunction = extensions.wrapfunction 125 wrapfunction = extensions.wrapfunction
102 wrapfunction(changegroup, 126 wrapfunction(
103 'supportedoutgoingversions', 127 changegroup, 'supportedoutgoingversions', supportedoutgoingversions
104 supportedoutgoingversions) 128 )
105 wrapfunction(changegroup, 129 wrapfunction(changegroup, 'allsupportedversions', allsupportedversions)
106 'allsupportedversions',
107 allsupportedversions)
108 130
109 # Teach revlog about our test flags 131 # Teach revlog about our test flags
110 flags = [REVIDX_NOOP, REVIDX_BASE64, REVIDX_GZIP, REVIDX_FAIL] 132 flags = [REVIDX_NOOP, REVIDX_BASE64, REVIDX_GZIP, REVIDX_FAIL]
111 flagutil.REVIDX_KNOWN_FLAGS |= util.bitsfrom(flags) 133 flagutil.REVIDX_KNOWN_FLAGS |= util.bitsfrom(flags)
112 revlog.REVIDX_FLAGS_ORDER.extend(flags) 134 revlog.REVIDX_FLAGS_ORDER.extend(flags)
115 for k in exchange._bundlespeccontentopts.keys(): 137 for k in exchange._bundlespeccontentopts.keys():
116 exchange._bundlespeccontentopts[k][b"cg.version"] = b"03" 138 exchange._bundlespeccontentopts[k][b"cg.version"] = b"03"
117 139
118 # Register flag processors for each extension 140 # Register flag processors for each extension
119 flagutil.addflagprocessor( 141 flagutil.addflagprocessor(
120 REVIDX_NOOP, 142 REVIDX_NOOP, (noopdonothingread, noopdonothing, validatehash,)
121 (
122 noopdonothingread,
123 noopdonothing,
124 validatehash,
125 )
126 ) 143 )
127 flagutil.addflagprocessor( 144 flagutil.addflagprocessor(
128 REVIDX_BASE64, 145 REVIDX_BASE64, (b64decode, b64encode, bypass,),
129 (
130 b64decode,
131 b64encode,
132 bypass,
133 ),
134 ) 146 )
135 flagutil.addflagprocessor( 147 flagutil.addflagprocessor(
136 REVIDX_GZIP, 148 REVIDX_GZIP, (gzipdecompress, gzipcompress, bypass)
137 (
138 gzipdecompress,
139 gzipcompress,
140 bypass
141 )
142 ) 149 )