Mercurial > hg
annotate tests/flagprocessorext.py @ 46531:d46885119f90
test-copies: don't use empty file for "same content" cases
For main case (using filelog or sidedata), this lead to the following hash
change.
Changesets:
- 01c2f5eabdc4ce2bdee42b5f86311955e6c8f573 → 319179230cc87769ab3a861ebffe7a534ebb3d85
- 01c2f5eabdc4 → 319179230cc8
- c72365ee036fca4fb27fd745459bfb6ea1ac6993 → 6cbc9c2b7b391dd738603173717c601648d3735f
- c72365ee036f → 6cbc9c2b7b39
File revision for `f`:
- 0dd616bc7ab1a111921d95d76f69cda5c2ac539c → cedeacc5bf5d9b9be4d7f8394d33a5349bb29c6e
- 0dd616bc7ab1 → cedeacc5bf5d
- eb806e34ef6be4c264effd5933d31004ad15a793 → ffb76cd765422a18759a335d8a81fa2bd455be6b
- eb806e34ef6b → ffb76cd76542
- 6da5a2eecb9c833f830b67a4972366d49a9a142c → 08d1ff5926fbd0285cdeb044cbe8ab651687e86a
- 6da5a2eecb9c → 08d1ff5926fb
File revision for `d`:
- 7bded9d9da1f7bf9bf7cbfb24fe1e6ccf68ec440 → ba177bbb45ea930ee48469a55d40224537bd57a9
For the "extra in changeset" case we get the following change for file `d`:
- 68d5bca9df0577b6bc2ea30ca724e13ead60da81 → b894de5c94aadcb4894ea7c358389819c27fbcce
- 68d5bca9df05 → b894de5c94aa
- b80de5d138758541c5f05265ad144ab9fa86d1db → 56647659eff080e06e45c18ea9e848836dadea71
- b80de5d13875 → 56647659eff0
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 22 Feb 2021 18:48:45 +0100 |
parents | 89a2afe31e82 |
children | 3d740058b467 |
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 ( | |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43076
diff
changeset
|
9 bundlecaches, |
30745 | 10 changegroup, |
11 extensions, | |
12 revlog, | |
13 util, | |
14 ) | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
15 from mercurial.revlogutils import flagutil |
30745 | 16 |
17 # Test only: These flags are defined here only in the context of testing the | |
18 # behavior of the flag processor. The canonical way to add flags is to get in | |
19 # touch with the community and make them known in revlog. | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
20 REVIDX_NOOP = 1 << 3 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
21 REVIDX_BASE64 = 1 << 2 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
22 REVIDX_GZIP = 1 << 1 |
30745 | 23 REVIDX_FAIL = 1 |
24 | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
25 |
30745 | 26 def validatehash(self, text): |
27 return True | |
28 | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
29 |
30745 | 30 def bypass(self, text): |
31 return False | |
32 | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
33 |
42988
f4caf910669e
flagprocessors: writetransform function take side data as parameter (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42985
diff
changeset
|
34 def noopdonothing(self, text, sidedata): |
30745 | 35 return (text, True) |
36 | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
37 |
42985
bd5858c28bbe
flagprocessors: have the read transform function return side data (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42732
diff
changeset
|
38 def noopdonothingread(self, text): |
bd5858c28bbe
flagprocessors: have the read transform function return side data (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42732
diff
changeset
|
39 return (text, True, {}) |
bd5858c28bbe
flagprocessors: have the read transform function return side data (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42732
diff
changeset
|
40 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
41 |
42988
f4caf910669e
flagprocessors: writetransform function take side data as parameter (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42985
diff
changeset
|
42 def b64encode(self, text, sidedata): |
30745 | 43 return (base64.b64encode(text), False) |
44 | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
45 |
30745 | 46 def b64decode(self, text): |
42985
bd5858c28bbe
flagprocessors: have the read transform function return side data (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42732
diff
changeset
|
47 return (base64.b64decode(text), True, {}) |
30745 | 48 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
49 |
42988
f4caf910669e
flagprocessors: writetransform function take side data as parameter (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42985
diff
changeset
|
50 def gzipcompress(self, text, sidedata): |
30745 | 51 return (zlib.compress(text), False) |
52 | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
53 |
30745 | 54 def gzipdecompress(self, text): |
42985
bd5858c28bbe
flagprocessors: have the read transform function return side data (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42732
diff
changeset
|
55 return (zlib.decompress(text), True, {}) |
30745 | 56 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
57 |
30745 | 58 def supportedoutgoingversions(orig, repo): |
59 versions = orig(repo) | |
36114
83246d6920f2
py3: use b'' for changegroup version literals
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35570
diff
changeset
|
60 versions.discard(b'01') |
83246d6920f2
py3: use b'' for changegroup version literals
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35570
diff
changeset
|
61 versions.discard(b'02') |
83246d6920f2
py3: use b'' for changegroup version literals
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35570
diff
changeset
|
62 versions.add(b'03') |
30745 | 63 return versions |
64 | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
65 |
30745 | 66 def allsupportedversions(orig, ui): |
67 versions = orig(ui) | |
36114
83246d6920f2
py3: use b'' for changegroup version literals
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35570
diff
changeset
|
68 versions.add(b'03') |
30745 | 69 return versions |
70 | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
71 |
37436
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
72 def makewrappedfile(obj): |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
73 class wrappedfile(obj.__class__): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
74 def addrevision( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
75 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
76 text, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
77 transaction, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
78 link, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
79 p1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
80 p2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
81 cachedelta=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
82 node=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
83 flags=flagutil.REVIDX_DEFAULT_FLAGS, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
84 ): |
37436
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
85 if b'[NOOP]' in text: |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
86 flags |= REVIDX_NOOP |
30745 | 87 |
37436
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
88 if b'[BASE64]' in text: |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
89 flags |= REVIDX_BASE64 |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
90 |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
91 if b'[GZIP]' in text: |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
92 flags |= REVIDX_GZIP |
30745 | 93 |
37436
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
94 # 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
|
95 # 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
|
96 if b'[FAIL]' in text: |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
97 flags |= REVIDX_FAIL |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
98 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
99 return super(wrappedfile, self).addrevision( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
100 text, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
101 transaction, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
102 link, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
103 p1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
104 p2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
105 cachedelta=cachedelta, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
106 node=node, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
107 flags=flags, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
108 ) |
30745 | 109 |
37436
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
110 obj.__class__ = wrappedfile |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
111 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
112 |
37436
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
113 def reposetup(ui, repo): |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
114 class wrappingflagprocessorrepo(repo.__class__): |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
115 def file(self, f): |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
116 orig = super(wrappingflagprocessorrepo, self).file(f) |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
117 makewrappedfile(orig) |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
118 return orig |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
119 |
9d4f09bfe3ec
simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37165
diff
changeset
|
120 repo.__class__ = wrappingflagprocessorrepo |
30745 | 121 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
122 |
30745 | 123 def extsetup(ui): |
124 # Enable changegroup3 for flags to be sent over the wire | |
125 wrapfunction = extensions.wrapfunction | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
126 wrapfunction( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
127 changegroup, 'supportedoutgoingversions', supportedoutgoingversions |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
128 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
129 wrapfunction(changegroup, 'allsupportedversions', allsupportedversions) |
30745 | 130 |
131 # Teach revlog about our test flags | |
132 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
|
133 flagutil.REVIDX_KNOWN_FLAGS |= util.bitsfrom(flags) |
30745 | 134 revlog.REVIDX_FLAGS_ORDER.extend(flags) |
135 | |
31832
77f746e5383a
test-flagprocessor: use changegroup3 in bundle2
Jun Wu <quark@fb.com>
parents:
30745
diff
changeset
|
136 # Teach exchange to use changegroup 3 |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43076
diff
changeset
|
137 for k in bundlecaches._bundlespeccontentopts.keys(): |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43076
diff
changeset
|
138 bundlecaches._bundlespeccontentopts[k][b"cg.version"] = b"03" |
31832
77f746e5383a
test-flagprocessor: use changegroup3 in bundle2
Jun Wu <quark@fb.com>
parents:
30745
diff
changeset
|
139 |
30745 | 140 # 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
|
141 flagutil.addflagprocessor( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
142 REVIDX_NOOP, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
143 ( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
144 noopdonothingread, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
145 noopdonothing, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
146 validatehash, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
147 ), |
30745 | 148 ) |
42732
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42730
diff
changeset
|
149 flagutil.addflagprocessor( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
150 REVIDX_BASE64, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
151 ( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
152 b64decode, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
153 b64encode, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
154 bypass, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45784
diff
changeset
|
155 ), |
30745 | 156 ) |
42732
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42730
diff
changeset
|
157 flagutil.addflagprocessor( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42988
diff
changeset
|
158 REVIDX_GZIP, (gzipdecompress, gzipcompress, bypass) |
30745 | 159 ) |